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
The average pH of citrus fruits is 2.2, and this value has been stored in the variable avg_citrus_pH . Provide a statement to di
olasank [31]

Answer:

The statement in Python is:

print("The average pH of citrus fruits is ",avg_citrus_pH)

Java

System.out.print("The average pH of citrus fruits is "+avg_citrus_pH);

C++

cout<<"The average pH of citrus fruits is "<<avg_citrus_pH;

Explanation:

The programming language is not stated; so, I answered the question in 3 languages (Python, Java and C++)

Assume that avg_citrus_pH has been declared and initialized; all you need to do is invoke a print statement and then append the variable

In Python, use print()

In c++, use cout<<

In Java, use System.out.print()

So, the statements are:

Python:

print("The average pH of citrus fruits is ",avg_citrus_pH)

Java

System.out.print("The average pH of citrus fruits is "+avg_citrus_pH);

C++

cout<<"The average pH of citrus fruits is "<<avg_citrus_pH;

8 0
2 years ago
A(n) ________ file contains data that has been encoded as text, using one of the computer's encoding schemes.
tangare [24]

Hello there

the answer is text

hope this helps

Queen Z

8 0
2 years ago
Read 2 more answers
HELP! Answer to question 2?
Vesnalui [34]
One advantage of Binary Search Algorithm: 
Compared to Linear search it is much faster because linear search starts its searching right from the first value but binary searches for something by splitting the array in two again and again and again. 

One disadvantage of Binary Search Algorithm:
Have to be sorted, unlike linear search that doesn't have to be. 
4 0
3 years ago
In Python please.
SOVA2 [1]

Answer:

negatives = []

zeros = []

positives = []

while True:

   number = input("Enter a number: ")

   if number == "":

       break

   else:

       number = int(number)

       if number < 0:

           negatives.append(number)

       elif number == 0:

           zeros.append(number)

       else:

           positives.append(number)

for n in negatives:

   print(n)

for z in zeros:

   print(z)

for p in positives:

   print(p)

Explanation:

Initialize three lists to hold the numbers

Create a while loop that iterates until the user enters a blank line

Inside the loop:

If the number is smaller than 0, put it in the negatives list

If the number is 0, put it in the zeros list

Otherwise, put the number in the negatives list

When the while loop is done, create three for loops to print the numbers inside the lists

5 0
3 years ago
Quick!! I'm TIMED!!!
agasfer [191]

Cloud suites are stored at a(n) option d. server on the Internet, rather than on your microcomputer.

<h3>What is a cloud at the Internet?</h3>

"The cloud" refers to servers which might be accessed over the Internet, and the software program and databases that run on the ones servers. Cloud servers are positioned in facts facilities all around the world.

A cloud suite is a cloud computing version that shops facts at the Internet via a cloud computing company who manages and operates facts garage as a service. It's brought on call for with just-in-time capability and costs, and gets rid of shopping for and handling your very own facts garage infrastructure.

Read more about the cloud suites :

brainly.com/question/5413035

#SPJ1

5 0
2 years ago
Other questions:
  • Shania has started a new job as an app developer. Her first task was to make an old app designed for Android available on other
    6·1 answer
  • A software license gives the owner the to use software.
    12·2 answers
  • What is a VIN and what role does it play during a criminal investigation? Explain how a VIN could help in a bomb and/or arson ca
    12·1 answer
  • In round-robin scheduling,a) the time quantum should be larger than the context switch time. b) the time quantum should be as sm
    15·1 answer
  • What is the meaning of photography​
    5·2 answers
  • Which of the following is true about advertisements?
    15·1 answer
  • What was software for modems that connected through phone lines called?
    6·1 answer
  • Why is the yellow light blinking on the front of my computer
    10·1 answer
  • Which of these technologies has been most used by terrorist organizations?
    6·1 answer
  • Bank Account Postings While reviewing your checking account balance online, you notice that debit card purchases have not posted
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!