Question: Solve the following Computer Science Program: Given the below rational class interface: class rational { friend istream & operator>> (istream&, rational&); //User is prompted to
Solve the following Computer Science Program:
Given the below rational class interface:
class rational
{
friend istream & operator>> (istream&, rational&);
//User is prompted to enter numerator then denominator for a rational number
//Postcondition: calling rational object is filled with values entered by user
friend ostream& operator<<(ostream&, const rational&);
//Postcondition: display the contents of the calling rational object in the format of a/b in simplified or reduced form
//by calling the private GCD function, e.g 1/2 (not 2/4) ,etc/ also , sign must be properly placed , e.g -7/8 (not 7/-8)
public:
void set (int aa, int bb);
//Postcondition : the calling rational object is set to aa/bb
rational operator - (const rational& r2) const;
//Postcondition : the result of (the calling rational object - r2), a rational object, is returned
bool operator> (const rational & r2) const;
//Note : you must use the overloaded ' operator -' defined above
//Postcondition: returns true if calling object is greater than r2; return false otherwise
int GCD () const;
//you must use the Eucledean algorithm
//Postcondition : returns the "greatest common divisor" between the numerator and enominator of the calling rational object
private :
int a; //numerator
int b; //denominator
};
Implement the following functions:
a) istream& operator>>(istream&, rational&);
b)ostream& operator<<(ostream&, const rational &);
c) void set (int aa, int bb)
d) rational operator - (const rational & r2) const;
e) bool operator> (const rational & r2) const;
f) int GCD const;
g) Write an internal function (i,e the function is not a member of a class) named sort that accepts a rational array r and an integer value n that representsthe numbers stored in the arraythat are to be sorted . The function then sorts the n rational numbers stored in the array in ascending order.
Please be advise you have to use it outside of the scope for example rational::
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
