Friend Function That Builds a New Object
mediumQuestion 178Create 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, so print one after the last line.
Hints3 available
Sign in to use hintsTopics
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.