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
Imagine that you were hired to create the label for a new brand of soup. The client wants to emphasize that the soup has homemad
lidiya [134]

Answer:

Explanation:

For tools, I would simply use Adobe Photoshop to create the label/poster for the brand of soup. In order to make the poster or representation of the soup look homemade, I would place a picture of a kid drinking the soup at a kitchen table with a picture of the mom in the background kitchen. Then I would create a light yellowish tint in the image and steam coming from the soup bowl. This would help the brand represent a form of memory to a delicious homemade meal by a parent.

4 0
3 years ago
When you think of computers, I want you to think:
jekas [21]

Answer:

Explanation:

When I think about computers, I can understand about the software and the hardware, we can touch the hardware, but the software don't because is only data stored in the hardware, we can interact with the stored data using the hardware, we can complete a system with data, software, hardware, and people, people try to learn about software because it is better paid than fix a hardware.

5 0
3 years ago
How can the Internet help our country to be a leader in technology?
BigorU [14]

Answer:

it can help in the aspect of making technologies to be fastly operated with fast internet connection there by it top among all other countries

4 0
2 years ago
The Danger zone around a robot is?
mojhsa [17]

maybe a EMP. tell me if im right

3 0
3 years ago
Read 2 more answers
In which two places are a keyboard usually held on a laptop?
Margarita [4]

Answer:

Bottom of the case

Through a connector

Explanation:

Regularly we must see the bottom of the case to remove some screws, and then move the keyboard, but first, you have to remove a connector.

The keyboards have evolved from windows and IMB built their own keyboards for desktop, and now we have digital keyboards, and replace a keyboard in a laptop can change for the model or the size.

6 0
3 years ago
Other questions:
  • HELP ASAP????? please
    5·2 answers
  • Betty took her friends bowling. they rented 4 lane. 10 people need rent shoes and
    12·1 answer
  • (BRAINLIEST QUESTION) What are some challenges that will need to be overcome in order for the Internet of Vehicles to become a r
    13·1 answer
  • True or False? In a C++ floating-point constant, a decimal point is not required if exponential (E) notation is used
    13·1 answer
  • What behaviors are most common in a successful entrepreneurship
    9·1 answer
  • What is the best way to improve the following code fragment? if ((counter % 10) == 0) { System.out.println("Counter is divisible
    11·1 answer
  • Computer can do work very___​
    7·2 answers
  • Ns.office.com/Pages/ResponsePage.aspx?id=bd8
    9·2 answers
  • What are the significances of blogs?
    7·2 answers
  • How to implement switch statement in Python?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!