|
CSIS 250 Summer 2000 Assignment #2Date Assigned: July 13, 2000 Date Due: July 18, 2000 at 10:00 AM Create a class called CRational for performing arithmetic with fractions. Information about fractions can be obtained at the following Web site. http://www.sosmath.com/algebra/fraction/frac3/frac3.html Write a main driver program and several test functions (one for each function member or friend function) to test your class. Use integer variables to represent the private data of the class-the numerator and denominator. Provide a constructor function that enables an object of this class to be initialized when it is declared. The constructor should contain default values (numerator = 1 and denominator = 1) in case no initializers are provided and should store the fraction in reduced form (i.e., the fraction 2/4 would be stored in the object as 1 in the numerator and 2 in the denominator). Provide the following functions: a) Constructor function with given values for numerator and denominator with default values b) constructor function to create a random fraction c) simplify function to simplify Crational numbers d) gcd function to calculate the greatest common divisor of two integers e) add function for two CRational numbers. The result should be stored in reduced form. f) subtract function for two CRational numbers. The result should be stored in reduced form g) multipliply function for two CRational numbers. The result should be stored in reduced form h) divide function for two CRational numbers. The result should be stored in reduced form i) display function for printing CRational numbers in the form a/b where a is the numerator and b is the denominator j) displayValue function for printing CRational numbers in floating-point format Self-Evaluation Sheet Project #2
Submit the following:
|