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
For a parking management system, use the Observer pattern to implement this interaction using Java and implement the three classes mentioned below. Implement a ParkingObserver that has the role of the Observer. The Observable classes (Subjects) will be the ParkingLots. It would be helpful if the notify method in the subjects (and update method in the observers) took a parameter, perhaps an object of type ParkingEvent, which could have fields including the lot, timeIn, timeOut (if relevant), and permit. The ParkingObserver should register with each ParkingLot and receive the messages. Once a car enters (in an entry-scan only lot) or leaves (in an entry-scan and exit-scan lot), then the ParkingObserver will be updated, and then can register the charge with the parking system via the TransactionManager’s park() method. Based on these requirements you should implement three actor classes in this interaction using java: TransactionManager, ParkingObserver and ParkingLot. 1. The…
We have a parking office class for an object-oriented parking management system using java Add (implement )a method to the Parking Office c to return a collection of customer ids (getCustomerIds) using java I have attached two class diagrams with definitions of all related classes in our system (i.e car, customer, .....).  N.B. Parking office methods in the class defination like register, getcustomer and addcharge have already been implemented, we just need an additional getcustomerID method as mentioned above
We have a parking office class for an object-oriented parking management system using java Add (implement )a function to the Parking Office class to return a collection of customer ids (getCustomerIds) using java I have attached two class diagrams with definitions of all related classes in our system (i.e car, customer, .....).  N.B. Parking office methods in the class definition like register, getcustomer and addcharge have already been implemented, we just need an additional getcustomerID function as mentioned above Explain the code you wrote with a few words

Chapter 15 Solutions

Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th 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
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License