c) (5 points) Can these two operators be overloaded as member operators? Explain
ID: 3723407 • Letter: C
Question
c) (5 points) Can these two operators be overloaded as member operators? Explain your reason. (2) (5 points) Write a code fragment to (a) declare a Box object using the default constructor, (b) read the width, length, and height of a box using the input operator to the object just defined, and then (c) output the 3 dimensions for the object using the output operator. You may assume that the code is embedded in the main function. Don't write the complete program. oy 8ox() (3) (5 points) Overload the > operators (greater than operator) so you can compare two boxes. The> operator should return true if the first box's volume is bigger than the second box's volume, return false otherwise. Write the function definition only.Explanation / Answer
2)
Box b;
int w, l, h;
cin >> w >> l >> h; // input width, length and height from console
b.setLength(l);
b.setWidth(w);
b.setHeight(h);
cout << "Width: " << b.getWidth() << endl;
cout << "Length: " << b.getLength() << endl;
cout << "Height: " << b.getHeight() << endl;
3)
bool operator>(Box &b);
bool Box::operator>(Box &b) {
return volume() > b.volume();
}
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.