Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the class declaration: class Farey { private: int Top, Bottom; public:

ID: 3666698 • Letter: C

Question

Consider the class declaration:

class Farey {

private: int Top, Bottom;

public:

Farey();

Farey(int T, int B);

Farey operator+(const Farey& RHS) const;

Farey operator-(const Farey& RHS) const;

bool operator==(const Farey& RHS) const;

void Display(ostream& Out) const;

};

Farey::Farey() {

Top = Bottom = 0;

}

Farey::Farey(int T, int B) {

Top = T;

Bottom = B;

}

Farey Farey::operator+(const Farey& RHS) const {

return Farey(Top + RHS.Top, Bottom + RHS.Bottom);

}

Farey Farey::operator-(const Farey& RHS) const {

return Farey(Top - RHS.Top, Bottom - RHS.Bottom);

}

bool Farey::operator==(const Farey& RHS) const {

return ( (Top == RHS.Top) && (Bottom == RHS.Bottom) );

}

void Farey::Display(ostream& Out) const {

Out << Top << '/' << Bottom;

}

Consider the following code fragment:

Farey A(3, 5), B(1, 4), C(2, 4), D(0, 5), E;

E = A + B; // line 1

A.Display(cout); // 2

E = A + B ; // 3

E = E – C; // 4

After the execution of line 1, what are the values of E.Top and E.Bottom, respectively?

A) 0 and 0
B) 3 and 5
C) 4 and 9
D) 9 and 4
E) None of these

Explanation / Answer

Ans: Option C..

After Execution of E = A + B // Line 1
The values are E.top is 4 and E.bottom is 9..

i.e A + B => here A is object and B is object..with the help of operator + overloading addition of these two objects will done and then return the value to E with the help of operator = overloading ..
then result of E.top is 4 and E.bottom is 9..