Ask Computer Engineering Expert

The goal of this test is for you to develop a calculator that will accept an arbitrary length algebraic expression that contains the standard operations (+,-,/, and *) and parentheses. The calculator must be able to accept real numbers (numbers containing decimals), rational numbers (numbers containing a fraction, which includes mixed numbers), or integers. Once the user presses the return key, the calcuator will display the RPN translation of the algrebraic expression, a space, an equal sign, and then the mixed number result.

When the program starts, a prompt such as INPUT: or EXPRESSION: must be printed. After each successful calculation, this prompt will re-appear asking for the next algebraic expression to enter. Naturally, if the user enters just the return key, then the program will terminate.

When the program starts, an appropriate message should appear that describes the functionality of the program.

What is RPN?

Reverse Polish Notation is a way of expressing arithmetic expressions that avoids the use of brackets to define priorities for evaluation of operators. In ordinary notation, one might prepare

(3 + 5) * (7 - 2)

and the brackets tell us that we have to add 3 to 5, and then subtract 2 from 7, and multiply the two results together. In RPN, the numbers and operators are listed one after another, and an operator always acts on the most recent numbers in the list. The numbers can be thought of as forming a stack, like a pile of plates. The most recent number goes on the top of the stack. An operator takes the appropriate number of arguments from the top of the stack and replaces them by the result of the operation.

In this notation the above expression would be

3 5 + 7 2 - *

Reading from left to right, this is interpreted as follows:
•Push 3 onto the stack.
•Push 5 onto the stack. The stack now contains (3, 5).
•Apply the + operation: take the top two numbers off the stack, add them together, and put the result back on the stack. The stack now contains just the number 8.
•Push 7 onto the stack.
•Push 2 onto the stack. It now contains (8, 7, and 2).
•Apply the - operation: take the top two numbers off the stack, subtract the top one from the one below, and put the result back on the stack. The stack now contains (8, 5).
•Apply the * operation: take the top two numbers off the stack, multiply them together, and put the result back on the stack. The stack now contains just the number 40

Polish Notation was devised by the Polish philosopher and mathematician Jan Lucasiewicz (1878-1956) for use in symbolic logic. In his notation, the operators preceded their arguments, so that the expression above would be written as

* + 3 5 - 7 2

The 'reversed' form has however been found more convenient from a computational point of view. Hewlett-Packard championed reverse Polish Notation for years, though it is rumored that their most recent calculators do not support it anymore, which is a pity. RPN is one of those things that can be difficult to learn, but wonderful to use once it is understood.



Algorithm to Convert Algebraic to RPN:

Edsger Dijkstra, one of the pilars of Computer Science, invented the Shunting-yard algorithm to convert infix expressions to postfix (RPN), so named because its operation resembles that of a railroad shunting yard. The link above is crucial to solving this problem.

In order to implement the Shunting-yard algorithm, you will be needing stacks and queues.

The Assignment Particulars:


Design a C++ program that will implement the following specifications for our command line calculator. You may use any resource that you wish to complete this assignment, excepting seeking help from any other individual. 

Clarification of the requirements may be asked during lab or during office hours.


Specifications:
•The calculator must read a complete algebraic expression that can consist of integers, decimals, fractions, or mixed numbers and present the result in proper form (fractions reduced, integer results must have just the integer and no 0/1, purely fractional results must not have a leading integer 0, negative signs must be in the proper places within mixed numbers, and so forth) Any expression that contains both decimals and fractions will provide the result in fractional / mixed number form.
•Your program must have the following classes: ?Mixed, which will have as part of it a data item of type Fraction
?Fraction, becuase you will be reading fractions on their own.
?Parser, a class that "figures out" what the user entered and prepares three things: an operand stack, an operator stack, and a queue which is the translation from algebraic to RPN.

•You MAY NOT use the STL stack or queue for this, as in you are being tested on your ability to prepare their equivalents. THIS MEANS THAT WRITING THE STACK AND QUEUE SPECIFIC TO THIS PROBLEM IS TOTALLY UNACCEPTABLE!!!!!!
•The stack and queue classes must implement their processes using dynamic arrays. Additionally, the stack and queue must not be adjusted between each user input line. This means that your parser class must check for exceptions and handle them accordingly. 
•The calculator should provide error messages for "algebriacally incorrect" entries (such as a missing closing parenthese, fractions that have a negative sign in the denominator, and so forth)
•For ease of parsing, the following rules must be followed: ?All operators must have at least one space on either side of them
?Mixed numbers can have only one space between the integer and the fraction
?Uninary minus signs must appear directly beside the value that they are making negative
?Visual display of the calculator should be aesthetically pleasing.

•You may use any resource you wish, as long as it can be FULLY DOCUMENTED within your code.
•You must be prepared to answer any problem about your program when you demonstrate its functionality during lab.



Hints:


Read the input character by charcter into a queue. ?If the character is a "(" or ")" this will dictate what to do with the input according to the Shunting-yard algorithm


Do not wait to start on this program. This is a standard problem for this level of a course at the four-year universities. At this level, this program should only take approximately 8 hours to complete.


Store all input as a mixed number or a fraction




Extra Credit:

Using the Qt graphics libaries, develop a windowing application that "look like" a calculator. "Look like" means that there will be keys for digits, operators, the fraction symbol, and an equal sign (which will signify end of input). As each key is pressed, the user should see their expression being built on the calculator (as in real life). Once the equal sign is pressed, the coverted expression will appear on another display with the answwer. (Note: calculators have a CLEAR and CLEAR ENTRY key, and they are required too).

Additional Requirements 

Level of Detail: Show all work 
Other Requirements: •REMEMBER, You MAY NOT use the STL stack or queue for this, as in you are being tested on your ability to prepare their equivalents. THIS MEANS THAT WRITING THE STACK AND QUEUE SPECIFIC TO THIS PROBLEM IS TOTALLY UNACCEPTABLE!!!!!!



Hints:

•Read the input character by charcter into a queue. ?If the character is a "(" or ")" this will dictate what to do with the input according to the Shunting-yard algorithm

•Do not wait to start on this program. This is a standard problem for this level of a course at the four-year universities. At this level, this program should only take approximately 8 hours to complete.

•Store all input as a mixed number or a fraction

 

 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M994519

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As