C++ program to find out the area of square, rectangle and triangle?

+1 vote
159 views
C++ program to find out the area of square, rectangle and triangle?
posted Feb 1, 2019

``````#include<iostream>
using namespace std;
int area(int);
int area(int,int);
float area(float);
float area(float,float);
int main()
{
int s,l,b;
float bs,ht;
cout<<"Enter side of a square:";
cin>>s;
cout<<"Enter length and breadth of rectangle:";
cin>>l>>b;
cout<<"Enter base and height of triangle:";
cin>>bs>>ht;
cout<<"Area of square is"<<area(s);
cout<<"\nArea of rectangle is "<<area(l,b);
cout<<"\nArea of triangle is "<<area(bs,ht);
}
int area(int s)
{
return(s*s);
}
int area(int l,int b)
{
return(l*b);
}
float area(float bs,float ht)
{
return((bs*ht)/2);
}
``````

Sample Input
Enter side of a square:2
Enter length and breadth of rectangle:3 6
Enter base and height of triangle:4 4

Sample Output
Area of square is4
Area of rectangle is 18
Area of triangle is 8

``````#include<iostream>

using namespace std;

int main()
{
int s,l,b,bs,ht;

int SquareArea,RectangleArea,TriangleArea;

cout<<"Enter the side";
cin>>s;
SquareArea= s*s;
cout<<"\nArea of the square is:"<<SquareArea;

cin>>l;
cin>>b;
RectangleArea=l*b;
cout<<"\nArea of the Rectangle is:"<<RectangleArea;

cout<<"\nEnter base and height for triangle";
cin>>bs>>ht;
TriangleArea=((bs*ht)/2);
cout<<"\nArea of the Triangle is:"<<TriangleArea;

return 0;
}
``````