Defining classes

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.
  1. Implement the setNumerator method to accept an integer parameter and set the numerator to that value
  2. Test it
  3. Implement the setDenominator method to accept an integer parameter and set the denominator to that value unless a 0 is entered
  4. Test it
  5. Create a getNumerator method that returns the value of the numerator
  6. Test it
  7. Create a getDenominator method that returns the value of the Denominator
  8. Test it
  9. Create a ReadNumerator method to place the value entered into a temporary and then invoke setNumerator
  10. Test it
  11. Create a ReadDenominator method to place the value entered into a temporary and then invoke setDenominator
  12. Test it
  13. Create a member function that sets both the numerator and the denominator:
    1. the method is to be called setRational
    2. the method is to have two parameters (numerator, denom)
    3. the method is to call setNumerator and setDenominator
  14. Test it
  15. Almost solution

For fun, write an application that uses the class. Write a menu driven application that gives the user 5 options
  1. Set the numerator of a rational number
  2. Set the denominator of a rational number
  3. Set both
  4. Print a rational number
  5. Quit the program