Question: you have to implement the class defined in the attached header file. you also need to implement a test program to test the validity of

you have to implement the class defined in the attached header file. you also need to implement a test program to test the validity of your implementation. your test program must use all overloaded operators and implemented functions.
# ifndef RATIONAL_H
# define RATIONAL_H
//forward references
class ostream;
class istream;
//
//class rational
//rational number data abstraction
//
class rational {
public:
// constructors
rational();
rational(int);
rational(int, int);
rational(const rational &);
// accessor functions
int numerator() const;
int denominator() const;
// assignments
void operator = (const rational &);
void operator += (const rational &);
void operator -= (const rational &);
void operator *= (const rational &);
void operator /= (const rational &);
// comparison
int compare(const rational &) const;
// conversions
operator float() const;
private:
// data areas
int top;
int bottom;
// operations used internally
void normalize();
};
//
//function prototypes
//
rational operator + (const rational &, const rational &);
rational operator - (const rational &, const rational &);
rational operator * (const rational &, const rational &);
rational operator / (const rational &, const rational &);
rational operator - (const rational &);
// comparison operations
int operator == (const rational &, const rational &);
int operator != (const rational &, const rational &);
int operator < (const rational &, const rational &);
int operator <= (const rational &, const rational &);
int operator > (const rational &, const rational &);
int operator >= (const rational &, const rational &);
// input and output functions
ostream & operator << (ostream &, const rational &);
istream & operator >> (istream &, rational &);
int floor(const rational &);
unsigned int gcd(unsigned int, unsigned int);
//
//inline functions
//
inline rational::rational() : top(0), bottom(1)
{
// no further initialization required
}
inline rational::rational(int numerator) : top(numerator), bottom(1)
{
// no further initialization required
}
inline rational::rational(const rational & value)
: top(value.top), bottom(value.bottom)
{
// no further initialization required
}
inline int rational::numerator() const
{
// return numerator field of rational number
return top;
}
inline int rational::denominator() const
{
// return denominator field of rational number
return bottom;
}
#endif

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 Databases Questions!