Programming Exercise (Chapter 2:Class) Object Oriented Porgramming

Exercise 1
Design a fraction class that would provide the capability for fractions to perform mathematical operations. The fraction class should have data members to represent the numerator and denominator (both integers) of a fraction object. It should be able to read and display a fraction and include operators for performing the common mathematical operations on fractions: add, subtract, multiply and divide. The design for fraction class is summarized as below.

 Each member function that performs an arithmetical operation is of type fraction. These functions return a fraction object that represents the result of the operation. The driver/ application program should test the arithmetic functions of class fraction. First, it calls readFrac to read two fractions (f1 and f2). It then uses the statement: f3 = f1.multiply(f2); to calculate f1 * f2 and assign the result to fraction f3. Next, it calls method displayFrac several times to display the fraction operands and the result of each arithmetic operation. A sample display can be viewed as follows.

Main Programme File


Class Declaration File

Function Definiton file

Post a Comment

0 Comments