Question
help me fix Programm C++ please //Rational class definition Class rational { public: // constructors Rational(int num, int den); Rational(int whole_number); Rational(); // friend functions
help me fix Programm C++ please
//Rational class definition
Class rational
{
public:
// constructors
Rational(int num, int den);
Rational(int whole_number);
Rational();
// friend functions
// function to overload the >> operator
friend istream& operator>>(istreams, Rationals);
//function to overload the << operator
friend ostream& operator << (ostream&, const Rationals);
//function to overload the ==operator
friend bool operator==(const Rationals, const Rationals);
//function to overload the < operator
friend bool operator<(const Rationals, const Rationals);
//function to overload the <= operator
friend bool operator<=(const Rationals, const Rationals);
//function to overload the > operator
friend bool operator>(const Rationals, const Rationals);
//function to overload the > =operator
friend bool operator>=(const Rationals, const Rationals);
//function to overload the +operator
friend bool operator+(const Rationals, const Rationals);
//function to overload the -operator
friend bool operator-(const Rationals, const Rationals);
//function to overload the *operator
friend bool operator*(const Rationals, const Rationals);
//function to overload the /operator
friend bool operator/(const Rationals, const Rationals);
private:
int numerator;
int denominator;
}; // end of Rational class definition
// function prototypes
void fraction_normalization(int num, int den);
int qreatest_common_divisor( int number1, int number2);
// two parameters constructor Rational ( int, int)
Rational::Rational ( int num, int den)
{
/* call the fraction_normalization function to normalize the fraction*/
normalize the fraction*/
fraction_normalization( num, den);
numerator = num;
denominator= den;
// verify whether the denominator is zero
If( denominator == 0)
{
cout << Denominator should not to be zero. <<
end1;
system ( pause );
exit(1);
} // end if
} // end of constructor
// one parameter constructor Rational (int)
Rational : : Rational (int whole_number)
{
numerator = whole_number;
denominator = 1;
} // end of constructor
// default constructor
Rational : : Rational()
{
numerator=0;
denominator = 1;
} // end of constructor
// operator>> () function definition
istream operator >>(istream input, Rational frctn)
{
//local variable
char ch;
// read the fraction entered by user
Input>> front.numerator >> ch >> frctn. denominator;
// verify whether the second character is / or not
if (ch != /)
{
cout << Wrong input : << ch << end1;
System (pause);
exit(1);
}
/* call the fraction _ normalization function to normalize the fraction */
fraction_normalization(frctn.numerator, frctn denominator);
return input;
} // end of function
// operator << () function definition
ostream& operator <<(ostream& output , const Rational & frctn)
{
// display the simplified fraction to the user
output << front.numerator << / << frctn.denominator
return output;
} // end of function
// operator == () function definition
bool operator == ( const Rational& frctn1, const Rational& frctn2)
{
return frctn1.numerator * frctn2. denominator<
frctn2.numerator * frctn1.denominator;
} // end of function
// operator <= () function definition
bool operator <= ( const Rational& frctn1, const Rational& frctn2)
{
return frctn1.numerator * frctn2. denominator<=
frctn2.numerator * frctn1.denominator;
} // end of function
// operator > () function definition
bool operator > ( const Rational& frctn1, const Rational& frctn2)
{
return frctn1.numerator * frctn2. denominator>
frctn2.numerator * frctn1.denominator;
} // end of function
// operator >= () function definition
bool operator >= ( const Rational& frctn1, const Rational& frctn2)
{
return frctn1.numerator * frctn2. denominator>=
frctn2.numerator * frctn1.denominator;
} // end of function
// pause the system for a while
system(pause);
return 0;
} // end of main function
// fraction_ normalization function definition
void fraction_normalization(int& num, int& den);
{
// local variable
Int god;
// call greatest_common_divisor
god=greatest_common_divisor(num, den);
num= num/ god;
den= den / god;
// change the sign of the fraction if requirs
If ( num> 0 && den<0 || num <0 && den< 0)
{
num = - num;
den= - den;
} // end if
} // end of normalize function
// greatest_common_divisor ( int number1 , int number2)
{
// local variables
int temp;
Int remainder;
// get the absolute values
number1 = abs(number1);
number2= abs( number2);
// verify whether the number 1 is greater than number 2
If ( number1 > number2)
{
temp = number1;
number1 = number2;
number2 = temp;
}. // end if
// find the remainder
Remainder = number 1 & number2;
// repeat the loop until the remainder not equals to 0
while ( remainder !=0)
{
remainder = number1 & number 2;
number 1 = number 2;
number2 = remainder ;
} // end while
// return the god
Return number1;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started