CS120
Lab #8
For this lab you will need to write a fraction class in a file named fraction.h.
A fraction has a numerator and a denominator. The details of the fraction
class are below.
A fractionTester.cpp has been provided here.
You will need to ensure you can compile your code and the fraction
tester to create an executable.
The file fraction.h should contain the following:
- Data Members appropriate to a fraction class
- int numerator
- int denominator
- Default value constructor that sets the numerator to 0 and the denominator to 1
- Explicit value constructor that sets the numerator and denominator to values specified by the user
- getNum(), which returns the numerator
- getDen(), which returns the denominator
- setNum(), which takes an int and sets the numerator
- setDen(), which takes an int (verifies it is not 0) and sets the denominator
- An equals Method, which takes two fractions as inputs and returns a Boolean value: true if fraction one's numerator and denominator are equal to fraction two's numerator and denominator and
false otherwise.
- An add Method
- An empty reduce method that doesn't do anything. Extra Credit: make the reduce() function actually reduce a fraction to lowest terms properly.
Notes
- See the fractionTester.cpp for the methods
- You are guaranteed that an integer will be entered for the numerator and the denominator. A rational number can be negative.
- Check the denominator for zero.
fractionTester.cpp - is provided for you - you do not have to write your own main()
- Contains two fraction objects
- fraction one which is a default object of 0/1
- fraction two which is an object that has a value of 2/3
- Contains a menu with the following choices
1) Change the value of the first fraction
2) Change the value of the second fraction
3) Display the value of the fraction one and fraction two
4) Compare the fraction one to fraction two checking if the numerator and the denominator are the same for both fractions
5) Add the fraction one to fraction two producing a new fraction
6) Quit
Turn in: use cscheckin to turn in your fraction.h file only.