Question: We are going to design an abstract data type (ADT) called Fraction. A Fraction consists of two atomic entities: a numerator and a denominator. The

We are going to design an abstract data type (ADT) called Fraction. A Fraction consists of two atomic entities: a numerator and a denominator. The numerator and denominator must be integer data types and they must be private attributes in the Fraction class. The denominator should never be zero, since division by zero is mathematically undefined. The responsibilities of the Fraction class must include:

Constructors:

Default Constructor

Parameterized Constructor

Mathematical Operations:

Reduction (Reduces a fraction to its lowest terms; for example 2/4 reduces to 1/2)

Addition (Adds two fraction objects and returns the sum in its reduced form)

Multiplication (Multiplies two fraction objects and returns the product in its reduced form)

Division (Divides two fraction objects and returns the quotient in its reducd form)

Reciprocal (Returns the reciprocal of a fraction object)

Comparison Operations:

Equal To (Returns true if two fraction objects are equivalent)

Less Than (Performs a less than comparison between two fraction objects)

Greater Than (Performs a greater than comparison between two fraction objects)

Observer Functions:

Write (Prints the fraction to standard output in form numerator/denominator)

Get Denominator (Returns the value of the current denominator)

Get Numerator (Returns the value of the current numerator)

How do you create a new source code file called Fraction.h? This header file contains the specifications for the Fraction class. Your header file must include comments that specify preconditions, postconditions, and operation type (constructor, transformer, or observer). These comments define the formal interface for the class.

Here is how the structure of your header file should look like:

We are going to design an abstract data type (ADT) called Fraction.

Aclass Fraction { public: // Public Data & Function Members Go Here // Examples provided: // Precondition: Fraction otherFraction is an argument // Postcondition: Returns a Fraction that is sum of two Fractions // Operation Type: observer Fraction Add (Fraction otherFraction) const; 11 12 // Precondition: None 13 // Postcondition: Reduces the fraction object to its simplest terms 14 // Operation Type: Transformer/Mutator 15 void Reduce () ; 16 17 // Precondition: Fraction otherFraction is an argument 18 // Postcondition: Returns true if the two fractions are equal, false otherwise 19 // Operation Type: Observer 20 bool IsEqual (Fraction otherFraction) ; 21 22 private : 23 // Private Data & Function Members Go Here 24

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!