CSC 309 Object-Oriented Programming in C++
Homework #5
Due: Feb 7 [Loop], 8 [DL] (1 week)

Write a class called Fraction and an application program which tests the class.  Your job is to write 3 files, completely from scratch.

  1. Fraction.h -- header file
  2. Fraction.cpp -- implementation file
  3. FractApp.cpp -- application file

To set up the header file and implementation file (with macroguard and #include's), review the previous homework assignments.


1. Class Fraction (in "Fraction.h" and "Fraction.cpp")

Fractions are of the form a / b, where a is the numerator and b is the denominator, and a,b are integers (and b is not 0). In addition to the two int data members, provide the following methods (16 class methods and 1 regular function):

Notes on the methods and functions:


2. Application (in "FracApp.cpp")

Write an application which tests all the methods you wrote.  The output of the program should be:

1/3 + 5/8 = 23/24
1/3 - 5/8 = -7/24
1/3 * 5/8 = 5/24
1/3 / 5/8 = 8/15
-(1/3) = -1/3

24/21, after reduce(), 8/7
5/8, after reduce(), 5/8

2/-3, after standardize(), -2/3
-2/-3, after standardize(), 2/3

11/15 < 17/23 is true
11/15 <= 17/23 is true
11/15 > 17/23 is false
11/15 >= 17/23 is false
11/15 == 17/23 is false
11/15 != 17/23 is true

11/15 < 22/30 is false
11/15 <= 22/30 is true
11/15 > 22/30 is false
11/15 >= 22/30 is true
11/15 == 22/30 is true
11/15 != 22/30 is false

Write necessary code to produce this output.  Of course you must create appropriate Fraction objects and call methods to produce the results.
NOTE: There is no interaction with the user in the program.


Submission