-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPRA_19
78 lines (67 loc) · 1.32 KB
/
PRA_19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* A program to demonstrate use of copy constructors.*/
#include<iostream>
using namespace std;
class ctor
{
int a[100],n;
public:
ctor()// do nothing constructor
{
}
ctor(ctor &A) // copy constructor definintion
{
n=A.n;
for(int i=0;i<n;i++)
{
a[i]=A.a[i];
}
cout << endl << "Copy constructor invoked ..."<<endl;
}
void getElemnt()
{
cout <<"ARRAY"<< endl << "Enter number of Elements : ";
cin >> n;
cout << endl << "Enter "<<n<<" Elements :"<< endl;
for(int i=0;i<n;i++)
{
cin >> a[i];
}
cout << endl ;
}
void putElemnt()
{
cout <<endl<<"ARRAY"<<endl << "Present Elements :";
for(int i=0;i<n;i++)
{
cout << a[i] << "\t";
}
cout << endl;
}
};
int main()
{
ctor ar;
ar.getElemnt();
cout <<endl<<"OBJECT 1 : "<<endl;
ar.putElemnt();
ctor b(ar); // invokes the copy constructor
cout << endl<<"OBJECT 2 : "<<endl;
b.putElemnt(); // puting elements after copy
return 0;
}
/*
ARRAY
Enter number of Elements : 5
Enter 5 Elements :
2 5 22 6 21 65
OBJECT 1 :
ARRAY
Present Elements :2 5 22 6 21
Copy constructor invoked ...
OBJECT 2 :
ARRAY
Present Elements :2 5 22 6 21
--------------------------------
Process exited after 19 seconds with return value 0
Press any key to continue . . .
*/