Home About Contact Privacy Terms Disclaimer
TECHAntena
Last Updated On: June 18, 2016
Editor: Adeeb C

C++ program to find the area of circle & rectangle using function overloading

Category: C++,Programing
Tags

Aim:

To write a program to find the area of a circle and rectangle using function overloading.

Algorithm:

Step 1: Start

Step 2: Declare a class over with data members and member functions.

Step 3: Define and declare the function volume() to find the volume of circle and rectangle.

Step 4: Create an object for the class over.

Step 5: Read the radius of the circle.

Step 6: Call the function volume() to find and print the volume of the circle.

Step 7: Read the length and breadth of the rectangle.

Step 8: Call the function volume() to find and print the volume of the rectangle.

Step 9: Stop

Program Code:

#include<iostream.h>

#include<conio.h>

class over

{

float l,b,r,area;

public:

void volume(float,float);

void volume(float);

};

void over::volume(float l, float b)

{

cout<<"Area of rectangle = "<<l*b;

void over::volume(float r)

{

cout<<"Area of circle = "<<3.14*r*r;

}

void main()

{

over o;

clrscre():

float r,l,b;

cout<<"\nEnter radius: ";

cin>>r;

o.volume(r);

cout<<"\n\nEnter lenght and breadth: ";

cin>>l>>b;

o.volume(l,b);

getch();

}

Output:

Enter Radius : 5

Area of circle = 78.5

Enter lenght and breadth : 3 4

Area of rectangle = 12