Display the resulting answers to the screen

Assignment Help Basic Computer Science
Reference no: EM13996570

In reverse Polish notation the operators follow their operands. To add 3 and 4, one would write "3 4+" rather than "3 + 4". If there are multiple operations, the operator is given immediately after its second operand. The expression written "3 - 4 + 5" would be written "3 4- 5 +" in RPN: first subtract 4 from 3, then add 5 to that. An advantage of RPN is that it obviates the need for parentheses that are required by infix notation.

Your assignment is to produce a Reverse Polish Notation calculator that operates on input files.

1. First, ask the userfor the location of an input text file. Open this file.

2. Read in the input text file, and interpret the input data as RPN. Each line in the file should be interpreted as its own math problem.

3. Display theresulting answers to the screen, with each output line corresponding to the input lines.

4. If a math problem has an error in its syntax, display SYNTAX ERROR for that line and continue with the next problem.
Do not support unary operators. The user will not beable to enter negative numbers. (However, your program must still be able to handle internal numbers that are negative and negative results.)
Add support for the following binary operators, written exactly as shown: + - * / % pow
The pow operator should raise the first operand to the power of the second operand. The % operator should perform modulo division. The C standard library supports modulo division of floating point numbers, whereas the built-in C++ modulo division operator only supports integer division. You will need to usethe library function in order to handle the potential decimal number inputs from the user.

Support decimal number inputs as well as integer number inputs.
Implement operators using good object oriented design techniques. Represent each type of data the user could enter as a class. There should be anoperandclass that represents anumber, and several classes that inherit froma base class ofoperator, which represents each operator implemented. The base operatorclass should have a function that applies the operator to two operands that are passed in as arguments to the function. Each operator class that inherits should then override the function with one that actually performs that operation. Each child class should also have agetter that returns the operator symbol.Allof these classes should inherit from a common ancestor class namedsymbol. Example boilerplate code follows:
class symbol { };

class operand : public symbol { ... };

class operator : public symbol { ... };

class add : public operator { ... };

...

class pow : public operator { ... };
You should take the input expressions and create the appropriate classes to represent the input data, and then run the functions on that data to obtain your result.
You maynotstore type information about the classes in the classes themselves. i.e. Do not do what we did with the type field in rock/paper/scissors.
Your project submission should be logically laid out and use good object oriented design. Pretend that this project might one day be extended by additional developers by adding additional operators or other features. Points may be deducted if your assignment does not allow for flexibility in the program.
There will be oneor more whitespace characters between two numbers. There will be zeroor more whitespace characters between a number and a symbol or two symbols.
Sample Input:

3 4 5.0 * -

7

4. * 8 30 +

banana

9 10 + 30 -

4. 7 3-+ 2 -3+

900 40.65- 20 +

45.2 23.999%

Sample Output:

-17

7

SYNTAX ERROR

SYNTAX ERROR

-11

9

879.35

21.201

Reference no: EM13996570

Questions Cloud

Functionality for a contact management system : logging in a user, and maintaining contact information. Within each use case, create the expected flow (happy-path) and one alternate flow (an exception).
Find the various changes in entropy due to melting of ice : Find the various changes in entropy due to the melting of the ice. What is the change in entropy, NS, of the block of ice? What is the change in entropy, NS, of the lake?
How fast will this person have to crank the hand pedals : A subject weighing 140 pounds wants to exercise at 4 METs on the arm ergometer. If the resistance is set at 1.5 kp, how fast will this person have to crank the hand pedals (assume the flywheel moves 2.5 m per pedal revolution)?
What is your opinion of customer service : What is your opinion of customer service? Is this something only marketing or the customer service department should emphasize, or is customer service something that should be a priority with everyone in the organization
Display the resulting answers to the screen : Read in the input text file, and interpret the input data as RPN. Each line in the file should be interpreted as its own math problem.
What amount of air passing per minute through wtg swept area : What is the amount of air passing per minute through the WTG swept area if the rotor radius is 40m, the air flux is 12 kg/((m^2)*(s^2)). would the amount of air passing through change if the temperature changed on site with +7C degree? (Yes or No,..
What is your opinion or experience with free samples : What is your opinion or experience with free samples? Do they work? Apparently they do for some companies selling product at Costco? What businesses are there today that should probably avoid free sampling
How it might be used for the small business : Analyze several of the possible choices for CPU, memory, storage, and input/output peripherals, and then make a recommendation for a specific file server solution. Justify the choices that you recommend.
What is the momentum of the system : What is the momentum of the system? Determine the speed and mass of the second particle emerging from the collision.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Write your function so that it returns an array of dice

Write your function so that it returns an array of Dice structs. Each element in the array should be set to indicate one of the possible ways of rolling the sum. The last element in the array should be the special "sentinel" value where both die1 and..

  Assess the efficiency speed and accuracy of the storage and

evaluate the efficiency speed and accuracy of the storage and retrieval techniques that two 2 search engine

  Which scenario is one that shows a positive attitude

List three tasks commonly performed during preventive maintenance. Using good grammar (complete sentences), describe a drawback to using an infrared wireless keyboard. Now, describe a benefit. Using good grammar, describe two benefits of using a laye..

  Explain about how device works

Write down what first comes to mind as to what is good and bad about the way the device works. The range of tasks a typical user would want to do using it.

  Critical infrastructure protection

Critical Infrastructure Protection According to the text, Critical Infrastructure Protection (CIP) is an important cybersecurity initiative that requires careful planning and coordination in protecting our infrastructure.

  Analyse the effectiveness of the qantas

Analyse the effectiveness of the Qantas Online Air Ticketing system

  How do we implement the posix api

how do we implement the POSIX API

  Consider the three binary relations on the set of integers

consider the three binary relations on the set of integers z defined by a less than or equal to b ab if and only if ab

  Write a program that translates a number

Write a program (called Grades) that translates a number between 0 and 4 into the closest letter grade. For example, the number 2.8 (which might have been the average of several grades) would be converted to B-. Break ties in favor of the better g..

  Measuring it value

Measuring IT Value

  How many threads will you create to perform the input

How many threads will you create to perform the input and output and how many threads will you create for the CPU-intensive portion of the application

  Explaining multiple-level total

Whch of the following is an example of a multiple-level total? A total shown at the end of report for number of books in a library or Total shown every time the type of book changes (for example, reference, fiction, nonfiction).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd