Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ Consider a graphics system that has classes for various figures, say rectangles, squares, triangles, circles, and so on. For example, a rectangle might have

c++

Consider a graphics system that has classes for various figures, say rectangles, squares, triangles, circles, and so on. For example, a rectangle might have data members height, width, and center point, while a square and circle might have only a center point and an edge length or radius, respectively. In a well-designed system, these would be derived from a common class, Figure. It is your job to implement this system. First, implement the base class Figure. Then, implement two classes that are derived from Figure - Rectangle and Triangle. Each class should have stubs for the member functions erase() and draw(). Each of these member functions outputs a messagetelling what function has been called and what the class of the calling object is. Since these are just stubs, they should do nothing more than output the message. Also implement the member function center(). Typically, center() would call erase and draw to erase and redraw the figure at the center. However, since our functions are only stubs, center() will simply print a message saying that center() has been called from the respective class. It will then call erase() and draw(), which will each print out their own message. You should implement the base class functions as virtual functions. Finally, test your program in main() by creating a Triangle object and a Rectangle object and calling draw(), erase(), and center() on each object.

image text in transcribed

SAMPLE RUN #0: . /Figures Interactive Session Hide Invisibles Show Highlighted Highlight: None Only Triangle object.called.draw function.... Triangle object.called erase.function.... Derived Triangle.object.calling.center). Triangle object.called.center function.... Triangle object.called erase.function.... Triangle.object.called.draw.function... Rectangle object.called draw-function... Rectangle object.called.erase.function... Derived-class-Rectangle . object-calling. center() .* Rectangle object.called.center function.... Rectangle object.called erase.function.... Rectangle-object.called-draw-function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions