Jun 2, 2015 at 2:25pm UTC
#include<iostream.h>
#include<conio.h>
class add
{
int num1,num2,sum;
public:
add()
{
cout<<"\n Constructor without parameters";
num1='\0';
num2='\0';
sum='\0';
}
add (int s1,int s2)
{
cout<<"\n Parameterized constructor";
num1=s1;
num2=s2;
sum=NULL;
}
add (add &a)
{
cout<<"\n Copy constructor";
num1=a.num1;
num2=a.num2;
sum=NULL;
}
void getdata()
{
cout<<"Enter data";
cin>>num1>>num2;
}
void addition(add b)
{
sum=num1+num2+b.num1+b.num2;
}
add addition()
{
add a(5,6);
sum=num1+num2+a.num1+a.num2;
}
void putdata()
{
cout<<"\n The numbers are";
cout<<num1<<'\t'<<num2;
cout<<"\n The sum of the numbers are"<<sum;
}
};
void main()
{
clrscr();
add a,b(10,20),c(b);
a.getdata();
a.addition(b);
b=c.addition();
c.addition();
cout<<"\n Object a:";
a.putdata();
cout<<"\n Object b";
b.putdata();
cout<<"\n Object c";
c.putdata();
getch();
}
Output of the above program
Constructor without parameters
Parameterized constructor..
Copy constructor .. Enter data .. 2 3
Copy Constructor....
Parameterized Constructor...
Parameterized Constructor...
Object a:
The numbers are .. 2 3
The sum of the numbers are.. 35
Object b:
The numbers are... 0 1494
The sum of the numbers are 0
Object c:
The numbers are .. 10 20
The sum of the numbers are ... 41
Jun 2, 2015 at 2:30pm UTC
You've been asked before: Please use code tags when posting code.
If you can't be bothered to make the effort to make your code readable, why should we make the effort to try and read it?
What particular aspect of the code don't you understand?