Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions