Quotation:


Create a function template named as shape() that accepts three arguments in such a way that first and second will be the dimension like base and height and the third will be the name of the shape. The shape() function displays the dimension values and the area of the shape. The function returns the area to the calling program; the area is the same data type as the parameter. [Note: Design a main program such that, it input the values of only those shapes whose area is computable on the bases of base and height only



#include <stdio.h>
#include<iostream>
using namespace std;

shape(double h,double w, string name )
{
double area;
if(name=="Square")
{
area=h*h;
return(area);
}
else if(name=="Rectangle")
{
area=h*w;
return(area);

}

else if(name=="Triangle")
{
area=(h*w)/2;
return(area);
}
else if(name=="Polygons")
{
area=(1/2) * w * h;
return(area);
}
else if(name=="Parallelogram")
{
area=(w * h);

return(area);
}
else if(name=="Circle")
{
area=(3.14 * (h*h));
return(area);

}

}


int main()
{
double height, width,area;
string name;
cout<<"Please Enter the Name of your Shape"<<endl;
cout<<"For Example Square,Rectangle,Triangle,Polygons, Parallelogram, Circle"<<endl;

getline(cin, name);

if(name=="Square")
{
cout<<"Enter the one side of Square"<<endl;
cin>>height;
cout<<endl;
area=shape(height,width,name);
cout<<"one side of Square is ="<<height<<endl;
cout<<"Area of Your Square is="<<area<<endl;
}

else if(name=="Rectangle")
{
cout<<"Enter the height of Rectangle"<<endl;
cin>>height;
cout<<endl;
cout<<"Enter the width of Rectangle"<<endl<<endl;
cin>>width;
cout<<endl;

area=shape(height,width,name);
cout<<"Height of Rectangle is ="<<height<<endl;
cout<<"Width of Rectangle is="<<width<<endl;
cout<<"Area of Your Rectangle is="<<area<<endl;
}

else if(name=="Triangle")
{
cout<<"Enter the height of Triangle"<<endl;
cin>>height;
cout<<endl;
cout<<"Enter the Base of Triangle"<<endl;
cin>>width;
cout<<endl;
area=shape(height,width,name);
cout<<"Height if Triangle is ="<<height<<endl;
cout<<"Base of Triangle is="<<width<<endl;
cout<<"Area of Your Triangle is="<<area<<endl;
}
else if(name=="Polygons")
{
cout<<"Enter the perimeter of Polygons"<<endl;
cin>>height;
cout<<endl;
cout<<"Enter the apothem of Polygons"<<endl;
cin>>width;
cout<<endl;
area=shape(height,width,name);
cout<<"perimeter of Polygons is ="<<height<<endl;
cout<<"apothem of Polygons is="<<width<<endl;
cout<<"Area of Your Polygons is="<<area<<endl;
}

else if(name=="Parallelogram")
{
cout<<"Enter the Height of Parallelogram"<<endl;
cin>>height;
cout<<endl;
cout<<"Enter the width of Polygons"<<endl;
cin>>width;
cout<<endl;
area=shape(height,width,name);
cout<<"Height of Parallelogram is ="<<height<<endl;
cout<<"width of Parallelogram is="<<width<<endl;
cout<<"Area of Your Polygons is="<<area<<endl;
}
else if(name=="Circle")
{
cout<<"Enter the Radious of Circle"<<endl;
cin>>height;
cout<<endl;
area=shape(height,width,name);
cout<<"Radious of Circle is ="<<height<<endl;
cout<<"Area of Your Circle is="<<area<<endl;

}

else
cout<<"Please Enter The Correct Shape Name";

return 1;
}