CS120
Lab #7
Due at the end of lab.
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 functon that takes two integers as inputs and
sets the numerator and denomenator of a fraction
object. The function should check that the denomiator 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 fraciton object as a decimal,
e.g. 1.5. Each of these print functions should have it's own name.
- An add function that adds two fractions. Or 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.
- Extra Credit: Write functions that allow an integer
to be added to, subtracted from, etc. a fraction object.
To test the fraction class create at least three different fraction objects
and use them to test all of the above functions.
Turn in: A copy of the program and sample output showing it runs.
As always, if you cannot finish all of the functionality turn in as much
as you complete - as long as your code compiles and runs.