Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Stacks and the STL library Objective The objective of the homework assignment is to create a calculator program. The program will ask the user to

Stacks and the STL library

image text in transcribed

image text in transcribed

image text in transcribed

Objective The objective of the homework assignment is to create a calculator program. The program will ask the user to enter a mathematical expression as an infix expression and your program will do two things. 1) It will covert the infix expression to postfix expression and display the result and 2) It will evaluate said expression. Program Details The program will only work with single integer digits (0, 1, 2, ..., 9) and the class string. There will be a minimum of three (3) functions: main, InfixToPostfix, and Evaluate. main: The main function will ask the user to enter an infix expression as a string and call the function InfixToPostfix passing the string as an argument. Then main will pass the string that InfixToPostfix returns to a function call to Evaluate. Main will then display the infix string the user enter, the postfix string, and finally the answer from Evaluate. Finally, main will ask the user if they wish to calculate another expression. InfixToPostfix: The function will take as argument a string and return a string. The purpose of the function is to use the STL library stack and the algorithm we discussed in class to convert an infix string expression to a postfix string expression. Evaluate: The function will take as argument a string and return a double (yes, you read that right). It will return a double because there could be an integer division! The purpose of the function is to use the STL library stack and the other algorithm we discussed in class to evaluate a postfix mathematical expression. Operators: What kind of operators are we going to work with? Simple math operators +, 0, 0, 0, and exponent/power function. where is for an Notes You can create and use more functions if you like, however, the only requirement will be to have at least the three functions mentioned in the Program Details. Make sure you follow the Coding Style Guidelines ! You can use the cctype library for the isdigit function and the cmath library for the power/exponent function (pow). Lastly, your program should work if the user enters spaces or no spaces between the values and operators. Enter an infix expression to evaluate: (3 + 5) * (4 + 3 / 2) - 5 Infix: (3 + 5) * (4 + 3 / 2) - 5 Postfix: 35 + 4 3 2 / + * 5 - Ans: 39 Would you like to try again (Y/N)? Y Enter an infix expression to evaluate: 7 * 6 + 5 Infix: 7 * 6 + 5 Postfix: 76 # 5 + Ans: 47 Would you like to try again (Y/N)? y Enter an infix expression to evaluate: 3 + (4 * 5) Infix: 3+ + (4 * 5) Postfix: 3 4 5 * + Ans: 23 Would you like to try again (Y/N)? y Enter an infix expression to evaluate: 3 + 6 * 7 * 8 - 3 Infix: 3 + 6* 7 * 8 - 3 Postfix: 3 6 7 * 8 * + 3 - Ans: 336

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

How would you feel if you were involved in such an ambush?

Answered: 1 week ago