class Farey { private: int Top, Bottom; public: Farey(); Farey(int T, int B); Fa
ID: 3666696 • Letter: C
Question
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 X(1, 2), Y(2, 4);
if ( X == Y ) // line 5
cout << "X == Y" << endl;
else
cout << "X != Y" << endl;
if ( X + X == Y ) // line 6
cout << "X + X == Y" << endl;
else
cout << "X + X != Y" << endl;
When the if statement beginning in line 6 is executed, what is written to cout?
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 X(1, 2), Y(2, 4);
if ( X == Y ) // line 5
cout << "X == Y" << endl;
else
cout << "X != Y" << endl;
if ( X + X == Y ) // line 6
cout << "X + X == Y" << endl;
else
cout << "X + X != Y" << endl;
When the if statement beginning in line 6 is executed, what is written to cout?
A) "X + X == Y"B) "X + X != Y"
Explanation / Answer
Ans: Option A..
if( X + X == Y)
A) "X + X == Y"
Explanation:
First X + X will do the addition operation with the help of operator + overloading ..and result will return
then result will compare with Y value..so both left hand side and right hand values are equal..
so the result is X + X == Y..Option A
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.