-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencapsulation.cpp
57 lines (49 loc) · 1.07 KB
/
encapsulation.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
#include<iostream>
using namespace std;
class Employee
{
private: // hidden or encapsulated
string Name;
string Company;
int Age;
public:
void setName(string name) // Setter
{
Name = name;
}
string getName() // Getter
{
return Name;
}
void setCompany(string company) // Setter
{
Company = company;
}
string getCompany() // Getter
{
return Company;
}
void setAge(int age) // Setter
{
if(age >= 18)
Age = age;
}
int getAge() // Getter
{
return Age;
}
Employee(string name, string company, int age) // parameterised constructor
{
Name = name;
Company = company;
Age = age;
}
};
int main()
{
Employee employee1 = Employee("Rounak", "Apple", 20);
Employee employee2 = Employee("Saldina", "YT-CodeBeauty", 25);
employee1.setAge(28);
cout << employee1.getName() << " is " << employee1.getAge() << " years old." << endl;
return 0;
}