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<<"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;
}

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;
}

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;
}
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;
}

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;
}
else if(name=="Circle")
{