Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The only way you must solve this is to include creating the main file and several classes: Square, Pentagon, Heptagon, and Decagon. Additionally, there will
The only way you must solve this is to include creating the main file and several classes: Square, Pentagon, Heptagon, and Decagon. Additionally, there will be header and implementation files for each class. I need a really good answer, so please take your time understanding the instructions below to accurately complete it with the necessary implementation and error checking. The checklist should be used too :
C PROGRAMMING: PolyMORPHISM ASSIGNMENT INSTRUCTIONS
OVERVIEW
The objective of this assignment is to give you some practice using inheritance, virtual functions, and polymorphism. With a focus on dynamic binding, this program shifts the focus from designtime static binding of functions to objects to runtime or dynamic binding It leverages the use of virtual functions and introduces the concept of abstract and concrete classes in its implementation of pure virtual functions as it also demonstrates polymorphic behavior.
There are some helpful links at the bottom of the instructions.
Ask the professor questions early if you need help with the assignment. Remember, this is a short week.
Note: Week is a short week. The instructions include several items that will help to speed your project up
Tip: One of students' most common problems with this Lab is getting the #include statements mixed up This will generate several different types of errors.
Below is a diagram of the hierarchy of the Classes that can help you visualize how the #includes work by showing you which Class includes which Class.
Most common error situation: If you include file in your main and file includes file then your main also has access to file through the #include of file
For the diagram below, you will need the following #include statements. You can choose to copypaste the items below, but you will not learn the 'why'. Take the time and look at the list and compare it to the diagram.
Review the class diagram and check your #include statements.
In the main file
#include "Square.h;
#include "Pentagon.h;
#include "Heptagon.h;
#include "Decagon.h;
In Square.h
#include "Shape.h;
In Square.cpp
#include "Square.h;
In Pentagon.h
#include "Shape.h;
In Pentagon.cpp
#include "Pentagon.h;
In Heptagon.h
#include "Shape.h;
In Heptagon.cpp
#include "Heptagon.h;
In Decagon.h
#include "Shape.h;
In Decagon.cpp
#include "Decagpm.h;
The diagram below shows the relationships between the Classes for the Lab
INSTRUCTIONS
Create a base class called Shape.
a All Shapes have a shapeType ie "Square", "Pentagon", "Heptagon", "Decagon", a shapeName user defined a numberSides, and a sideLength which is generated as a random number. The number of sides for each type are:
i Square
ii Pentagon
iii. Heptagon
iv Decagon
b Provides a constructor that allows the shapeName and sideLength to be set by the client when the object is created. This constructor should also output the message "Invoking Shape argument constructor."
c Provides a destructor for this class that outputs the message "Invoking Shape destructor." This destructor is virtual, which means that this destructor will fire, and the destructor from the inherited class will fire.
d Provides a function called calcPerimeter that will calculate and return the Perimeter. The formula is numberSides sideLength.
e Provides a function called displayShapeInfo that cannot be implemented. That is it should be declared as a purely virtual function.
f Provides Get and Set methods to allow the shapeName, shapeType, numberSides, and sideLength to be accessed.
Note: The setter for shapeName and sideLength must be located in the private section of the h file. This is because these data members are Read Only to the world outside the class. Only this class or the class that inherits from this class will be able to access these setters when they are in the private section.
From the Shape class, derive the Square, Pentagon, Heptagon, and Decagon classes.
a The derived classes should each have a constructor and destructor that output an appropriate message eg the Square constructor outputs "Invoking Square argument constructor," and the Square destructor outputs "Invoking Square destructor", etc.
b The constructor of each derived class should allow the shapeName and sideLength of the Shape to be passed directly to the constructor of the base class. The derived constructor body will then use the base class private setters to pass in the hardcoded shape type and number of sides using the setShapeName and setNumberSides setters.
Example: The example below shows parameters received by the derived
class constructor and those parameters being passed to the base class constructor.
c The derived classes should each have a member function called displayShapeInfo that o
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started