The first part of this assignment is to define and implement a Fraction class. You should overload the following operators as member functions: +=, -=, *=, /=, = (assignment operator). You should also overload the following operators as non-member friend functions: (+, -, *, /, >>, <<, <, >, ==, !=, >=, <=). You should also implement a constructor that creates a fraction from a long.
Here is a starting point for your Fraction.h:
class Fraction {
...
public:
Fraction(long);
...
friend Fraction operator+(const Fraction &, const Fraction &);
Fraction & operator+=(const Fraction &);
...
}
The second part of this assignment is to implement a template function
that takes as arguments an array of ints, doubles, or Fractions and
the size of the array. The function should return the maximal value
(an int, double, or Fraction) that can be obtained by placing an
operator (+,-,*,/) between every two consecutive numbers in the array
and computing the resulting expression in the old calculator style.
For example, if the array is 1,2,3 then the maximal value is 1+2*3 =
9. If the array is 1/2, 3/4, 6/5 then the maximal value is 1/2 + 3/4
+ 6/5 = 49/20.
The third part of your assignment is to test your Fraction class and template function by implementing a main function that:
Example: joe@prelude% fractions
Please choose the number type ("int", "double", "fraction") or enter "quit": int
Please enter the size of the array: 3
Please enter a number: 1
Please enter a number: 2
Please enter a number: 3
The maximal value for 1,2,3 is 9!
Please choose the number type ("int", "double", "fraction") or enter "quit": fraction
Please enter the size of the array: 3
Please enter a number: 1/2
Please enter a number: 3/4
Please enter a number: 6/5
The maximal value for 1/2,3/4,6/5 is 49/20!
Please choose the number type ("int", "double", "fraction") or enter "quit": quit
joe@prelude%
Note: The red text is user input. The blue text is the output of your program.
Do all the following while logged into classes.cs.uchicago.edu.
hw4
.
main.cc
should begin with a comment
along the lines of /********************************************* * * * I, Joe Schmoe, a.k.a. jschmoe@cs, wrote * * and tested this program myself, without * * assistance or collaboration. * * * *********************************************/Of course, this does not preclude you from asking general questions about C++ (to anyone), or from asking the instructor or TA's for clarification of the assignment.
make
at
the command line. This should be set up to produce an executable file called
fractions
.
trial.txt
.
Choose the trial input carefully to demonstrate that your program functions
correctly even on "hard" cases. The contents of this file must agree with the
actual behavior of your program.
make distclean
should take care of
this for you.
cd ..
to change to the parent
directory.
hwsubmit 11600 hw4You should get a message indicating that the correct files are being copied. If you get error messages or no message, then send email to one of the TA's before the submission deadline.