CISC 124 Assignment 4 Due Friday, April 2 Write an RPN calculator for complex numbers. The calculator should support the four arithmetic operations (+,-,*,/) on complex numbers. A complex number has a real and an imaginary part. For this program, it will be written as two numbers with a space between. The complex number "1.23 4.56" has 1.23 as the real part and 4.56 as the imaginary part. You can find on the Web the definitions of the four arithmetic operations on complex numbers. Reverse Polish Notation (RPN) is a notation for mathematical expressions which puts the operator at the end of (instead of between) the operands. RPN was developed by Jan Lukasiewicz in the 1920s and was used by the Hewlett-Packard's RPN calculators starting in the 1970s. More information is available at http://www.hpmuseum.org/rpn.htm and elsewhere on the Web. Briefly, with RPN, the expression "a + b" is written as "a b +" and the expression "a + (b / c)" is written as "a b c / +". As operands (a,b,c) are encountered in the input, they are pushed onto a stack. When an operator (+,-,*,/) is encountered, two operands are popped from the stack, the operator is applied, and the result is pushed back on the stack. Here's a sample of correct behaviour of an RPN calculator on complex numbers. Input is on the left. Output is on the right. Your program should duplicate this behaviour, with the output on the right. 1 1 3 4 + 4 5 3 1 - 1 4 3 2 4 -3 / 0.24 0.68 + 1.24 4.68 Here's what the stack looks like after each step: stack --------------> top 1 1 (1 1) 3 4 (1 1) (3 4) + (4 5) 4 5 3 1 (4 5) (3 1) - (1 4) 1 4 3 2 (1 4) (3 2) 4 -3 (1 4) (3 2) (4 -3) / (1 4) (0.24 0.68) 0.24 0.68 + (1.24 4.68) 1.24 4.68 So, after each operation, your program should print the element at the top of the stack, as shown in the sample output above. Note that the example above tells you the order in which the operators - and / apply to their operands on the stack. You are provided with a skeleton C++ program in these files: stack.h a complete, generic stack class rpn.cpp a skeleton main program complex.h a skeleton Complex class complex.cpp some skeleton I/O code for Complex For the Complex class, you have to provide arithmetic operators and accessors (in complex.h) and I/O operators (in complex.cpp). You have to provide the RPN calculator (in rpn.cpp). You don't need to touch the stack class. Quick Start for Unix/Linux -------------------------- unzip a4.zip; cd a4; make; ./rpn Less Quick Start for Windows Visual C++ .NET -------------------------------------------- Unzip the files into a directory 'a4' on your desktop. Start up Visual C++. Create a new project: Select File -> New Project. Select "Visual C++ Projects", "Win32 Project". Name it "a4". Click "Ok" (or whatever) to continue. On the next screen, click on "Application Settings". Select "console application". Select "empty project". Click "Ok" (or whatever) to continue. Add the four a4 files to the project: Select File -> Add Existing Item Select the four files in the a4 directory. Build the project: Select Build -> Build Run it: Select Debug -> Start