Home / Expert Answers / Computer Science / c-program-given-the-following-class-nbsp-rational-nbsp-similar-to-the-lab-7-write-the-definitio-pa675

(Solved): C++ Program : Given the following class Rational similar to the Lab 7, write the definitio ...



C++ Program : Given the following class Rational similar to the Lab 7, write the definition of the friend function inverse, which finds the inverse value of the object and output. Assume that numerator and denominator are not normalized, i.e., simplified, so you will need to normalize them before inverse and display. Make sure you place the sign correctly. Assume you have already included <cmath> and you can use the abs function to convert an integer to it’s absolute value. Also you can assume that a function "int gcd(int, int)" is already defined. For example, for numerator = 4 and denominator = 7, it should display 7/4; for numerator = 1 and denominator = -3, it should display -3; and for numerator = -12 and denominator = -15, it should display 5/4.

class Rational
{
public:
    Rational();
    Rational(int numer, int denom);
    int getNumerator();
    int getDenominator();
    friend void inverse(ostream& ost, const Rational& rat);
private:
    int numerator;
    int denominator;

};



We have an Answer from Expert

View Expert Answer

Expert Answer


// first inverse nu
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe