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]
3 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:
jeka943 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
Which object event is an indication that something has been created but not committed into the database?
ollegr [7]

Answer:

before update

Explanation:

because the update has been made but not submited

8 0
3 years ago
I wrote a program to calculate how many unique students I have taught over the years. It will read in a file formatted with firs
weqwewe [10]

This question is incomplete. The complete question, answer & explanation for this question is given in the attachment below.

Download docx
4 0
3 years ago
Explain the components of Information System?​
slavikrds [6]

Answer:

An information system is essentially made up of five components hardware, software, database, network and people. These five components integrate to perform input, process, output, feedback and control. Hardware consists of input/output device, processor, operating system and media devices.

Explanation:

7 0
3 years ago
Use the ________ property in the html link tag to to associate a web page with a style sheet for printing.
lawyer [7]
You should use the <span>media="print" link tag to achieve this. </span>
8 0
3 years ago
The ________ contains the central electronic components of the computer. select one:
Sati [7]
The motherboard contains the central electronic components of the computer.
6 0
3 years ago
Other questions:
  • (If the link is not working, search for "Veritasium Levitating Barbecue". At approximately the 2 minute mark, the screen shows 8
    9·1 answer
  • Word processing, presentation, photo editing, and video games are all types of what?
    9·2 answers
  • 50 POINTS!!!!
    8·1 answer
  • Write the definition of a method min that has two int parameters and returns the smaller.
    9·1 answer
  • My friend has 200 subs and i have only 36 can you help me its ACYT ZR
    9·2 answers
  • The process of identifying and removing logical errors and runtime errors is called ..............
    5·2 answers
  • Which of the following is not the disadvantage of closed
    7·2 answers
  • What is Parallelism? And what is Pipelining?<br> Can someone please explain them fully?!
    14·1 answer
  • (a) What is the meaning of word 'computer (b) Cive a reason for the evolution of computer (c) Write a weakness of a computer (d)
    14·1 answer
  • the first thing to do when your computer gives you an error message is A restart the computer B press the F2 key C write down th
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!