Write your question here.
#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;
return a;
}
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();
}
Kindly explain this program ...
Last edited on
Hi chervil
Why object b of sum value is get zero?
Kindly explain...
Dear Chervil
Thanks for your response
I have one doubt Why c.addition get value 41
But b=c.addition get value zero.
Kindly explain please
Thanks in advance...
Dear keskiverto
add addition()
{
add a(5,6);
sum=num1+num2+a.num1+a.num2;
return a;
}
Now I have added return statement...
The value of Object b is 5 and 6
But sum value get zero
Please explain
Dear Ksekiverto
Thanks a lot
Sorry for frequently disturbed..
Why Object C get the value sum is 41
Please explain...
You do call member function addition()
of object c.
The code of that function is on my previous post.
What does happen on line 3?
What does happen on line 4?
What member variables does object of type class add
have?
What were the values of the member variables of object c before calling the function?