netx_iit

Copy constructor in C++

Jun 27th, 2020 (edited)
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. /* Create demo class and two member function 1st one is getting data and second one is display data*/
  2. /*
  3.  
  4. Output of program is
  5. sum of object a1 x and obj a2 x is 40
  6. */
  7.  
  8. #include<iostream.h>
  9. #include<stdio.h>
  10. #include<conio.h>
  11. class demo
  12. {
  13.     //public:
  14.     int age;
  15.     char name[20];//data member;
  16.     public:   //private,protected,public (by def private)
  17.     void getData()//member function
  18.     {
  19.         cout<<"\nEnter your name:";
  20.         cin>>name;
  21.         cout<<"\nEnter your age:";
  22.         cin>>age;
  23.     }
  24.  
  25.     void display()//member function
  26.     {
  27.         cout<<"\nYour name is "<<name<<" and age is "<<age;
  28.     }
  29. };
  30. int main()
  31. {
  32.     demo d1;//d1 is object
  33.     clrscr();
  34.     cout<<"\n\n";
  35.     cout<<d1.age;
  36.     d1.getData();
  37.     d1.display();
  38.     getch();
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment