Consider the following class. class FeetInches {public: int feet;//To hold a num
ID: 3843506 • Letter: C
Question
Consider the following class. class FeetInches {public: int feet;//To hold a number of feet int inches;//To hold a number of inches}; a) Inside the class, add a function for overloading addition (+) operator. This function will create a new object whose data members will be the sum of this and parameter object of the same class (e.g., feet member of new object will be the sum of the feet of this object and feet of parameter object. Similarly, inches member of new object will be the sum of inches of this object and inches of parameter object. The function will return the new object. b) Overload the equality (-) operator. The function compares two objects of the given class. It returns true if two objects are equal and false otherwise. It first checks whether feet data member of two objects are equal or not If feet data members of two objects are equal, then it checks whether inches data member of two objects are equal or not. c) Overload the stream insertion (Explanation / Answer
class sample { private : int x; public : sample(int x1 =0) { x = x1; } sample operator+(sample s); }; sample sample::operator+(sample s) { x = x + s.x; return *this; } int main() { sample s1(10); sample s2; s2 = s2 + s1; return 0; }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.