#include<iostream.h>
#include<conio.h>
class value
{
private:
int a1, a2, a3, f, h;
float b1, b2, b3, bs;
public :
void getdata();
value()
{ a1 = 0;
}
value(int a);
value(int a, int b);
value(float a, float b, float c);
int fact(int);
int big(int, int, int);
float sum(float, float, float);
void display1();
void display2();
void display3();
void display4();
};
value :: value(int a)
{
a1 = a;
}
value :: value (int a, int b)
{
a1 = a;
a2 = b;
}
value :: value(float a, float b, float c)
{
b1 = a;
b2 = b;
b3 = c;
}
int value :: fact(int a1)
{
int fact = 1;
for(int i=1; i<=a1; i++)
{
fact = fact*i;
}
return(fact);
}
int value :: big(int a1, int a2, int a3)
{
int high;
high = a1;
if (a2>high)
high = a2;
if (a3>high)
high = a3;
return(high);
}
float value :: sum(float b1, float b2, float b3)
{
return (b1+b2+b3);
}
void value :: display1()
{
cout<<"The value assigned to a1 by the first constructor1 is :"<<a1<<endl;
}
void value ::display2()
{
f= fact(a1);
cout<<"The factorial of value initialized by constructor2 is :"<<f<<endl;
}
void value :: display3()
{
h = big(a1, a2, a3);
cout<<"The biggest of three no. initialized by constructor3 is : "<<h<<endl;
}
void value :: display4()
{
bs = sum(b1, b2, b3);
cout<<"The sum of float numbers initialized by constructor4 is : "<<bs<<endl;
}
int main()
{
class value obj1, obj2(4), obj3(5,4), obj4(1.1, 2.2, 3.3);
clrscr();
obj1.display1();
obj2.display2();
obj3.display3();
obj4.display4();
getch();
return 0;
}
|
|

| To demonstrate the operation of constructor overloading |
|
| |
|
|
|
|