Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective: Write a program where a user populates a collection of various shapes

ID: 3803700 • Letter: O

Question

Objective: Write a program where a user populates a collection of various shapes, which is sorted by its area. The user should be able to specify which type of shape they wish to enter, and then are prompted with the pertinent information which will be used to calculate the shape's area. Requirements The types of shapes the user can enter are: Circle Rectangle Triangle The structure of the program should follow this UML class diagram. ShapeCollection Shape FrontEnd shapes: Shape0 addShape(Shape) void sortShapes0: void static main Stringl argsivoid removeShape(String double): void print Shapes0:void +get Area 0:double +toString(): String +getShapeType0 String Rectangle Triangle length: double base: double width double -height: double +getRadius0: double +getLength(): double getBase0: double setRadiusIdouble) void setlength double): void setBase(double): void getHeight0: double +getWidth 0: double setWidth (double): void setHeight(double): void You may also include helper methods that are not noted in the class diagram, but its overall class structure should be what is shown above.

Explanation / Answer

Answer:

#include<iostream.h>
#include<conio.h>
const float pi=3.14;
float area(float n,float b,float h)
{
float ar;
ar=n*b*h;
return ar;
}
float area(float r)
{
float ar;
ar=pi*r*r;
return ar;
}
float area(float l,float b)
{
float ar;
ar=l*b;
return ar;
}
void main()
{
float b,h,r,l;
float result;
clrscr();
cout<<“ Enter the Base & Hieght of Triangle: ”;
cin>>b>>h;
result=area(0.5,b,h);
cout<<“ Area of Triangle: “<<result<<endl;
cout<<“ Enter the Radius of Circle: ”;
cin>>r;
result=area(r);
cout<<“ Area of Circle: “<<result<<endl;
cout<<“ Enter the Length & Bredth of Rectangle: ”;
cin>>l>>b;
result=area(l,b);
cout<<“ Area of Rectangle: “<<result<<endl;
getch();
}