Polymorphic print(ostream&)
mediumQuestion 634An abstract base class Shape is given in the starter with the pure virtual method virtual void print(ostream& out) const = 0;. Derive two classes from it:
1. Circle(int r) — print writes Circle r= followed by the radius and a newline, e.g. Circle r=2
2. Rect(int w, int h) — print writes Rect , the width, the letter x, the height and a newline, e.g. Rect 3x4
Both overrides must write to the out parameter, not cout.
Do NOT write a main function.
Expected output
Circle r=2 Rect 3x4 Rect 1x1 Circle r=10
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Streamsostream
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.