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
A ____ is a prewritten formula that is built into excel.
kondor19780726 [428]
A function is a prewritten formula that is built into excel.
3 0
4 years ago
A(n) _____ allows individuals to create and publish a profile, create a list of other users with whom they share a connection (o
Mice21 [21]

Answer:

Social Networks

Explanation:

Social Network provides a way for users to create a profile, create a list of other users whom they share a connection with. This allows users to connect with other users who share similar interests with them. Businesses can also leverage the power of the social network to boost their sales and gain more reach and visibility.

4 0
3 years ago
Which of the strategies below are likely to increase audience attention?
coldgirl [10]

Answer:

Use lots of different animation styles on each slide.

Explanation:

3 0
3 years ago
What is stand-alone LDAP server?
FinnZ [79.3K]

Answer:

A stand-alone LDAP server is defined as to remove the load from a server that does multi function tasks. It is more efficient when we use one or more LDAP configurations .

Light weight Directory Access Protocol (LDAP) is a client and server protocol used for accessing directory data. It  helps in reading and editing the directories over IP networks and runs directly over Transmission control protocol and internet protocol used simple string format for transferring of data.

8 0
3 years ago
The _____ component of a database management system (dbms) is used to add, delete, modify, and retrieve records from a database.
ikadub [295]
The correct answer is:  [A]:  "data manipulation" .
________________________________________________________
3 0
4 years ago
Read 2 more answers
Other questions:
  • Effective teams use strategies that help members work together a) smoothly b) independently c) loosely d) secretly
    5·2 answers
  • Peter recently bought a media player and a digital camera he wants to buy memory card for the devices which memory device should
    10·2 answers
  • There are how many GPS satellites orbiting the earth
    15·1 answer
  • Design a Ship class with the following members:
    13·1 answer
  • As a student you are able to earn extra money by assisting your neighbors
    6·2 answers
  • This project involves writing a program that encodes and decodes messages. The program should prompt the user to select whether
    15·1 answer
  • Why is flash memory considered nonvolatile?
    5·1 answer
  • , 13 dB correspond to a power ratio of ....?
    14·1 answer
  • Given a dataset where the dataset is not linearly-separable, and each of the fea- tures have continuous values, which of the fol
    7·1 answer
  • Aarti, a museum employee, has created a table in access titled “Roman Achitecture”. She has included a field that links users im
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!