-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMS.cpp
260 lines (225 loc) · 8.94 KB
/
CMS.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
// including user defined header files
#include "student.h"
#include "faculty.h"
// including colors library to use windows terminal supported colors in output stream
#include "colors.hpp"
// Defining colors
#define red colors::bright_red
#define green colors::bright_green
#define blue colors::bright_cyan
#define bold colors::bold
#define bold colors::bold
using std::cin;
using std::cout;
using std::endl;
using std::string;
// functions to get the user input to make an entry
void getStudentInput(string &name, string &id, string &course, string &email);
void getFacultyInput(string &name, string &id, string &course, string &email);
int main()
{
// Passwords for different roles
const string hodPassword = "hod123";
const string coordinatorPassword = "coordinator456";
const string facultyPassword = "faculty789";
// object declaration of classes in "student.h" and "faculty.h"
bca_fcdata fc;
bca_stdata st;
mca_fcdata fc1;
mca_stdata st1;
// variables to take input from the uesr
string name, id, course, email, st_id, fc_id;
cout << green << bold << "\n==========================================\n"
<< "Welcome to College Management System (CMS)\n"
<< "==========================================\n\n" << reset;
// asking user their role in the college
int user;
cout << blue << "Who are you?\n\n";
cout << "(1) Head of Department (HoD)\n";
cout << "(2) Coordinator\n";
cout << "(3) Faculty\n";
cout << red << "(4) Exit\n" << reset;
cin >> user;
// if user chooses 4, return 0 (exit the program)
if (user == 4)
{
cout << red << "Exiting the system. Goodbye!\n" << reset;
return 0;
}
// pointer to the passwords of different roles
const string *correctPassword;
// limitations given for low authority roles
bool canEnterFacultyData = true;
bool canEnterStudentData = true;
// setting password and limitations
switch (user)
{
case 1:
correctPassword = &hodPassword;
break;
case 2:
correctPassword = &coordinatorPassword;
canEnterFacultyData = false;
break;
case 3:
correctPassword = &facultyPassword;
canEnterStudentData = false;
canEnterFacultyData = false;
break;
default:
cout << red << "Enter a valid choice!\n"
<< reset;
exit(0);
}
string pass;
int tries = 0;
// External do-while loop
do
{
// password check logic starts here
tries++;
if (tries == 1)
{
cout<< blue << "Enter the password to authenticate yourself:\n" << reset;
cin >> pass;
}
else if (tries > 1)
{
cout << endl << blue << "Try again:\n" << reset;
cin >> pass;
// exiting the program when the try limit is exceeded
if (tries == 5)
{
cout << red << "You have exceeded the trial limit, the application is locked for this session!\n" << reset;
return 0;
}
}
if (pass == *correctPassword)
{
int ch;
do
{
// selecting the department/section
cout << blue << "\nSelect the department:\n\n";
cout << "(1) BCA\n";
cout << "(2) MCA\n";
cout << red << "(3) Exit\n" << reset;
cin >> ch;
if (ch == 1 || ch == 2)
{
char department_choice;
do
{
// list of actions
cout << blue << "\nSelect the action to perform:\n\n";
cout << "(1) Show all student data\n";
cout << "(2) Show all faculty data\n";
if (canEnterStudentData)
cout << "(3) Enter student data\n";
if (canEnterFacultyData)
cout << "(4) Enter faculty data\n";
cout << "(5) Display data of a specific identity of student\n";
cout << "(6) Display data of a specific identity of faculty\n";
cout << red << "(7) Exit this section\n" << reset;
cin >> department_choice;
// ----------------------------THE CORE OF THE PROGRAM----------------------------
// calling the respective functions upon the choice made
switch (department_choice)
{
case '1':
// call func from st(BCA) object if the user chose bca else call func from st2(MCA)
(ch == 1 ? st.displaystudentdata() : st1.displaystudentdata());
break;
case '2':
// call func from fc(BCA) object if the user chose bca else call func from fc2(MCA)
(ch == 1 ? fc.displayfacultydata() : fc1.displayfacultydata());
break;
case '3':
if (canEnterStudentData)
{
getStudentInput(name, id, course, email);
// add the data to BCA if user chose BCA else MCA
(ch == 1 ? st.setstudentdata(name, id, course, email) : st1.setstudentdata(name, id, course, email));
}
else
// show warning message if user is a faculty
cout << red << "\nYou are not allowed to enter student data!\n" << reset;
break;
case '4':
if (canEnterFacultyData)
{
getFacultyInput(name, id, course, email);
// add the data to BCA if user chose BCA else MCA
(ch == 1 ? fc.setfacultydata(name, id, course, email) : fc1.setfacultydata(name, id, course, email));
}
else
// show warning message if user is either a faculty or a coordinator
cout << red << "\nYou are not allowed to enter faculty data!\n" << reset;
break;
case '5':
cout << blue << "\nEnter any detail of the student (ID, Name, Email address):\n";
cin >> st_id;
(ch == 1 ? st.stid_display(st_id) : st1.stid_display(st_id));
break;
case '6':
cout << blue << "\nEnter any detail of the faculty (ID, Name, Email address):\n";
cin >> fc_id;
(ch == 1 ? fc.fcid_display(fc_id) : fc1.fcid_display(fc_id));
break;
case '7':
cout << red << "\nExiting this section!\n" << reset;
break;
default:
cout << red << "\nPlease enter a valid choice!\n" << reset;
break;
}
} while (department_choice != '7');
}
else if(ch == 3)
{
cout << red << "\nExiting the system. Goodbye!\n" << reset;
}
else
{
cout << red << "\nPlease enter a valid choice!\n" << reset;
}
} while (ch != 3); // loop runs until the user doesn't select exit (3)
}
else
{
cout << red << "\nIncorrect password!\n" << reset;
}
} while (pass != *correctPassword);
return 0;
}
// definition of input functions
void getStudentInput(string &name, string &id, string &course, string &email)
{
cout << blue << "\nEnter the student full name: ";
cin.ignore();
getline(cin, name);
cout << "Enter the student ID: ";
cin >> id;
cout << "Enter the student Course: ";
cin >> course;
cout << "Enter the student Email Address: ";
cin.ignore();
getline(cin, email);
}
void getFacultyInput(string &name, string &id, string &course, string &email)
{
cout << green << "\nEnter the faculty full name: ";
cin.ignore();
getline(cin, name);
cout << "Enter the faculty ID: ";
cin >> id;
cout << "Enter the faculty Department: ";
cin >> course;
cout << "Enter the faculty Email Address: ";
cin.ignore();
getline(cin, email);
}