Problem

Visit www.myprogramminglab.com to complete select exercises online and get instant feedbac...

Visit www.myprogramminglab.com to complete select exercises online and get instant feedback.

Exercise

Consider a graphics system that has classes for various figures—say, rectangles, boxes, triangles, circles, and so on. For example, a rectangle might have data members’ height, width, and center point, while a box 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. You are to implement such a system.

The class Figure is the base class. You should add only Rectangle and Triangle classes derived from Figure. Each class has stubs for methods erase and draw. Each of these methods outputs a message telling the name of the class and what method has been called. Because these are just stubs, they do nothing more than output this message. The method center calls the erase and draw methods to erase and redraw the figure at the center. Because you have only stubs for erase and draw, center will not do any “centering” but will call the methods erase and draw. which will allow you to see which versions of draw and center it calls. Also, add an output message in the method center that announces that center is being called. The methods should take no arguments. Also, define a demonstration program for your classes.

For a real example, you would have to replace the definition of each of these methods with code to do the actual drawing. You will be asked to do this in Programming Project 1.

Project 1

Visit www.myprogramminglab.com to complete select exercises online and get instant feedback.

Exercise

Flesh out Programming Project. Give new definitions for the various constructors and methods center, draw, and erase of the class Figure; draw and erase of the class Triangle; and draw and erase of the class Rectangle. Use character graphics; that is, the various draw methods will place regular keyboard characters on the screen in the desired shape. Use the character for all the character graphics. That way, the draw methods actually draw figures on the screen by placing the character at suitable locations on the screen. For the erase methods, you can simply clear the screen (by outputting blank lines or by doing something more sophisticated). There are a lot of details in this project and you will have to decide on some of them on your own.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 8