0% found this document useful (0 votes)
82 views

Overloading Function To Find Area

This document describes a C++ program that uses function overloading to calculate the area of different shapes. The program overloads the area() function to accept different parameters for calculating the area of a circle (radius), square (side), rectangle (length, breadth), triangle (sides a, b, c) and parallelogram (base, height). The main() function uses a switch case to call the appropriate area() function based on the user's shape selection and displays the calculated area output.

Uploaded by

Mariya Benny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Overloading Function To Find Area

This document describes a C++ program that uses function overloading to calculate the area of different shapes. The program overloads the area() function to accept different parameters for calculating the area of a circle (radius), square (side), rectangle (length, breadth), triangle (sides a, b, c) and parallelogram (base, height). The main() function uses a switch case to call the appropriate area() function based on the user's shape selection and displays the calculated area output.

Uploaded by

Mariya Benny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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>

void area(float radius)


{
float area;
area=3.14*radius*radius;
cout<<"The area of the given circle is : "<<area<<endl;
}

void area(int side)


{
int area;
area=side*side;
cout<<"The area of the given square is : "<<area<<endl;
}

void area(int length,int breadth)


{
int area;
area=length*breadth;
cout<<"The area of the given rectangle is : "<<area<<endl;
}

void area(int a,int b,int c)


{
float area;
float s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"The area of the given triangle is : "<<area<<endl;
}

void area(float base, float height)


{
float area;
area=base*height;
cout<<"The area of the given parallelogram is : "<<area<<endl;
}

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

You might also like