-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeep copy from obj1 to obj2 and obj3.cpp
73 lines (73 loc) · 1.24 KB
/
deep copy from obj1 to obj2 and obj3.cpp
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
#include<iostream>
using namespace std;
class MyBigInt
{
int* big_int;
int int_length;
public:
MyBigInt()
{
big_int = nullptr;
int_length = 0;
}
MyBigInt(int size)
{
int_length = size;
big_int = new int[int_length];
for (int i = 0; i < int_length; i++) {
cin >> big_int[i];
}
}
MyBigInt(const MyBigInt &obj)
{
int_length = obj.int_length;
big_int= new int[int_length];
for (int i = 0; i < int_length; ++i)
{
big_int[i] = obj.big_int[i];
}
}
void assign(const MyBigInt &obj)
{
int* data = new int[int_length];
if (this != &obj)
{
for (int i = 0; i < int_length; i++)
data[i] = obj.big_int[i];
}
}
void display()
{
if (big_int != nullptr)
{
for (int i = 0; i < int_length; i++)
cout << big_int[i] << " ";
}
else
{
cout << "No Value Assigned";
}
cout << endl;
}
~MyBigInt()
{
delete[]big_int;
big_int = nullptr;
int_length = 0;
}
};
int main()
{
int size;
cout << "Enter the size : ";
cin >> size;
MyBigInt obj1;
MyBigInt obj2(size);
cout << "Object 1 Data : " << endl;
obj2.display();
MyBigInt obj3 = obj2;
cout << "Object 2 Data : " << endl;
obj3.display();
obj1.assign(obj3);
return 0;
}