CJCoding With Joseph
15free / daySign inCreate account

Friend Function That Builds a New Object

Create a class Box with a private int volume set by its constructor, plus a public int getVolume() const. Write a friend function Box mergeBoxes(const Box& a, const Box& b) that returns a NEW Box whose volume is the sum of the two boxes' volumes.

The friend function needs direct access to the private volume of both boxes.

Do NOT write a main function.

Expected Output:

30
12

= newline. The output ends with a newline — print one after the last line.

Hints3 available
Topics:
ClassesFriend Functions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.