Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Done in Cygwin using g++ compiler This is a three part project: Part one - build a program that: Prompts the user for a string

Done in Cygwin using g++ compiler

This is a three part project:

  • Part one - build a program that:
    • Prompts the user for a string of user input .
    • Treat that string as a mathematical expression in an infix form.
    • Convert the string into a series of tokens where each token is an operator, or a value delimited by whitespace , operator, or
  • Part two -
    • Convert to postfix and print out the results. ( or print out an error if badly formed)
  • Part Three - further.
    • Do the math to evaluate the expression when all operands are values ( not variables)

For this project the operators you will support are:

Plus +

Minus -

Times *

Divide /

Modula %

When I test the program I would expect to see something like this: ( Bold is what I enter on the command line)

Input an expression: A+ B * 31

Tokens: A + B * 31

Postfix: A B + 31 *

Value: Cannot be calculated

Input and Expression: 3+4*12

Tokens: 3 + 4* 12

Postfix: 3 4 12* +

Value: 51

If the input expression is invalid, print out that fact. Use exceptions to catch any error conditions.

(Note - put a space between each Token for clarity)

How do you look at a string and know what the operands vs operators. IE if the input string is:

A+FRED+23*13-GG OR A + FRED +23* -GG

How do you identify that the tokens are A, FRED, 23, * etc. - and which tokens are operands vs operators?

The easiest way is with a stack.

Put the first character on the stack.

Keep putting characters on until you see an unpend char ( a space) OR an operator or a

Pop the chars off the first stack onto a second

Pop the chars off the second stack ( now they are in proper order)

Pass the token to your infx to postgix code.

If you have an operator.Send that

Repeat until no more characters.

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

=+What would be the level of autonomous expenditures?

Answered: 1 week ago