currently i found myself stuck on step 3 i have made some attempts but keep runn
ID: 3635322 • Letter: C
Question
currently i found myself stuck on step 3 i have made some attempts but keep running into problems.STEP 3: Add a Base Class Pointer Array and an Additional Function
Add to the test function a base class array of pointers of the same dimension as the total number of Circle and
Rectangle objects that were created in the previous step. Use this pointer array to access the Circle and the
Rectangle objects to call a new, nonclass member function that will display all the information about each object.
1. Circle objects should display radius, circumference, and area.
2. Rectangle objects should display dimensions, perimeter. and area.
The information-display function should accept as its calling parameter a pointer of the class Shape.
Run the test function to demonstrate static (early) binding using the derived class objects calling their member
functions, and run the test function to demonstrate dynamic (late)
Here is what i currently have any help would be appreciated
//Shape.h
#ifndef ShapeH
#define ShapeH
class Shape
{
public:
virtual double Area() const = 0;
virtual double Parimeter() const = 0;
private:
};
#endif
//Circle.h
#include "Shape.h"
class Circle: public Shape
{
public:
Circle();
void setRadius(const double r);
double getRadius() const;
virtual double Area() const;
virtual double Parimeter() const;
~Circle();
protected:
double Radius;
};
#endif
//Circle.cpp
#include <iostream>
#include "Circle.h"
using namespace std;
const double PI = 3.14159;
Circle::Circle()
{
}
void Circle::setRadius(const double r)
{
Radius = r;
}
double Circle::getRadius() const
{
return(Radius);
}
double Circle::Area() const
{
return (PI * Radius * Radius);
}
double Circle::Parimeter() const
{
return(2 * PI * Radius);
}
Circle::~Circle()
{
}
//Rectangle.h
#ifndef RectangleH
#define RectangleH
#include "Shape.h"
class Rectangle: public Shape
{
public:
Rectangle();
void setDimensions(int H, int W);
double getHeight();
double getWidth();
double Area() const;
double Parimeter() const;
~Rectangle();
private:
double Height;
double Width;
double A;
double P;
};
#endif
//Rectangle.cpp
#include <iostream>
#include "Rectangle.h"
using namespace std;
Rectangle::Rectangle()
{
}
void Rectangle::setDimensions(int W, int H)
{
Width = W;
Height = H;
}
double Rectangle::getHeight()
{
return(Height);
}
double Rectangle::getWidth()
{
return(Width);
}
double Rectangle::Area() const
{
return(Width * Height);
}
double Rectangle::Parimeter() const
{
return((2 * Width) + (2 * Height));
}
Rectangle::~Rectangle()
{
}
//Main.cpp
#include <iostream>
#include "Circle.h"
#include "Rectangle.h"
using namespace std;
//Prototype
void displayMenu(void);
char getMenuSelection(void);
void Cir(void);
void Rec(void);
void main()
{
char action;
double r;
double h;
double w;
Rectangle rec;
Circle cir;
do
{
displayMenu(); //displays the intitial menu
action = getMenuSelection(); //gets the menu selection
if(action == 'c' || action == 'C')
{
cout << "Enter the radius of the circle: ";
cin >> r;
cir.setRadius(r);
cout << "Radius: " << r << endl;
cout << "Area: " << cir.Area() << endl;
cout << "Parimeter: " << cir.Parimeter() << endl;
}
if(action == 'r' || action == 'R')
{
cout << "Enter the height of the rectangle: ";
cin >> h;
cout << "Enter the length of the rectangle: ";
cin >> w;
rec.setDimensions(h, w);
cout << "Dimensions= " << "Hight: " << h << " Width: " << w << endl;
cout << "Area: " << rec.Area() << endl;
cout << "Parimeter: " << rec.Parimeter() << endl;
}
if(action == 'l' || action == 'L')
{
}
}
while(action != 'q' || action != 'Q'); //loop until program has been quit
cin.ignore(2);
}
void displayMenu() //Displays the initial starting menu options
{
cout << "==================================================================" << endl;
cout << "|*************** Enter C to create a circle object **************|" << endl;
cout << "==================================================================" << endl;
cout << "|************** Enter R to create a rectangle object ************|" << endl;
cout << "==================================================================" << endl;
cout << "|****************** Enter L to print array list *****************|" << endl;
cout << "==================================================================" << endl;
cout << "|*********************** Enter Q To quit ************************|" << endl;
cout << "==================================================================" << endl;
}
char getMenuSelection() //Gets the menu selection
{
cout << "Enter your choice and press enter:";
char action;
cin >> action;
switch(action)
{
case 'c':
case 'C':
return action;
break;
case 'r':
case 'R':
return action;
break;
case 'l':
case 'L':
return action;
break;
case 'q':
case 'Q':
exit(0);
break;
default: //if menu selection is not valid let the user know
cout << " Invalid selection: try again" << endl;
displayMenu();
getMenuSelection();
break;
}
}