C++ Project: Fraction Class, part 1
A Fraction Class
Imagine that the company you work for is going to create a lot of tutorials on Fractions. You are to create a robust Fraction class that will have all of the following (all examples are for a fraction half that has a numerator of 1 and a denominator of 2):
- Private integers numerator and denominator ;
- All public getter and setter functions for the numerator and denominator;
- Safeguard that the denominator will NEVER become 0!
- It is OK if the numerator is negative.
- a default constructor with no arguments;
- a constructor that accepts both the numerator and denominator;
- a toDecimal method that returns the decimal value of the fraction, example: 1/2 will be 0.5;
- a toString method that will return the fraction as a string, , example: 1/2 will be "1/2";
- a reduce method that will change the numerator and denominator by finding a common denominator and reducing the fraction. Example 3/12 becomes 1/4;
- Overload ==, <, <=, >, >= operators (use the decimal values to compare);
- Overload = operator (assigns the numerator and denominator to the fraction);
- Overload ++ so that 1/3 becomes 2/3 for example.
- Overload -- so that 2/3 becomes 1/3 for eaxample.
Submit the following as part of this assignment:
- Instead of a flowchart, you are to include a representation of the class as shown on page 715 of the text.
- The class definition and main in one cpp file (similar to the one for the Rectangle example.)
- Sample output showing several different fractions and an example where the user tried to assign 0 to the denominator. Your output should show all of the methods listed above.
This web site, and all pages therein, are the sole property and responsibility of Zebra0.com.
It is not endorsed, sponsored, or provided by or on behalf of Montgomery College.