Problem Solving with C++ (10th Edition)
Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 15, Problem 5PP

Consider a graphics system that has classes for various figures—rectangles, squares, triangles, circles, and so on. For example, a rectangle might have data members for height, width, and center point, while a square and circle might have only a center point and an edge length orradius, 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 member functions erase and draw. Each of these member functions outputs amessage telling what function has been called and what the class of the calling object is. Since these are just stubs, they do nothing more than output this message. The member function center calls the erase and draw functions to erase and redraw the figure at the center. Since you have only stubs for erase and draw, center will not do any “cantering” but will call the member functions erase and draw. Also add an output message in the member function center that announces that center is being called. The member functions should take no arguments.

There are three parts to this project:

a. Write the class definitions using no virtual functions. Compile andtest.

b. Make the base class member functions virtual. Compile and test.

c. Explain the difference in results.

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

Use the following main function for all testing:

//This program tests Programming Project 5. #include <iostream>

#include "figure.h"

#include "rectangle.h"

#include "triangle.h"

using std::cout;

int main( )

{

Triangle tri;

tri.draw( );

cout<<

"\nDerived class Triangle object calling center( ).\n";

tri.center( ); //Calls draw and center

Rectangle rect;

rect.draw( );

cout<<

"\nDerived class Rectangle object calling center().\n";

rect.center( ); //Calls draw and center

return 0;

}

Blurred answer
Students have asked these similar questions
Computer Programming Java
A company plans to create a system for managing of a movie store. The movie store has a name, address and phone number. Movies are described with title , genre, year of creation, number of sold copies and list of songs. The songs are described with name and duration. Design a set of classes and relationship between each other, which models the data of the record company. Implement a test class, which demonstrates the work of rest of the classes
Provide one example of where you might use polymorphism in your design of the library system and say which classes would be involved. Which class would be the base class?

Chapter 15 Solutions

Problem Solving with C++ (10th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License