-
Notifications
You must be signed in to change notification settings - Fork 0
/
Week 3 Challenge
48 lines (42 loc) · 897 Bytes
/
Week 3 Challenge
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
/* Class Pair has already been declared
* as shown in the following comments:
*
* class Pair {
* public:
* int *pa,*pb;
* Pair(int, int);
* Pair(const Pair &);
* ~Pair();
* };
*
* Implement its member functions below.
*/
Pair::Pair(int a, int b){
pa= new int(a);
pb= new int(b);
}
Pair::Pair(const Pair &obj){
pa=new int();
pb=new int();
*pa=*obj.pa;
*pb=*obj.pb;
std::cout<<*pa<<" "<<*pb;
}
Pair::~Pair(){
delete pa;
delete pb;
}
/* Here is a main() function you can use
* to check your implementation of the
* class Pair member functions.
*/
int main() {
Pair p(15,16);
Pair q(p);
Pair *hp = new Pair(23,42);
delete hp;
std::cout << "If this message is printed,"
<< " at least the program hasn't crashed yet!\n"
<< "But you may want to print other diagnostic messages too." << std::endl;
return 0;
}