#include<iostream.h>
#include<conio.h>
class demo
{
private:
int a1, a2, as;
float b1, b2, bs;
double d1, d2, ds;
public:
void getdata();
int sum(int, int);
float sum(float, float);
double sum(double, double);
void display();
};
void demo :: getdata ()
{
cout<<"Enter two integers : ";
cin>>a1>>a2;
cout<<"Enter two float no. : ";
cin>>b1>>b2;
cout<<"Enter two double no. : ";
cin>>d1>>d2;
}
int demo :: sum(int a1, int a2)
{
return (a1+a2);
}
float demo :: sum(float b1, float b2)
{
return (b1+b2);
}
double demo :: sum(double d1, double d2)
{
return (d1+d2);
}
void demo :: display()
{
as = sum(a1, a2);
bs = sum(b1, b2);
ds = sum(d1, d2);
cout<<"The sum of entered integer is : "<<as<<endl;
cout<<"The sum of entered float no is : "<<bs<<endl;
cout<<"The sum of entered double no is : "<<ds<<endl;
}
int main()
{
class demo obj ;
clrscr();
obj.getdata();
obj.display();
getch();
return 0;
}
|
|

| To calculate sum of given integers, float and double number using function overloading technique. |
|
| |
|
|
|
|