The purpose of this lab is to further your knowledge of how to correctly define
a class. Try to consider the user of your class - do you provide everything
they need? Do you make it simple for them? Do they need to know any details of your code?
This lab is based on the rational class
-
copy the code linked here into your C++
IDE.
Compile and run it.
- Implement the setNumerator method to accept an integer parameter
and set the numerator to that value
- Test it
- Implement the setDenominator method to accept an integer parameter
and set the denominator to that value unless a 0 is entered
- Test it
- Create a getNumerator method that returns the value of the numerator
- Test it
- Create a getDenominator method that returns the value of the Denominator
- Test it
- Create a ReadNumerator method to place the value entered into a temporary
and then invoke setNumerator
- Test it
- Create a ReadDenominator method to place the
value entered into a temporary
and then invoke setDenominator
- Test it
- Create a member function that sets both the numerator and the
denominator:
- the method is to be called setRational
- the method is to have two parameters (numerator, denom)
- the method is to call setNumerator and setDenominator
- Test it
- Almost solution
For fun, write an application that uses the class.
Write a menu driven application that gives the user 5 options
- Set the numerator of a rational number
- Set the denominator of a rational number
- Set both
- Print a rational number
- Quit the program