Write a program with the use of Function Overloading
1)
#include<iostream.h>
#include<conio.h>
class overloading
{
public:
int add(int x, int y)
{
return x+y;
}
int add(int x, int y, int z)
{
return x+y+z;
}
double add(double x, double y)
{
return x+y;
}
};
void main()
{
clrscr();
overloading ov;
cout<<ov.add(5,10)<<"\n";
cout<<ov.add(5,10,15)<<"\n";
cout<<ov.add(1.5,1.6)<<"\n";
getch();
}
#include<conio.h>
class overloading
{
public:
int add(int x, int y)
{
return x+y;
}
int add(int x, int y, int z)
{
return x+y+z;
}
double add(double x, double y)
{
return x+y;
}
};
void main()
{
clrscr();
overloading ov;
cout<<ov.add(5,10)<<"\n";
cout<<ov.add(5,10,15)<<"\n";
cout<<ov.add(1.5,1.6)<<"\n";
getch();
}
Here is the output:::)
2)
#include<iostream.h>
#include<conio.h>
class math
{
public:
int add(int x,int y,int z)
{
return x+y+z;
}
int mul(int x, int y, int z)
{
return x*y*z;
}
int div(int x, int y)
{
return x/y;
}
int sub(int x, int y, int z)
{
return x-y-z;
}
int mod(int x, int y)
{
return x%y;
}
};
void main()
{
clrscr();
math mt;
cout<<"Addition= "<<mt.add(10,5,15)<<endl;
cout<<"Multiplication= "<<mt.mul(1,2,3)<<endl;
cout<<"Division= "<<mt.div(8,4)<<endl;
cout<<"Subtraction= "<<mt.sub(15,5,5)<<endl;
cout<<"Module= "<<mt.mod(7,2)<<endl;
getch();
}
#include<conio.h>
class math
{
public:
int add(int x,int y,int z)
{
return x+y+z;
}
int mul(int x, int y, int z)
{
return x*y*z;
}
int div(int x, int y)
{
return x/y;
}
int sub(int x, int y, int z)
{
return x-y-z;
}
int mod(int x, int y)
{
return x%y;
}
};
void main()
{
clrscr();
math mt;
cout<<"Addition= "<<mt.add(10,5,15)<<endl;
cout<<"Multiplication= "<<mt.mul(1,2,3)<<endl;
cout<<"Division= "<<mt.div(8,4)<<endl;
cout<<"Subtraction= "<<mt.sub(15,5,5)<<endl;
cout<<"Module= "<<mt.mod(7,2)<<endl;
getch();
}
Here is the output :::)
3)
#include<iostream.h>
#include<conio.h>
class overloading
{
public:
int add( int x, int y)
{
return x+y;
}
float ad( float x, float y)
{
return x+y;
}
double sub( double x, double y)
{
return x-y;
}
};
void main()
{
clrscr();
overloading ov;
cout<<"\n Integer addition= "<<ov.add(5,7)<<endl;
cout<<"\n Floating addition= "<<ov.ad(2.5,1.5)<<endl;
cout<<"\n Double subtraction= "<<ov.sub(3.5,2.5)<<endl;
getch();
}
#include<conio.h>
class overloading
{
public:
int add( int x, int y)
{
return x+y;
}
float ad( float x, float y)
{
return x+y;
}
double sub( double x, double y)
{
return x-y;
}
};
void main()
{
clrscr();
overloading ov;
cout<<"\n Integer addition= "<<ov.add(5,7)<<endl;
cout<<"\n Floating addition= "<<ov.ad(2.5,1.5)<<endl;
cout<<"\n Double subtraction= "<<ov.sub(3.5,2.5)<<endl;
getch();
}
No comments:
Post a Comment