-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncapsulation.cpp
47 lines (36 loc) · 1.17 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
#include <iostream>
using namespace std;
#define p(x) cout << x << endl;
/*
Encapsulation is a protective barrier that keeps the data
and code safe within the class itself
- We are providing access to those fields via public methods
- Getters and Setters
*/
class Employee{
public:
Employee(string,string,int);
// getter and setter for name
const string& getName() { return name; }
void setName(string name) { this->name = name; }
// getter and setter for company
const string& getCompany() { return company; }
void setCompany(string company) { this->company = company; }
// getter and setter for age
int getAge() { return age; }
void setAge(int age) { this->age = age; }
private:
// these variables are private and they cannot be directly access
string name,company;
int age;
};
Employee::Employee(string name, string company, int age){
this->name = name;
this->company = company;
this->age = age;
}
int main(){
Employee emp1 = Employee("Alperen","Amazon",19);
const string& name = emp1.getName();
p(name);
}