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
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; } |
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Concepts Of Programming Languages
Introduction to Programming Using Visual Basic (10th Edition)
Starting Out with Python (4th Edition)
Starting out with Visual C# (4th Edition)
- In this problem you will implement a simple library system based on object-oriented approach (using inheritance, polymorphism and abstract classes). At the library we have items and people are allowed to borrow them for a while or use them in the library premises. We have 3 types of items at the library. Books, Magazines and Compact Discs (CDs). All items have a unique number called serial number, shelf number that the item put on that shelf and shelf index, the index of the item at the shelf. Items at the library have additional different properties changing to item type. For example books have name, publisher name, and author name. CDs have title property and magazines have name, publisher properties. But people are allowed to borrow only books and CDs, but not magazines. Suppose that two kinds of people using library items. These are students and academic staff. Students can borrow only one item at a time, and academic stuffs can borrow at most 3 items at the same time. Also people…arrow_forwardDraw the UML class diagrams for the following classes: An abstract Java class called Person that has the following attributes: a String called idNumber a Date called dateOfBirth representing the date of birth. a String for name A class called VaccineRecord with the following attributes: an enum called type of VaccineType a Date called date a String called batchCode A class called Patient that extends the Person class and has the following attributes and behaviours: an ArrayList that contains VaccineRecord objects called vaccinationRecord a public method called vaccinate that takes a VaccineRecord with the following signature: public void vaccinate(VaccineRecord vaccineRecord); a public boolean method called isVaccinated that returns whether or not the Patient has had a vaccine. A MedicalPractitioner class that extends the Person class and has the following attributes and behaviours: a String called licenseCode a public method called vaccinatePatient that takes as a…arrow_forwardProgramming language is C. I would really be appriciate if you could help me with this. Please provide me with your cashapp, so I can tip you for your work. THANK YOU:) In this project, we shall simulate the operations of an ATM machine. Suppose you’re in charge of this simulation and here is a scenario of what is required to do: The customer will be assigned a random or fixed number for his/her balance. First, the customer is prompted to enter his personal identification number pin (for this case study, we test only if this pin is formed by 4 digits! otherwise, a message like “Invalid PIN, try again . . .” will be displayed) and the user is re-prompted to enter the pin. The customer is given three chances to enter his pin. If he/she fails during the three trials you display a message like “Sorry you can’t continue, contact your bank for assistance!” If the pin is correct (formed by 4 digits), then the system will ask the customer for the receipt ( 1 for YES and 2 for NO ) and a menu…arrow_forward
- Programing language is Java. Define a class Person that represents a person. People have a name, an age, anda phone number. Since people always have a name and an age, your class shouldhave a constructor that has those as parameters. Define a toString() method whichdisplays all of the relevant information using a format like this: “Jim Lahey - Age 57- Phone 9025555555”.arrow_forwardDefine a Polygon interface that has methods area() and perimeter(). Then implement classes for Triangle, Quadrilateral, Pentagon, Hexagon, and Octagon, which implement this interface, with the obvious meanings for the area() and perimeter() methods. Also implement classes, IsoscelesTriangle, Equilateral- Triangle, Rectangle, and Square, which have the appropriate inheritance relationships. Finally, write a simple user interface, which allows users to create polygons of the various types, input their geometric dimensions, and then out- put their area and perimeter. For extra effort, allow users to input polygons by specifying their vertex coordinates and be able to test if two such polygons are similar ORIGINAL WORKS ONLYarrow_forwardFor your first program, you are to write a simple Dodgeball simulation. In this simulation, we will have nplayers, and one ball. One player, the "thrower," will have the ball. The thrower will throw the ball at anotherplayer, the "target." The target could catch the ball, could be hit by the ball, or the ball could completely missthe target. If the target catches the ball, then the thrower is out of the game (and the target becomes the nextthrower.) If the ball hits the target, then the target is out of the game. If the ball misses the target, neitherplayer is out. In the latter two cases, any one can pick up the ball and become the next thrower. The game isover when only one player is left.In this simple version, the players (initially n players) will stand in a circle. The thrower will always countthe players to his/her right, and then throw the ball at the dth player, who becomes the target. The target willalways catch the ball, so that the thrower will be out of the game (and will…arrow_forward
- In java language Deeper Class Design - the Square, Circle, Picture Class he Bigger Picture – The ObjectList (or ArrayList (v1.0)) Class A picture is simply a composition of shapes, and in this last section, we’ll build a class used to manage such a picture. We’ll create this new class by reusing code from an existing piece of software. We’ll create an Picture class that will contain, amongst other state items (data), an array (or list) of Objects that are the Squares and Circles in the Picture to be drawn. Picture.java will be a simple abstraction here, and will just “draw” shapes to the console in the order that they appear in the list –ignoring the coordinate pairs stored in each Shape for now. Again, note the static storage restriction of only 100 shapes per picture; in future sections, we’ll learn how to dynamically resize our arrays. Aside: when we get to working with any of the Java graphics framework classes and/or swing, then a simple use of this Picture class (called a…arrow_forwardmake a program by use of two abstract classes, Position and Maze. A Position is used to identify a unique location within a maze. Any Position can be transformed into another Position by asking it for an adjacent position to the north, south, east, or west.arrow_forwardWrite the classes as shown in the following class diagram. Add a tester that asks the user for a cat, dog and a BigDog then call all of their methods. Note that Cat and Dog inherit from the abstract class Animal and BigDog inherits from Dog.arrow_forward
- Let’s consider a superclass Vehicle. Different vehicles have different features and properties however there few of them are common to all. Speed, color, fuel used, size are few which are common to all. Hence we can create a class ‘Vehicle’ with states and actions that are common to all vehicles. The subclass of this superclass can be any type of vehicle. Example: Class Car A has all the features of a vehicle. But it has its own attributes which makes it different from other subclasses. By using inheritance we need not rewrite the code that we’ve already used with the Vehicle. The subclass can also be extended. We can make a class ‘Sports Car’ which extends ‘Car’. It inherits the features of both ‘Vehicle’ and ‘Car’.arrow_forwardJAVA Create a class representing the student. Define all the properties you can think of. Define all methods the student class might have. (You can be inspired by the UML diagram but add some more methods you come up with). You can simplify the university management system by modeling it as an array of Students. Define all the methods the university management system should have.arrow_forwardWrite an abstract class, it can be anything well defined from the very basics.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education