CJCoding With Joseph
15free / daySign inCreate account

Polymorphic print(ostream&)

An 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 — print one after the last line.

Hints4 available
Topics:
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.