← Back to Streams
Question 634
Polymorphic print(ostream&)
Polymorphic print(ostream&)
An abstract base classShapeis given in the starter with the pure virtual methodvirtual void print(ostream& out) const = 0;. Derive two classes from it: 1.Circle(int r)—Circle r=followed by the radius and a newline, e.g.Circle r=22.Rect(int w, int h)—Rect, the width, the letterx, the height and a newline, e.g.Rect 3x4Both overrides must write to theoutparameter, notcout. 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
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.