writtern in c This class implements rational number of the t

//writtern in c++//

This class implements rational number of the type 2/3.

Requirements:

Write a class Fraction;

The private data consists of: int num, (numerator of the fraction) and int den (denominator of the fraction).

The public interface consists of:

  Constructors that have two int args, to allow setting rational to any legitimate value

    one int arg, to construct rationals with arg numerator and denominator 1.

Overloaded operators << and >> to allow writing to screen in form 325/430 and reading from the keyboard in the same format. Overloaded operators + - * / < <= > >= ==

Notes: either num or den, or both may contain a negative integer . Please use the following main function to test your program :

int main()
{
    cout <<\"HELLO\ \";
    cout << \"Testing declarations \" << endl;
    cout << \"Fraction x, y(2), z(-5,-6), w(1,-3);\" << endl;
    Fraction x, y(2), z(-5,-6), w(1,-3);
    cout   << \"z = \" << z << \", y = \" << y << \", z = \" << z
            << \", w = \" << w << endl;
    cout   << \"Testing >> overloading: \ Enter a fraction in the format \"
            << \"integer _numerator/integer _denominator\" << endl;
    cin >> x;
    cout << \"You entered the equivalent of: \" << x << endl;
    cout << z << \" - (\" << w << \") = \" << z - w << endl;
    cout << \"Testing the constructor and normalization routines: \" << endl;
    y =Fraction(-128, -48);
    cout << \"y =Fraction(-128, -48) outputs as \" << y << endl;
    y =Fraction(-128, 48);
    cout << \"y =Fraction(-128, 48 ) outputs as \" << y << endl;
    y = Fraction(128,-48);
    cout << \"y = Fraction(128, -48) outputs as \" << y << endl;
    Fraction a(1,1);
    cout << \"Fraction a(1,1); a outputs as: \" << a << endl;
    Fraction ww = y*a;
    cout << y << \" * \" << a << \" = \" << ww << endl;
    w = Fraction(25,9);
    z = Fraction(3,5);
    cout   << \"Testing arithmetic and relational operator overloading\"
            << endl;
    cout << w << \" * \" << z << \" = \" << w * z << endl;
    cout << w << \" + \" << z << \" = \" << w + z << endl;
    cout << w << \" - \" << z << \" = \" << w - z << endl;
    cout << w << \" / \" << z << \" = \" << w / z << endl;
    cout << w << \" < \" << z << \" = \" << (w < z) << endl;
    cout << w << \" < \" << w << \" = \" << (w < w) << endl;
    cout << w << \" <= \" << z << \" = \" << (w <= z) << endl;
    cout << w << \" <= \" << w << \" = \" << (w <= w) << endl;
    cout << w << \" > \" << z << \" = \" << (w > z) << endl;
    cout << w << \" > \" << w << \" = \" << (w > w) << endl;
    cout << w << \" >= \" << z << \" = \" << (w >= z) << endl;
    cout << w << \" >= \" << w << \" = \" << (w >= w) << endl;
    w = Fraction(-21,9);
    z = Fraction(3,5);
    cout << w << \" * \" << z << \" = \" << w * z << endl;
    cout << w << \" + \" << z << \" = \" << w + z << endl;
    cout << w << \" - \" << z << \" = \" << w - z << endl;
    cout << w << \" / \" << z << \" = \" << w / z << endl;
    cout << w << \" < \" << z << \" = \" << (w < z) << endl;
    cout << w << \" < \" << w << \" = \" << (w < w) << endl;
    cout << w << \" <= \" << z << \" = \" << (w <= z) << endl;
    cout << w << \" <= \" << w << \" = \" << (w <= w) << endl;
    cout << w << \" > \" << z << \" = \" << (w > z) << endl;
    cout << w << \" > \" << w << \" = \" << (w > w) << endl;
    cout << w << \" >= \" << z << \" = \" << (w >= z) << endl;
    cout << w << \" >= \" << w << \" = \" << (w >= w) << endl;
return 0;
}

