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

13.Function overloading

The document presents a C++ program demonstrating function overloading through a class that calculates the area of different shapes: circle, rectangle, and triangle. It includes methods for each shape's area calculation and a main function that provides a menu for user interaction. The program continues to prompt the user until they choose to exit.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

13.Function overloading

The document presents a C++ program demonstrating function overloading through a class that calculates the area of different shapes: circle, rectangle, and triangle. It includes methods for each shape's area calculation and a main function that provides a menu for user interaction. The program continues to prompt the user until they choose to exit.

Uploaded by

ponni.world009
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

13.

Function overloading

#include<iostream.h>

#include<conio.h>

#include<stdlib.h>

#define pi 3.14

class fn

public:

void area(int);

void area(int,int);

void area(float,int,int);

};

void fn::area(int a)

cout<<"\n Area of circle :"<<pi*a*a;

void fn::area (int a, int b)

cout<<"\n Area of rectangle :"<<a*b;

void fn::area(float t, int a, int b)

cout<<"\n Area of triangle :"<<t*a*b;

void main()

{
int ch;

int a,b,r;

clrscr();

fn obj;

while(2)

cout<<"\n Function overloading \n ";

cout<<"\n 1. Area of circle \n 2. Area of Rectangle \n 3.Area of tri\n


4.Exit";

cout<<"\n \t Enter your choice:";

cin>>ch;

switch(ch)

case 1:

cout<<"\n\t Enter radius of circle:";

cin>>r;

obj.area(r);

break;

case 2:

cout<<"\n\t Enter side of rectangle :";

cin>>a>>b;

obj.area(a,b);

break;

case 3:

cout<<"\n\t Enter side of triangle:";

cin>>a>>b;

obj.area(0.5,a,b);
break;

case 4:

exit(0);

break;

default:

cout<<"\n\tPlease enter your correct choice : ";

getch();

break;

You might also like