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
Let’s say you attach four images to accompany an important tweet that you’ve composed in the Hootsuite Compose Box. On Twitter,
Damm [24]
I doub between:

<span>  C)  A series of 4 full size, but individual tweets (with the tweet copy appearing above the first image of the series)  D)  A collage format, with full size images</span>

6 0
4 years ago
In the lungs,blood picks up carbon dioxide and releases oxygen true or false
Maksim231197 [3]

Answer:

false

Explanation:

plants do that, they absorb carbon dioxide and then they create oxygen, then humans breathe the oxygen and makes CB

8 0
3 years ago
Web sites use _____ to track users while they are on the site.
Liula [17]
These are files called cookies. =)
6 0
3 years ago
3. A vulnerability is: a. A hacker searching for open ports b. A known attack method c. An incorrectly implemented policy d. All
ELEN [110]

Answer:

A

Explanation:

A hacker searching for open ports denotes vulnerability of computer (to hacking).

Cheers

7 0
3 years ago
Which of the following assumes that the repair will happen just as the technician stated?
kipiarov [429]
A (filling out carachts
3 0
3 years ago
Other questions:
  • Which of the following Internet business models involves a merchant creating an online digital environment that enables people w
    11·1 answer
  • How do i protect my computer from electrical spikes
    14·2 answers
  • A game’s ______ is what contains its directions and calculations; some refer to it as the “engine” that drives the game.
    12·1 answer
  • Which of these scenarios depicts unethical workplace practice by an employee?
    7·2 answers
  • What is an end user license (EULA) agreement an example of?
    9·2 answers
  • Implement the Dining Philosophers problem (described on pages 167-170 in the textbook (chapter 2.5.1)). Create a Graphical User
    13·1 answer
  • Social networking is the most popular online activity?<br> True<br> False
    8·2 answers
  • X = 9 % 2<br><br> if (x == 1):<br>   print ("ONE")<br> else:<br>   print ("TWO")
    5·2 answers
  • Write pseudo code that performs the following: Ask a user to enter a number. If the
    13·1 answer
  • A process spawning or initiating another process is referred to as _____
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!