Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

PROGRAM -CREATE A CLASS TRIANGLE ,INCLUDE

OVERLOADED FUNCTIONS FOR CALCULATING


AREA
#include<iostream.h>

#include<conio.h>

#include<math.h>

using namespace std;

class triangle {

public:

void area(int ,,int , int);

void area( int, int);

};

void triangle::area( int a, int b) {

cout << "Area of triangle:" << .5 * a*b;

void triangle::area(int i, int j, int k)

float s=(i+j+k)/2;
float ar=sqrt(s*(s-i)*(s-j)*(s-k));
cout<<"\nthe area of triangle when 3 sides are given is\n"<<ar;

Int main() {

int a, b;

int i,j,k;
clrscr();

triangle obj;

cout << "\n\t\tFunction Overloading";

cout << “.Area of Triangle”;

cout << "Enter Sides of the Triangle:";

cin >> a>>b;

obj.area( a, b);

cout<<”when three sides of a triangle are given”;

cin>>i>>j>>k;

obj.area(i,j,k);

getch();

return 0;

Above programming is overloading area of triangle


depending on number of arguments passed to function
area()
First of all see the previous notes on function overloading

You might also like