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
Write a program that inputs two characters first and second, and then prints all non-alphabetic characters starting from second
baherus [9]

Answer:

fbtcft gdfgfffff tvfft gxf

8 0
3 years ago
Which of the following is an example of a soft skill?
Lady bird [3.3K]
Answer is (B)

Helping a customer by answering a question whether on the phone of face to face is an example of soft skills. Such skills are developed through Effective communication, better listening skills, positivity, assertiveness, empathy, conflict resolution, and depersonalization. 
<span>Basically, if you have these skills when handling a customer, what they will remember is what they felt about your service.</span>

 
8 0
3 years ago
Read 2 more answers
A user has become compromised as a result of visiting a specific web page, without clicking on any kind of content. What type of
Nostrana [21]

Answer:

drive-by-download

Explanation:

3 0
2 years ago
Read 2 more answers
A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-lif
Leokris [45]

Answer:

#include <iostream>

#include<iomanip>

using namespace std;

int main()

{

double caffeineMg;

cin>>caffeineMg;

cout<<"After 6 hours: "<<fixed<<setprecision(2)<<caffeineMg/2.0<<" mg\n";

cout<<"After 12 hours: "<<fixed<<setprecision(2)<<caffeineMg/4.0<<" mg\n";

cout<<"After 24 hours: "<<fixed<<setprecision(2)<<caffeineMg/8.0<<" mg\n";

 

return 0;

}

Explanation:

  • Take the caffeine as input from user.
  • Calculate by dividing this value with relevant half life.
  • Use setprecision(2) to display 2 digits after decimal point.
3 0
3 years ago
A user is trying to delete a file located on an ntfs volume on his windows 8 computer but is unable to do so. Why is this.
dezoksy [38]

It happened because the window files on that users pc are corrupted and deleted so the user needs to reinstall the windows and then after he should be able to remove that file from his PC.

If the above thing didn't work, follow the following steps.

- Click the start button ,type in cmd then it will show you a command prompt program icon, right click on that and open it by using the administrator rights. Once the program opened then type in chkdsk /f and hit Enter to automatically scan your computer for any corrupted files/ folders upon the restart of the computer.

This will be definitely helpful for you.

4 0
3 years ago
Other questions:
  • Which query will give the following result when it it applied on table 1????!!!!!
    10·1 answer
  • Disk ___________________ helps improve the speed and efficiency of a hard disk.
    6·1 answer
  • Write a program that: program starts; declares and initializes to .06625 constant float variable NJSALES_TAX; declares and initi
    8·1 answer
  • Which kind of testing runs the system in a simulated environment using simulated data?a) validation testing. b) verification tes
    5·1 answer
  • How do you change the number of rows and columns displayed for an embedded Excel object on a PowerPoint slide?
    8·1 answer
  • C. An error that due to wrong input.​
    13·1 answer
  • The five types of personal computers are: desktops, laptops, tablets, smartphones, and ________.
    13·1 answer
  • It’s just a multiple choice question about emails
    11·2 answers
  • What are interpersonal skills for non-technical user
    14·1 answer
  • Read the Python program below: num1 = int(input()) num2 = 10 + num1 * 2 print(num2) num1 = 20 print(num1) Question 1 When this p
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!