-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq30.cpp
53 lines (46 loc) · 1.2 KB
/
q30.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
#include <iostream>
using namespace std;
class A {
int num;
string str;
public:
//default constructor:
A () {
cout << "Default constructor called!" << endl;
cout << "Enter value for num: ";
cin >> num;
cout << "Enter value for str: ";
cin >> str;
}
// Parametrized constructor:
A (int num, string str) {
cout << "Parametrized constructor called!" << endl;
this->num = num;
this->str = str;
}
//Copy constructor
A (A& t) {
cout << "Copy constructor called!" << endl;
num = t.num;
str = t.str;
}
void display_values();
};
void A :: display_values() {
cout << "\tNum = " << num << endl;
cout << "\tStr = " << str << endl;
}
int main() {
A default_ctor;
cout << "Entered values: " << endl;
default_ctor.display_values();
cout << endl;
A param_ctor(420, "Mark");
cout << "Entered values: " << endl;
param_ctor.display_values();
cout << endl;
A copy_ctor(default_ctor);
cout << "Entered values: " << endl;
copy_ctor.display_values();
return 0;
}