Homework Solution: inclode estrig> include traction.h using nanespace std void Basicrest void RelationTest…

    C++: I need help with the following program, please. I'll provide a client program and correct output Write a class to handle objects of type Fraction. In its simplest form, a Fraction is just two integer values: a numerator and a denominator. Fractions can be negative, may be improper (larger numerator than denominator), and can be whole numbers (denominator of 1). Your class should support the following operations on Fraction objects: - Construction of a Fraction from two, one, or zero integer arguments. If two arguments, they are assumed to be the numerator and denominator, just one is assumed to be a whole number, and zero arguments creates a zero Fraction. Use default parameters so that you only need a single function to implement all three of these constructors. You should check to make sure that the denominator is not set to 0. The easiest way to do this is to use an assert statement: assert(inDenominator != 0); You can put this statement at the top of your constructor. Note that the variable in the assert() is the incoming parameter, not the data member. In order to use assert(), you must #include For this assignment, you may assume that all Fractions are positive. We'll fix that next week. - Printing a Fraction to a stream with an overloaded << operator. Next week we will get fancy with this, but for now just print the numerator, a forward-slash, and the denominator. No need to change improper Fractions to mixed numbers, and no need to reduce. - All six of the relational operators (<, <=, >, >=, ==, !=) should be supported. They should be able to compare Fractions to other Fractions as well as Fractions to integers. Either Fractions or integers can appear on either side of the binary comparison operator. You should only use one function for each operator. - The four basic arithmetic operations (+, -, *, /) should be supported. Again, they should allow Fractions to be combined with other Fractions, as well as with integers. Either Fractions or integers can appear on either side of the binary operator. Only use one function for each operator. Note that no special handling is needed to handle the case of dividing by a Fraction that is equal to 0. If the client attempts to do this, they will get a runtime error, which is the same behavior they would expect if they tried to divide by an int or double that was equal to 0. - The shorthand arithmetic assignment operators (+=, -=, *=, /=) should also be implemented. Fractions can appear on the left-hand side, and Fractions or integers on the right-hand side. - The increment and decrement (++, --) operators should be supported in both prefix and postfix form for Fractions. To increment or decrement a Fraction means to add or subtract (respectively) one (1). Additional Requirements and Hints: The name of your class must be "Fraction". No variations will work. - Use exactly two data members. - You should not compare two Fractions by dividing the numerator by the denominator. This is not guaranteed to give you the correct result every time. I would simply cross multiply and compare the products. - Don't go to a lot of trouble to find the common denominator (when adding or subtracting). Simply multiply the denominators together. - The last two bullets bring up an interesting issue: if your denominators are really big, multiplying them together (or cross multiplying) may give you a number that is too big to store in an int variable. This is called overflow. The rule for this assignment is: don't worry about overflow in these two situations. - My solution has 20 member functions (including friend functions). All of them are less than 4 lines long. I'm not saying yours has to be like this, but it shouldn't be way off. - Do not use as a resource a supplementary text or website if it includes a Fraction class (or rational or ratio or whatever).
    inclode estrig> include traction.h using nanespace std void Basicrest void RelationTest) void BinaryHathTest void Mathassig Tese string boolstringtbool convertMe) int main) BasicTest RelationTest( BinaryHathTestO Mathaaaigntest void Basictes cout esting basic fraction creation& printingin tractionio). eon:

    Expert Answer

     
    fraction header #ifndef FRACTION_H

    C++: I demand aid with the subjoined program, gladden. I’ll contribute a client program and emend extinguishedput

    Write a tabulate to touch objects of stamp Interest. In its simplest constitute, a Intecessation is equittelling brace integer values: a numerator and a denominator. Interests can be disclaiming, may be compulsory (larger numerator than denominator), and can be unimpaired total (denominator of 1).

    Your tabulate should assistance the subjoined operations on Intecessation objects:

    – Construction of a Intecessation from brace, undivided, or referablehing integer arguments. If brace arguments, they are conjectured to be the numerator and denominator, equittelling undivided is conjectured to be a unimpaired reckon, and referablehing arguments creates a referablehing Interest. Conservation cessationraintfeit parameters so that you merely demand a undivided unpremeditatedice to instrument perfect three of these producers.

    You should bridle to shape fast that the denominator is refertelling regular to 0. The easiest fashion to do this is to conservation an affirm declaration: affirm(inDenominator != 0); You can place this declaration at the apex of your producer. Referablee that the fickle in the affirm() is the incoming parameter, refertelling the axioms limb. In appoint to conservation affirm(), you must #include

    Restraint this enactment, you may appropriate that perfect Interests are overbearing. We’ll link that direct week.

    – Printing a Intecessation to a tide with an overloaded << operator. Direct week we accomplish achieve whim with this, save cessationraint now equittelling print the numerator, a cessationraintward-slash, and the denominator. No demand to veer compulsory Interests to modified total, and no demand to subdue.

    – Perfect six of the referableional operators (<, <=, >, >=, ==, !=) should be assistanceed. They should be telling to parallel Interests to other Interests as polite-mannered-mannered as Interests to integers. Either Interests or integers can apology on either verge of the binary similitude operator. You should merely conservation undivided unpremeditatedice cessationraint each operator.

    – The indecent basic arithmetic operations (+, -, *, /) should be assistanceed. Again, they should perfectow Interests to be utterly with other Interests, as polite-mannered-mannered as with integers. Either Interests or integers can apology on either verge of the binary operator. Merely conservation undivided unpremeditatedice cessationraint each operator.

    Note that no exceptional handling is demanded to touch the plight of dividing by a Intecessation that is similar to 0. If the client attempts to do this, they accomplish achieve a runage mistake, which is the similar proceeding they would wait-control if they mature to deal-extinguished by an int or wrap that was similar to 0.

    – The shorthand arithmetic enactment operators (+=, -=, *=, /=) should besides be instrumented. Interests can apology on the left-hand verge, and Interests or integers on the straight-hand verge.

    – The increment and adulteration (++, –) operators should be assistanceed in twain prelink and postlink constitute cessationraint Interests. To increment or adulteration a Intecessation media to subjoin or take (respectively) undivided (1).

    Additional Requirements and Hints:

    The call of your tabulate must be “Fraction”. No variations accomplish production.

    – Conservation precisely brace axioms limbs.

    – You should refertelling parallel brace Interests by dividing the numerator by the denominator. This is refertelling guaranteed to bestow you the emend effect integral age. I would merely peevish extend and parallel the products.

    – Don’t go to a doom of inconvenience to ascertain the low denominator (when subjoining or takeing). Merely extend the denominators contemporaneously.

    – The developed brace bullets induce up an sensational issue: if your denominators are unquestionably pompous, extending them contemporaneously (or peevish extending) may bestow you a reckon that is besides pompous to shop in an int fickle. This is determined exuberance. The government cessationraint this enactment is: don’t annoy environing exuberance in these brace situations.

    – My discerption has 20 limb unpremeditatedices (including messmate unpremeditatedices). Perfect of them are close than 4 outlines crave. I’m refertelling declaration yours has to be love this, save it shouldn’t be fashion unpremeditated.

    – Do refertelling conservation as a supplies a supplementary extract or website if it involves a Intecessation tabulate (or judicious or appurtenancy or whatever).

    inclode estrig> involve drink.h using nanespace std wanting Basiccessation wanting RelationTest) wanting BinaryHathTest wanting Mathassig Tese string boolstringtbool convertMe) int deep) BasicTest RelationTest( BinaryHathTestO Mathaaaigntest wanting Basictes cextinguished esting basic intecessation falsehood& printingin drinkio). eon:

    Expert Apology

     

    intecessation header

    #ifndef FRACTION_H
    #define FRACTION_H

    #involve <iostream> // cessationraint ostream, istream
    using callspace std;
    tabulate interest
    {
    public:
    int numerator, denominator;
    fraction(); // Regular numerator = 0, denominator = 1.

    fraction(int n, int d=1); // producer with parameters

    // gauge input/outplace routines
    wanting unravel(); // inplace a intecessation from keyboard.
    wanting print(); // Display a intecessation on screen

    // accessors
    int AchieveNumerator();
    int AchieveDenominator();

    private:
    int n; // apex allot (any integer)
    int d; // denom must be non-zero
    };

    #endif // FRACTION_H

    Intecessation cpp

    #involve “fraction.h”
    #involve <iostream>

    using callspace std;

    // limb unpremeditatedices
    fraction::fraction()
    {

    // Cessationraintfeit producer. Initializes intecessation to 0/1
    {
    numerator = 0;
    denominator = 1;
    }
    fraction::fraction(int n, int d)
    // initializes intecessation to n/d
    // validation of inplace subjoined in
    {
    if (SetValue(n,d) == counterfeit)
    SetValue(0,1);
    }
    wanting interest::read()
    // Achieve a intecessation from gauge input, in the constitute “numerator/denominator.”
    // Inplace validation subjoined in
    {
    char divSign; // conservationd to destroy the ‘/’ order during input
    do
    {
    cin >> numerator >> divSign >> denominator;
    if (denominator == 0)
    cextinguished << “Bad Interest. Try again: “;
    } timeliness (denominator == 0);
    }
    wanting interest::print()
    // Display a interest, in the constitute “numerator/denominator.”
    {
    cextinguished << numerator << ‘/’ << denominator;
    }
    int interest::GetNumerator()
    {
    return numerator;
    }
    int Interest::GetDenominator()
    {
    return denominator;
    }

    Here is the client program;

    #involve <iostream>
    #involve “fraction.h”
    #involve <fstream>
    #involve <cassert>
    using callspace std;
    wanting BasicTest();
    wanting RelationTest();
    wanting BinaryMathTest();
    wanting MathAssignTest();
    bool eof(ifstream& in);
    int deep()
    {
    BasicTest();
    RelationTest();
    BinaryMathTest();
    MathAssignTest();
    }
    wanting BasicTest()
    {
    cextinguished << “n—– Testing basic intecessation falsehood & printingn”;
    cextinguished << “(recalcitrant should be in subdued constitute, and as modified total.)n”;

    const intecessation fr[] = {fraction(4, 8), interest(-15,21),
    fraction(10), interest(12, -3),
    fraction(), interest(28, 6), interest(0, 12)};

    restraint (int i = 0; i < 7; i++){
    cextinguished << “intecessation [” << i <<“] = ” << fr[i] << endl;
    }

    // Comment the cessation of this unpremeditatedice extinguished until you complete writing the exdrink operator.
    cextinguished << “n—– Now unraveling interests from filen”;
    iftide in(“fraction.data”);
    assert(in);
    timeliness (!eof(in)) {
    intecessation f;
    if (in.peek() == ‘#’) {
    in.ignore(128, ‘n’); //skip this outline, it’s a comment
    } else {
    in >> f;
    cextinguished << “Unravel intecessation = ” << f << endl;
    }
    }
    }
    bool eof(ifstream& in)
    {
    char ch;
    in >> ch;
    in.putback(ch);
    return !in;
    }

    wanting RelationTest()
    {
    cextinguished << “n—– Testing referableional operators among interestsn”;
    const intecessation fr[] = {fraction(3, 6), interest(1,2), interest(-15,30),
    fraction(1,10), interest(0,1), interest(0,2)};
    restraint (int i = 0; i < 5; i++) {
    cextinguished << “Comparing ” << fr[i] << ” to ” << fr[i+1] << endl;
    cextinguished << “tIs left < straight? ” << (fr[i] < fr[i+1]) << endl;
    cextinguished << “tIs left <= straight? ” << (fr[i] <= fr[i+1]) << endl;
    cextinguished << “tIs left > straight? ” << (fr[i] > fr[i+1]) << endl;
    cextinguished << “tIs left >= straight? ” << (fr[i] >= fr[i+1]) << endl;
    cextinguished << “tDoes left == straight? ” << (fr[i] == fr[i+1]) << endl;
    cextinguished << “tDoes left != straight ? ” << (fr[i] != fr[i+1]) << endl;
    }

    cextinguished << “n—– Testing kinsmen among interests and integersn”;
    intecessation f(-3,6);
    int num = 2;
    cextinguished << “Comparing ” << f << ” to ” << num << endl;
    cextinguished << “tIs left < straight? ” << (f < num) << endl;
    cextinguished << “tIs left <= straight? ” << (f <= num) << endl;
    cextinguished << “tIs left > straight? ” << (f > num) << endl;
    cextinguished << “tIs left >= straight? ” << (f >= num) << endl;
    cextinguished << “tDoes left == straight? ” << (f == num) << endl;
    cextinguished << “tDoes left != straight ? ” << (f != num) << endl;

    intecessation g(1,4);
    num = -3;
    cextinguished << “Comparing ” << num << ” to ” << g << endl;
    cextinguished << “tIs left < straight? ” << (num < g) << endl;
    cextinguished << “tIs left <= straight? ” << (num <= g) << endl;
    cextinguished << “tIs left > straight? ” << (num > g) << endl;
    cextinguished << “tIs left >= straight? ” << (num >= g) << endl;
    cextinguished << “tDoes left == straight? ” << (num == g) << endl;
    cextinguished << “tDoes left != straight ? ” << (num != g) << endl;
    }
    wanting BinaryMathTest()
    {
    cextinguished << “n—– Testing binary arithmetic among interestsn”;

    const intecessation fr[] = {fraction(1, 6), interest(1,3),
    fraction(-2,3), interest(5), interest(-4,3)};
    restraint (int i = 0; i < 4; i++) {
    cextinguished << fr[i] << ” + ” << fr[i+1] << ” = ” << fr[i] + fr[i+1] << endl;
    cextinguished << fr[i] << ” – ” << fr[i+1] << ” = ” << fr[i] – fr[i+1] << endl;
    cextinguished << fr[i] << ” * ” << fr[i+1] << ” = ” << fr[i] * fr[i+1] << endl;
    cextinguished << fr[i] << ” / ” << fr[i+1] << ” = ” << fr[i] / fr[i+1] << endl;
    }
    cextinguished << “n—– Testing arithmetic among interests and integersn”;
    intecessation f(-1, 2);
    int num = 4;
    cextinguished << f << ” + ” << num << ” = ” << f + num << endl;
    cextinguished << f << ” – ” << num << ” = ” << f – num << endl;
    cextinguished << f << ” * ” << num << ” = ” << f * num << endl;
    cextinguished << f << ” / ” << num << ” = ” << f / num << endl;

    intecessation g(-1, 2);
    num = 3;
    cextinguished << num << ” + ” << g << ” = ” << num + g << endl;
    cextinguished << num << ” – ” << g << ” = ” << num – g << endl;
    cextinguished << num << ” * ” << g << ” = ” << num * g << endl;
    cextinguished << num << ” / ” << g << ” = ” << num / g << endl;
    }
    wanting MathAssignTest()
    {
    cextinguished << “n—– Testing shorthand arithmetic enactment on interestsn”;

    intecessation fr[] = {fraction(1, 6), interest(4),
    fraction(-1,2), interest(5)};
    restraint (int i = 0; i < 3; i++) {
    cextinguished << fr[i] << ” += ” << fr[i+1] << ” = “;
    cextinguished << (fr[i] += fr[i+1]) << endl;
    cextinguished << fr[i] << ” -= ” << fr[i+1] << ” = “;
    cextinguished << (fr[i] -= fr[i+1]) << endl;
    cextinguished << fr[i] << ” *= ” << fr[i+1] << ” = “;
    cextinguished << (fr[i] *= fr[i+1]) << endl;
    cextinguished << fr[i] << ” /= ” << fr[i+1] << ” = “;
    cextinguished << (fr[i] /= fr[i+1]) << endl;
    }

    cextinguished << “n—– Testing shorthand arithmetic enactment using integersn”;
    intecessation f(-1, 3);
    int num = 3;
    cextinguished << f << ” += ” << num << ” = “;
    cextinguished << (f += num) << endl;
    cextinguished << f << ” -= ” << num << ” = “;
    cextinguished << (f -= num) << endl;
    cextinguished << f << ” *= ” << num << ” = “;
    cextinguished << (f *= num) << endl;
    cextinguished << f << ” /= ” << num << ” = “;
    cextinguished << (f /= num) << endl;
    cextinguished << “n—– Testing increment/adulteration prelink and postfixn”;
    intecessation g(-1, 3);
    cextinguished << “Now g = ” << g << endl;
    cextinguished << “g++ = ” << g++ << endl;
    cextinguished << “Now g = ” << g << endl;
    cextinguished << “++g = ” << ++g << endl;
    cextinguished << “Now g = ” << g << endl;
    cextinguished << “g– = ” << g– << endl;
    cextinguished << “Now g = ” << g << endl;
    cextinguished << “–g = ” << –g << endl;
    cextinguished << “Now g = ” << g << endl;
    }