CSCI 216 Spring 2015
Project
#3
Date Due: 30
October 2015
Purpose: To reimplement
the fraction program using classes.
Program objective: This program will implement the fraction
library as a fraction class. In
addition, it will use the fraction class to build a reverse polish notation fraction
calculator.
Instructions: You
are to take the program you wrote for project 2 and re-implement it using
classes this time instead of structures and functions. You should have a fraction class which has a numerator
and denominator as private ints, and functions to
add, subtract, multiply, divide, print, and read as public member functions,
along with constructors and a destructor.
You should test this class using the same main program that you used for
project 2, and changing all the references to structures and functions to be references
to objects and member functions.
Don’t forget to
append your sample output to the end of your code as comments.
This is part
1. AFTER you have implemented your
fraction class, you now need to create a calculator class. THIS class should have four fraction
registers in it, x, y, z, and r, that act as a stack. If you type in a fraction and hit enter, that
fraction should go into the x register, what is in the x register should move
to the y register, what’s in the y register should move to the z register ,
what’s in the z register should move to the r register, and what’s in the r
register is lost.
You should
implement the for arithmetic operations +, -, *, and
/, which should take the fractions in the x and y registers and compute y+x, y-x, y*x or y/x, and then put the results back into
the x register. What was in the z
register should move to the y register, what was in the r register should move
to the z register and also stay in the r register.
You should have
a function that prints the register stack, an instruction that clears the x
register, an instruction that clears all the registers, and a circulate
instruction that rotates the registers so that what is in y goes to x, what is
in z goes to y, what is in r goes to z, and what is in x goes to r. Your instructions should look as follows:
Integer / nonzero
integer ENTER
Fraction
-> x -> y -> z -> r
+, -, *, /
y
+ x -> x, r -> z -> y
y
– x -> x, r -> z -> y
y * x -> x, r -> z -> y
y / x -> x, r -> z -> y
C clears the x
register
0
-> x; y, z, and r remain the same
E erases all
the registers
0
-> x, 0 -> y, 0 -> z, 0 -> r
P prints the
registers
contents of r, z, y, and x are printed in that
order, one per line
values in x, y, z, and r
are unchanged
R rotates the
registers
r -> z -> y -> x -> r
X exits the
program
You should
write a new main program that sits in a loop waiting for input from the
user. If the input is one of the above,
perform the action, ask for the next input, and wait. If the input is not a legal input, print an
error, ask for the next input, and wait.
Good luck and
have fun!