-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.h
118 lines (92 loc) · 2.33 KB
/
user.h
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// Created by hussein on 8/1/22.
//
#ifndef EXPEDIA_COM_USER_H
#define EXPEDIA_COM_USER_H
using namespace std;
enum class UserType { CustomerUser = 0, AdminUser = 1 };
class User {
protected:
string user_name;
string password;
string name;
string email;
UserType type = UserType::CustomerUser;
public:
// prevent copy constructor and assignment operator
User(const User&) = delete;
void operator=(const User&) = delete;
User() {}
// to allow dynamic casting
virtual ~User() {}
// for printing user || admin
string ToString() const {
ostringstream oss;
oss << "Name: " << user_name;
if (type == UserType::AdminUser)
oss << " | Admin";
else if (type == UserType::CustomerUser)
oss << " | Customer";
oss << "\n";
oss << "Email: " << email << "\n";
oss << "User name: " << user_name << "\n";
return oss.str();
}
// for reading user info
void Read(const string &user_name) {
SetUserName(user_name);
string str;
cout << "Enter password: ";
cin >> str;
SetPassword(str);
cout << "Enter name: ";
cin >> str;
SetName(str);
cout << "Enter email: ";
cin >> str;
SetEmail(str);
}
// getters and setters
const string& GetUserName() const {
return user_name;
}
void SetUserName(const string& user_name) {
this->user_name = user_name;
}
const string& GetPassword() const {
return password;
}
void SetPassword(const string& password) {
this->password = password;
}
const string& GetName() const {
return name;
}
void SetName(const string& name) {
this->name = name;
}
const string& GetEmail() const {
return email;
}
void SetEmail(const string& email) {
this->email = email;
}
UserType GetType() const {
return type;
}
void SetType(UserType type) {
this->type = type;
}
};
class Admin : public User {
protected:
public:
// prevent copy constructor and assignment operator
Admin(const Admin&) = delete;
void operator=(const Admin&) = delete;
// default constructor
Admin() {
SetType(UserType::AdminUser);
}
};
#endif //EXPEDIA_COM_USER_H