Answer to Question #235110 in C++ for SOM

Question #235110

Write a program using copy constructor to copy data of an object to another object.


1
Expert's answer
2021-09-11T07:01:15-0400
#include <iostream>  
  
using namespace std;  
  
class A  
{  
    int x;  
    int y;  
    int z;  
    public:  
    A()  
    {  
       
    }  
    void input(int a,int b,int c)  
    {  
        x=a;  
        y=b;  
        z=c;  
    }  
    void display()  
    {  
        cout << "x is : " <<x<<endl;  
        cout << "y is : " <<y<<endl;  
        cout << "z is : " <<z<<endl;  
    }  
};  
int main()  
{  
    A a1;  
    a1.input(10,20,30);  
    A a2 = a1;  
    a2.display();  
    return 0;  
}  

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS