Question
Implement base struct Shape and derived struct Circle, Rectangle and Square simulating polymorphism without using the virtual keyword. Do not use the C++ inheritance or
Implement base struct Shape and derived struct Circle, Rectangle and Square simulating polymorphism without using the virtual keyword. Do not use the C++ inheritance or polymorphism mechanisms but simulate them as described in our lecture. You are allowed to use some lecture code. Your code must be general. Use standard C++, such that the following main() works. You are not allowed to modify the main(). You are not allowed to include any files or built-in libraries, except for output. Submit your standard C++ code in the textbox below. Do not write the main() again.
int main() { Circle circle; CircleInitialize(&circle, 10); // circle with radius 10
Rectangle rectangle; RectangleInitialize(&rectangle, 3, 5); // rectangle with width 3 and height 5
Square square; SquareInitialize(&square, 7); // square with side length 7
Shape* shapes[3]; shapes[0]=(Shape*)&circle; shapes[1]=(Shape*)&rectangle; shapes[2]=(Shape*)
double total_area=0;
int i; for(i=0;i<3;i++) { double d=GetArea(shapes[i]); total_area+=d; } cout< return 0;
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