Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Following examples from Week 1 0 , pgs . 2 1 - 2 5 lecture notes create your own Geometry class and the two subclasses
Following examples from Week pgs lecture notes create your own Geometry class
and the two subclasses Circle and Square. Reproduce the behavior shown on pg of
Week notes.
a Create an array of Geometry pointers on the stack. The number of elements is six. The
syntax looks like
Geometry Geom ;
where Geom is the name of the pointer array. Note that since this array is created on the
stack you do not need to explicitly delete this pointer array, however, you will need to delete
the objects that each of the pointers point to will be discussed later
b We will create a total of three circles and three squares and store them on the heap using the
Geom pointer array. They will be stored in the sequence Circle Square, Circle, Square,
Circle, Square The first CircleSquare pair will have diameter and edge length Edge
The second pair will have and Edge and the third pair will have
and Edge Each object will be created using the new operator, for example, for the
first circle we have
Geom new Circle;
Use a similar process to create the remaining Squares and Circles storing all six elements into
the Geom pointer array. In your main program be sure to delete the memory pointed to by
the Geom pointer before the end of the main program by using statements such as:
delete Geomi;
where dots, This should be located right before the return ; in main.
c After you have created the Geometry objects, use a for loop to iterate over all the Geom
pointers and calls the Show function. Note if this is done correctly it will automatically
call the "Circle Show function for the first element of the array, the "Square Show
function for the second element, etc. The syntax for this is something like
Geom iShow ; for each objects
NOTES FROM WEEK :
# include iostream
using namespace std;
class Geometry
protected:
double Area;
double Perimeter;
public:
Geometry;
virtual ~Geometry;
virtual void Show;
;
Geometry::Geometry
cout endl;
cout "Geometry Cnstr Called" endl;
Area ;
Perimeter ;
Geometry::~Geometry
cout "Geometry Dstr Called" endl;
void Geometry::Show
cout endl;
cout "Area Area endl;
cout "Perimeter Perimeter endl;
cout endl;
class Circle : public Geometry
protected:
double D; Diameter
const double PI;
public:
Circledouble d : PI
cout"Circle Cnstr Called"
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