Solution

int main()
{
    cout <<\"HELLO\ \";
    cout << \"Testing declarations \" << endl;
    cout << \"Fraction x, y(2), z(-5,-6), w(1,-3);\" << endl;
    Fraction x, y(2), z(-5,-6), w(1,-3);
    cout   << \"z = \" << z << \", y = \" << y << \", z = \" << z
            << \", w = \" << w << endl;
    cout   << \"Testing >> overloading: \ Enter a fraction in the format \"
            << \"integer _numerator/integer _denominator\" << endl;
    cin >> x;
    cout << \"You entered the equivalent of: \" << x << endl;
    cout << z << \" - (\" << w << \") = \" << z - w << endl;
    cout << \"Testing the constructor and normalization routines: \" << endl;
    y =Fraction(-128, -48);
    cout << \"y =Fraction(-128, -48) outputs as \" << y << endl;
    y =Fraction(-128, 48);
    cout << \"y =Fraction(-128, 48 ) outputs as \" << y << endl;
    y = Fraction(128,-48);
    cout << \"y = Fraction(128, -48) outputs as \" << y << endl;
    Fraction a(1,1);
    cout << \"Fraction a(1,1); a outputs as: \" << a << endl;
    Fraction ww = y*a;
    cout << y << \" * \" << a << \" = \" << ww << endl;
    w = Fraction(25,9);
    z = Fraction(3,5);
    cout   << \"Testing arithmetic and relational operator overloading\"
            << endl;
    cout << w << \" * \" << z << \" = \" << w * z << endl;
    cout << w << \" + \" << z << \" = \" << w + z << endl;
    cout << w << \" - \" << z << \" = \" << w - z << endl;
    cout << w << \" / \" << z << \" = \" << w / z << endl;
    cout << w << \" < \" << z << \" = \" << (w < z) << endl;
    cout << w << \" < \" << w << \" = \" << (w < w) << endl;
    cout << w << \" <= \" << z << \" = \" << (w <= z) << endl;
    cout << w << \" <= \" << w << \" = \" << (w <= w) << endl;
    cout << w << \" > \" << z << \" = \" << (w > z) << endl;
    cout << w << \" > \" << w << \" = \" << (w > w) << endl;
    cout << w << \" >= \" << z << \" = \" << (w >= z) << endl;
    cout << w << \" >= \" << w << \" = \" << (w >= w) << endl;
    w = Fraction(-21,9);
    z = Fraction(3,5);
    cout << w << \" * \" << z << \" = \" << w * z << endl;
    cout << w << \" + \" << z << \" = \" << w + z << endl;
    cout << w << \" - \" << z << \" = \" << w - z << endl;
    cout << w << \" / \" << z << \" = \" << w / z << endl;
    cout << w << \" < \" << z << \" = \" << (w < z) << endl;
    cout << w << \" < \" << w << \" = \" << (w < w) << endl;
    cout << w << \" <= \" << z << \" = \" << (w <= z) << endl;
    cout << w << \" <= \" << w << \" = \" << (w <= w) << endl;
    cout << w << \" > \" << z << \" = \" << (w > z) << endl;
    cout << w << \" > \" << w << \" = \" << (w > w) << endl;
    cout << w << \" >= \" << z << \" = \" << (w >= z) << endl;
    cout << w << \" >= \" << w << \" = \" << (w >= w) << endl;
return 0;
}

//writtern in c++// This class implements rational number of the type 2/3. Requirements: Write a class Fraction; The private data consists of: int num, (numerat
//writtern in c++// This class implements rational number of the type 2/3. Requirements: Write a class Fraction; The private data consists of: int num, (numerat
//writtern in c++// This class implements rational number of the type 2/3. Requirements: Write a class Fraction; The private data consists of: int num, (numerat

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site