CS120
Assignment #7
Due on or before October 11 at 11:59 PM.
For this assignment you will be creating and testing a fraction class.
The fraction class should have the following features:
- The class should have two private data members: a numerator and a denominator.
- A function that takes two integers as inputs and
sets the numerator and denominator of the fraction
object. The function should check that the denominator is not zero and set the
fraction to 0 over 1 if the denominator is zero.
- A print function that prints a fraction object as an improper fraction,
e.g. 6/4.
- A print function that prints a fraction object as a mixed number,
e.g. 1 2/4.
- A print function that prints a fraction object as a decimal,
e.g. 1.5. Each of these print functions should have a different name.
- An add function that adds two fractions. Or you could overload the + operator to add fractions.
- A subtract function that subtracts two fractions.
Or overload the - operator to subtract fractions.
- A multiply function that multiplies two fractions.
Or overload the * operator to multiply fractions.
- A divide function that divides two fractions.
Or overload the / operator to divide fractions.
To test the fraction class, create at least three different fraction objects
and use these instances to test all of the above functions.
Be sure to test each instance with different data to ensure that your fraction class is working correctly.
Turn in: Use the script command to demonstrate how your program runs.
Place the output from the script command into a file named Assignment7output.txt.
If you can't finish all of the specified functionality, turn in as much as you complete, but what you turn in must compile and run.
Turn in a copy of your program code and the Assignment7output.txt file to Canvas.