Ask Question
25 February, 17:54

Create a classRationalNumber (fractions, see problem 11.15 p. 639) with the following capabilities:a) Create a constructor that prevents 0 on the denominator in a fraction, reduces (or simplifies) fractionsthat are not in reduced form (lowest terms), and avoids negative denominatorsb) Overload the addition, subtraction, multiplication, and division operators for this class. c) Overload the relationaland equality = = operators for this class. Test all member functions and overloaded operators.

+1
Answers (1)
  1. 25 February, 18:01
    0
    See explaination

    Explanation:

    #include

    using namespace std;

    class a

    {

    int i, n, d, sn, sd, cond;

    public:

    void getdata ()

    {

    cout<<"Enter the numerator"<
    cin>>n;

    cout<<"Enter the denominator"<
    cin>>d;

    }

    void operator + (a a1)

    {

    if (a1. d!=d)

    {

    sn = (a1. n*d) + (n*a1. d);

    sd = (a1. d) * (d);

    }

    else

    {

    sn=a1. n+n;

    sd=a1. d;

    }

    if (sn>sd)

    {

    cond=sd;

    }

    else if (sd>sn)

    {

    cond=sn;

    }

    }

    void sum ()

    {

    for (i=2; i<=cond; i++)

    {

    if (sn%i==0 && sd%i==0)

    {

    sn=sn/i;

    sd=sd/i;

    }

    }

    cout<<"Sum is "<
    }

    a operator - (a a1)

    {

    a a3;

    if (a1. d!=d)

    {

    a3. sn = (a1. n*d) - (n*a1. d);

    a3. sd = (a1. d) * (d);

    }

    else

    {

    a3. sn=a1. n-n;

    a3. sd=a1. d;

    }

    return a3;

    }

    void sub ()

    {

    if (sn>sd)

    {

    cond=sd;

    }

    else if (sd>sn)

    {

    cond=sn;

    }

    for (i=2; i<=cond; i++)

    {

    if (sn%i==0 && sd%i==0)

    {

    sn=sn/i;

    sd=sd/i;

    }

    }

    cout<<"Subtraction is "<
    }

    a operator / (a a1)

    {

    a a4;

    a4. sn=a1. n*d;

    a4. sd=a1. d*n;

    return a4;

    }

    void div ()

    {

    if (sn>sd)

    {

    cond=sd;

    }

    else if (sd>sn)

    {

    cond=sn;

    }

    else if (sn==sd)

    {

    sn=1;

    sd=1;

    }

    for (i=2; i<=cond; i++)

    {

    if (sn%i==0 && sd%i==0)

    {

    sn=sn/i;

    sd=sd/i;

    }

    }

    cout<<"Division is "<
    }

    a operator * (a a1)

    {

    a a5;

    a5. sn=a1. n*n;

    a5. sd=a1. d*d;

    return a5;

    }

    void mul ()

    {

    if (sn>sd)

    {

    cond=sd;

    }

    else if (sd>sn)

    {

    cond=sn;

    }

    for (i=2; i<=cond; i++)

    {

    if (sn%i==0 && sd%i==0)

    {

    sn=sn/i;

    sd=sd/i;

    }

    }

    cout<<"Multiplication - "<
    }

    };

    int main ()

    {

    a a1, a2, a3, a4, a5, a6;

    a1. getdata ();

    a2. getdata ();

    a2 + (a1);

    a2. sum ();

    a3=a2 - (a1);

    a3. sub ();

    a4=a2 / (a1);

    a4. div ();

    a5=a2 * (a1);

    a5. mul ();

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Create a classRationalNumber (fractions, see problem 11.15 p. 639) with the following capabilities:a) Create a constructor that prevents 0 ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers