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
What are screenshots helpful for ?
alex41 [277]

A

Creating.

Explanation:

What else would they be used for

4 0
3 years ago
Read 2 more answers
Write a program in qbasic to accept a character and check it is vowel or consonant​
Alborosie

Answer:

In sub procedure or normal program?

6 0
3 years ago
The _____ icon allows the user to improve the brightness, contrast, or sharpness of the picture.
bija089 [108]

Answer:

The Corrections icon

Explanation:

In Office 2010, 2013, 2016, you can adjust the brightness, contrast, and the sharpness of a picture. This can be achieved by using the corrections tool. Assuming you already have the picture, click on it and on the Format tab, under the Pictures tools, in the Adjust group, click Corrections. Under the Sharpen/Soften or the Brightness/Contrast, you can click the thumbnails that you want to make adjustments.

4 0
2 years ago
Which of the following is something you need to keep an eye out for
Brilliant_brown [7]

Answer:

D. Pedestrians ignoring DON'T WALK signs

Explanation:

Pedestrians ignoring DON'T WALK signs is something you need to keep an eye out for  near packed intersections.

4 0
3 years ago
Read 2 more answers
What behaviors are most common in a successful entrepreneurship
Kryger [21]
1. Proper planning
2. Honesty
3. Being reasonable in pricing
4. Knowledge of what you’re offering
5. Being kind/good to your clients
8 0
3 years ago
Other questions:
  • Discussion group may have a___________ who monitors the postings and enforces the sides rules​
    13·1 answer
  • How long did it take Linkedln to reach 1 million users?
    5·2 answers
  • A _____ defines what must take place, not how it will be accomplished.​
    12·1 answer
  • How does the binary numbering system differ from the hexadecimal numbering system?
    14·2 answers
  • Visual imagery encoding relates to _____ encoding, in that a person is connecting the new information to previously existing inf
    11·1 answer
  • If two egg cells are fertilized what will happen?
    10·1 answer
  • What is it called when you remove some information from a file or remove a file from the disk ? A) save b) delete c) edit d) rem
    5·1 answer
  • Your _______ can help block inappropriate content online.<br> 1. web browser<br> 2. Password
    14·1 answer
  • Why is a salt added to a password that is being stored in a database?
    5·1 answer
  • Technology __________ guides how frequently technical systems are updated, and how technical updates are approved and funded.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!