-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConstructor.cpp
91 lines (77 loc) · 1.71 KB
/
Constructor.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <bits/stdc++.h>
using namespace std;
// Example with Encapsulations:
// Constructor
class Account
{
private:
double balance;
string password;
public:
string account_id;
string user_name;
string dept;
string subject;
// setter
void setbalance(double b)
{
balance = b;
}
void setpassword(string p)
{
password = p;
}
// getter
double getbalance()
{
return balance;
}
string getpassword()
{
return password;
}
// constructor
// non-parameterized constructor
// always public
Account()
{
user_name = "Prolay Ghosh";
account_id = "100012";
}
// Parameterized constructor
Account(string user_name, string account_id, string dept, string subject)
{
this->user_name = user_name;
this->account_id = account_id;
this->dept = dept;
this->subject = subject;
}
// copy constructor
// not original object copy, its full original object
Account(Account &org_obj)
{ // Pass by reference
cout << "Copy constructor" << endl;
;
this->user_name = org_obj.user_name;
this->account_id = org_obj.account_id;
this->dept = org_obj.dept;
this->subject = org_obj.subject;
}
void getInfo()
{
cout << "User Name- " << user_name << endl;
cout << "account_id- " << account_id << endl;
cout << "Department- " << dept << endl;
cout << "subject- " << subject << endl;
}
};
int main()
{
Account s1("Prolay Ghosh", "100012", "Computer Science", "DataStructure Algorithms");
// using setter method set data
s1.setbalance(25000.00);
s1.setpassword("lock123");
// s1.getInfo();
Account s2(s1);
s2.getInfo();
}