1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Shalnov [3]
4 years ago
13

Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the

numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format.
Computers and Technology
1 answer:
jeka944 years ago
5 0

Answer:

#include <iostream>

#include <string>

#include <stack>

#include <math.h>

using namespace std;

int main() {

  string s;

  double n=0;

  int position=0;  

  stack<int> wholeNumbers;

  cout<<"Enter a decimal number:";

  cin>>s;

  string::iterator counter = s.begin();

  while(*counter!='.' && counter!=s.end()){

      wholeNumbers.push(*counter-48);

      counter++;

      position=position+1;

     

  }

  for(int i=0;i<position;i++){

      n=n+(wholeNumbers.top()*pow(10,i));

      wholeNumbers.pop();

  }

  position=-1;

  if(counter!=s.end()){

      counter++;

  }

  while(counter!=s.end()){

      n=n+((*counter-48)*pow(10,position));

      position=position-1;

      counter++;      

  }

  cout<<n;

}

Explanation:

  • Inside the while loop, push the push a number to the wholeNumbers stack by subtracting it with 48.
  • Increment the counter and position variable by 1 inside the while loop.
  • Count the number of digit, push each digit to top of stack and find the end of the number,
  • Run a for loop up to the value of position variable and pop a value from the wholeNumbers stack.
You might be interested in
You have just changed the system time within your computer's BIOS. You choose to save the settings upon exit. What happens next
vazorg [7]
The system reboots with the time changed
8 0
3 years ago
Read 2 more answers
Why does space exploration lead to new technology?
valentina_108 [34]

Answer:

C. Because materials developed for use in space are often useful to ordinary citizens.

Explanation:

A, is not correct due to the "only" word. Humans can explore space too.

B, not that either because you will need lots of technology to space travel, not less.

C, because materials that can be produced through scientists' ideas can help contribute to society and improve technology.

D, is not correct because there is no need for new materials for new technology.

5 0
3 years ago
Which four of the following qualify as fair use?
lora16 [44]

Answer:

1 using the quote and citing it

Explanation:

6 0
3 years ago
Read 2 more answers
The report Jamie created has a dark background and the page number is not displaying correctly. Which formatting option would he
Readme [11.4K]
The Font Color <span>formatting option would be needed to apply to the page number to add contrast between the background and the page number</span>
8 0
3 years ago
One method of encoding messages is known as the "expanding square code". this method encodes message by placing the character of
mars1129 [50]
Wow!! that is ALOT of info,I dont think i could help with this one Umders 699 maybe someone else can sorry that i couldn`t help :)
4 0
4 years ago
Other questions:
  • Carrie works on a help desk and is assigned a ticket that was automatically generated by a server because of an error. The error
    5·1 answer
  • The project started the development of inter-network connections using tcp/ip that has evolved into the internet today.
    5·1 answer
  • What type of scientists studies tree rings to determine the history of an area?
    9·2 answers
  • Damage to which portion of the limbic system results in loss of memory of recent events and difficulty committing anything new t
    13·1 answer
  • A website sells illegal and counterfeited materials. According to which law can the US Attorney General seek a court order to re
    5·2 answers
  • What is the digital divide? What does the digital divide mean for the world?
    9·1 answer
  • How many fonts are there in a theme?<br> A. 1<br> B. 2<br> C. 4<br> D. 5
    10·1 answer
  • When you type into a basic search engine like Google, Bing, or Yahoo!, the sites that appear at the top or on the side of the re
    7·1 answer
  • What is one way you can learn about your digital footprint?
    13·1 answer
  • It is important to give the health and safety experience to new or inexperienced workers, including those that have been away fr
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!