Write a program that will demonstrate copy
constructor function. The program that uses the following properties – class
names- add; two integer type private member variables- x,y; two parameterized
constructor function add(int m, int n), add(add &); one public member
function display(). Constructor function add(int m, int n) get the value from
parameterized object s1(20,50) and assigns the values for x,y; display() member
function do the addition for x, y and displays the result as output. Also
object s1 copy its value to object s2 and s2 also displays its value as output.
#include<iostream>
using
namespace std;
class add
{
int x,y;
public:
add(int m,int n);
add(add &);
void display();
};
add::add(int
m,int n)
{
x=m;
y=n;
}
add::add(add
&p)
{
x=p.x;
y=p.y;
}
void
add::display()
{
cout<<"Addition value is
:"<<x+y<<endl;
}
int main()
{
add s1(20,50);
s1.display();
add s2(s1);
s2.display();
return 0;
}
This comment has been removed by the author.
ReplyDeleteHello sir i do not use add(add & );
ReplyDeletewhats problem.If I do This program This way.Given Below....
#include
using namespace std;
class add{
private:
int x,y;
public:
add(int m,int n){
x=m;
y=n;
}
void display(){
cout<<"Addition result "<<(x+y)<<endl;
}
};
int main(){
add s1(3,3);
s1.display();
add s2=s1;
s2.display();
return 0;
}
Please replay me.
Regards,
Md.Mohosin Miah
Casinos in Arizona, NV - MapYRO
ReplyDeleteArizona Casinos. MapYRO is a licensed online gambling destination with a list of all 당진 출장안마 gambling venues in the 안산 출장마사지 state. 서산 출장샵 A map showing casinos 서울특별 출장안마 and other gambling 성남 출장샵