Question
C++ PROGRAMMING PLEASE REVISE MY CODE BELOW in your test program, create an array of type BasicShape with size 4 then populate array with 2
C++ PROGRAMMING
PLEASE REVISE MY CODE BELOW
in your test program, create an array of type BasicShape with size 4 then populate array with 2 Circle objects and 2 Rectangle objects. You can prompt use to enter values and then assign them to the array. Then define a function that will accept the array of BasicShape and in the function, and in a loop, print area of each object. What you should demonstrate here is Polymorphism since the type of the array is BasicShape.
Lastly, use pointers. That is an array of pointers to BasicShape and still of size 4.
#include
#include "Circles.h"
#include "Rectangles.h"
using namespace std;
void dispArea(Shapes* sh);
int main()
{
Circles *ptr = nullptr;
Circles cir(5, 2, 3.0);
ptr = ○
Rectangles *ptr1 = nullptr;
Rectangles rec(7, 8);
ptr1 = &rec;
dispArea(ptr);
dispArea(ptr1);
system("pause");
return 0;
}
void dispArea(Shapes* sh)
{
cout << sh->getAreas() << endl;
}
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