Professional Documents
Culture Documents
Overloading Function To Find Area
Overloading Function To Find Area
Overloading Function To Find Area
AIM
To calculate the area of different shapes like Rectangle,Square etc (at least 5 shapes)
using overloaded function area()
PROGRAM
#include <iostream>
using namespace std;
#include <cmath>
int main() {
int choice,option;
do{
cout<<"*******************Welcome***********************";
cout<<"\n\nYou can do the following: ";
cout<<"\n\n1.Area of circle\n2.Area of square\n3.Area of rectangle\n
4.Area of triangle\n5.Area of parallelogram\n6.Exit"<<endl;
cout<<"\n\nWhat is your choice?"<<endl;
cin>>choice;
switch(choice)
{
case 1:
float radius;
cout<<"\n\nEnter radius of circle\n";
cin>>radius;
area(radius);
break;
case 2:
int side;
cout<<"\n\nEnter side of square\n";
cin>>side;
area(side);
break;
case 3:
int length,breadth;
2
cout<<"\n\nEnter length & breadth of rectangle\n";
cin>>length>>breadth;
area(length, breadth);
break;
case 4:
int a,b,c;
cout<<"\n\nEnter sides of triangle\n";
cin>>a>>b>>c;
area(a, b, c);
break;
case 5:
float base, height;
cout<<"\n\nEnter height and base of parallelogram\n";
cin>>height>>base;
area(height, base);
break;
case 6:
break;
}
cout<<"******************Thank you!**************************";
cout<<"\n\nDo you wish to continue?\n1.Continue\n2.Exit\n";
cin>>option;
}
while(option == 1);
return 0;
3
SAMPLE INPUT-OUTPUT