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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!