Homework 3

CS18

60 pts., due Mar. 22

C++ does not have a data type fraction for the rational numbers. Specify and implement an ADT fraction that addresses this deficiency. Provide operations that read, write, add, subtract, multiply, and divide fractions. Provide a constructor with default parameters that will either create a fraction with a default value of 0 or initialize it to a specified value. The results of all arithmetic operations should be in lowest terms, so include a private function ReduceToLowestTerms. Exercise 19 in Chapter 2 of Carrano will help you with the details of this function. To simplify the determination of a fraction's sign, you can assume that its denominator is positive.

The class declaration should be put in a local include file. The method definitions should be put into their own source file (as demonstrated in class). Write a driver program (in its own source file) that demonstrates the features of your class.

Turn in your data type specification, copies of your source code (three files), and an example run with the input and output.



Thomas P. Kelliher
Thu Mar 14 13:13:57 EST 1996
Tom Kelliher