-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.cpp
More file actions
140 lines (116 loc) · 3.48 KB
/
Copy pathadmin.cpp
File metadata and controls
140 lines (116 loc) · 3.48 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include<iostream>
using namespace std;
class Manager {
private:
string system_username;
int system_password;
public:
Manager();
bool login();
void displayOptions();
void showRoomStatus();
void addEmployee();
};
Manager::Manager()
{
system_username = "user";
system_password = 123456;
}
bool Manager:: login()
{
string username;
int password;
bool isLoggedIn = false;
int match = 1; // Used to match the user names
cout << "Enter username: ";
cin >> username;
cout << "Enter password: ";
cin >> password;
// Check if the username matches
if (username == system_username && password == system_password) {
cout << "\t\t\t\tWelcome Manager!\n";
isLoggedIn = true;
displayOptions();
}
else
{
cout << "Wrong username or password.\n";
}
return isLoggedIn;
}
void Manager:: displayOptions()
{
int choice;
do {
cout << "\nManager Menu:\n";
cout << "1. Show Room Status\n";
cout << "2. Add New Employee\n";
cout << "3. Logout\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
showRoomStatus();
break;
case 2:
addEmployee();
break;
case 3:
cout << "Logging out...\n";
return;
default:
cout << "Invalid choice. Please choose again.\n";
}
} while (choice != 3);
}
void Manager:: showRoomStatus()
{
int rooms[101];
ifstream inFile("rooms.txt");
if (!inFile) {
cout << "Error: Unable to open file!\n";
return;
}
for (int i = 1; i <= 100; i++) {
inFile >> rooms[i];
}
inFile.close();
for (int i = 1; i <= 100; i++) {
if (rooms[i] == 1) {
cout << "Room " << i << ": Not Available\t";
} else {
cout << "Room " << i << ": Available\t";
}
if (i % 5 == 0) {
cout << "\n";
}
}
}
void Manager:: addEmployee()
{
string name;
int id;
long long phone;
cout << "Enter the name of the new employee: ";
cin.ignore(); // To avoid newline issue after previous input
getline(cin, name);
cout << "Enter an ID for the new employee: ";
cin >> id;
cout << "Enter the phone number of the new employee: ";
cin >> phone;
// Save the new employee information in separate files
ofstream outFileNames("Employes/names.txt", ios::app);
ofstream outFileIds("Employes/ids.txt", ios::app);
ofstream outFilePhones("Employes/phone_nums.txt", ios::app);
if (outFileNames && outFileIds && outFilePhones) {
outFileNames << "\n" << name;
outFileIds << "\n" << id;
outFilePhones << "\n" << phone;
cout << "\nEmployee added successfully.\n";
} else {
cout << "Error: Unable to open file(s) to save employee information!\n";
}
outFileNames.close();
outFileIds.close();
outFilePhones.close();
}