-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkiwi's fruit_UTM ATTENDANCE SYSTEM.cpp
316 lines (272 loc) · 7.22 KB
/
kiwi's fruit_UTM ATTENDANCE SYSTEM.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#include <iostream>
#include <algorithm>
#include <string>
#include <ctime>
using namespace std;
class nodeStack
{
public:
string FullName;
string MatricNum;
string dt;
nodeStack *next;
nodeStack(){
FullName="";
MatricNum="";
}
nodeStack(string FullName, string MatricNum,string dt){
this->FullName=FullName;
this->MatricNum=MatricNum;
this->dt=dt;
}
};
class stack
{
private:
nodeStack* top;
public:
void createStack(){
top=NULL;
}
bool isEmpty(){
return top == NULL;
}
void push();
void pop();
void display();
void search();
void sort();
};
void stack::push()
{
string newFullName, newMatricNum;
nodeStack* node = new nodeStack;
nodeStack* currNode = top;
time_t datetime = time(0);
string dt = ctime(&datetime);
if(node == NULL){
cout << "Cannot allocate memory." << endl;
}
else{
system("CLS");
cout << "<<<<<<< Insert Attendance >>>>>>>" << endl << endl;
cout<<"Enter Matric Number:"<<endl;
getline(cin,newMatricNum);
transform(newMatricNum.begin(), newMatricNum.end(), newMatricNum.begin(), ::toupper);
cout<<"Enter Full Name:"<<endl;
getline(cin,newFullName);
transform(newFullName.begin(), newFullName.end(), newFullName.begin(), ::toupper);
cout<<"Date : "<<dt<<endl;
node->MatricNum = newMatricNum;
node->FullName = newFullName;
node->dt=dt;
node->next = top;
top = node;
}
}
void stack::pop(){
nodeStack* delNode;
nodeStack* currNode = top;
time_t datetime = time(0);
string dt = ctime(&datetime);
system("CLS");
if(top == NULL){
cout<<"Attendance is empty"<<endl;
cout<<"<<Press any key to continue>>";
cin.get();
}
else{
string matricNum;
cout << "Enter the Matric Number of the student whose attendance you want to remove: ";
cin >> matricNum;
nodeStack* delNode;
nodeStack* currNode = top;
nodeStack* prevNode = NULL;
while (currNode != NULL) {
if (currNode->MatricNum == matricNum) {
cout << "Full Name : " << currNode->FullName << endl;
cout << "Matric Number : " << currNode->MatricNum << endl;
cout<<"Date: "<<currNode->dt<<endl;
cout << "<< Press any key to continue >>";
cin.get();
if (prevNode == NULL) {
top = currNode->next;
}
else {
prevNode->next = currNode->next;
}
delNode = currNode;
delete delNode;
break;
}
prevNode = currNode;
currNode = currNode->next;
}
}
}
void stack::display(){
int num=0;
nodeStack* currNode = top;
system("CLS");
cout << "<<<<<<< Display Attendance History >>>>>>>" << endl << endl;
if (isEmpty()){
cout<<"no History"<<endl;
}
else{
while(currNode != NULL){
cout<<"["<< num++ <<"]" << "\tFull Name : " << currNode->FullName <<endl;
cout<<"\tMatric Number : " << currNode->MatricNum <<endl;
cout<<"\tDate: "<<currNode->dt<<endl <<endl;
currNode = currNode->next;
}
}
cout<<"<<Press any key to continue>>";
cin.get();
}
void stack::search(){
int choice;
string input;
string abc;
nodeStack* currNode = top;
system("CLS");
cout << "<<<<<<< Search Attendance(s) >>>>>>>" << endl << endl;
cout << "Enter Matric Number : ";
getline(cin,input);
if(currNode == NULL){
cout<<"No Record Found, Stack Empty"<<endl;
}
else{
bool found = false;
while(currNode != NULL){
abc = currNode->MatricNum;
if(input == abc){
cout<< "\tPage Full Name : " << currNode->FullName <<endl;
cout<< "\tPage Matric Number : " << currNode->MatricNum <<endl;
cout<<"\tDate: "<<currNode->dt<<endl;
found = true;
}
currNode = currNode->next;
}
if(!found){
cout<<"No Record Found"<<endl;
}
}
cout << "<< Finish searching... Press any key to continue >>";
cin.get();
}
void stack::sort(){
nodeStack* currNode;
nodeStack* nextNode;
bool swapped;
int n = 0;
nodeStack* lastNode = NULL;
if (isEmpty()){
cout<<"no data to sort"<<endl;
}
else {
while (lastNode != top) {
currNode = top;
swapped = false;
while (currNode->next != lastNode) {
nextNode = currNode->next;
if (currNode->FullName > nextNode->FullName) {
swap(currNode->FullName, nextNode->FullName);
swap(currNode->MatricNum, nextNode->MatricNum);
swap(currNode->dt, nextNode->dt);
swapped = true;
}
currNode = currNode->next;
}
lastNode = currNode;
if (!swapped) break;
}
display();
}
}
//To display main menu
void dispMenu()
{
system("CLS");
cout << "UTM ATTENDANCE " << endl
<< "\n\t1. Remove Name"
<< "\n\t2. Search Attendance"
<< "\n\t3. Display List of Attendance"
<< "\n\t4. Display by Sorting Alphabetical Order"
<< "\n\t5. Exit"
<< "\n\t6. Back To Main Page"<<endl;
}
void dispMenuStudent()
{
system("CLS");
cout << "UTM ATTENDANCE " << endl
<< "\n\t1. Insert Name / Attendance"
<< "\n\t2. Return To Main Page" << endl;
}
int main()
{
time_t datetime = time(0);
string dt = ctime(&datetime);
stack attend;
attend.createStack();
int choice, option1;
do{
system("cls");
cout << "\n:::::::::::::::::::: UTM ATTENDANCE SYSTEM ::::::::::::::::::::\n";
cout << "Welcome to our Main Menu!\n\n";
cout << "Are you a staff or student?\n";
cout << "[1] Staff\n";
cout << "[2] Student\n";
cout << "[3] Exit\n";
cin>>option1;
if(option1 == 1){
do
{
dispMenu();
cout << "\nEnter your choice [1-6]: ";
cin >> choice;
cin.ignore();
switch (choice)
{
case 1:
attend.pop();
break;
case 2:
attend.search();
break;
case 3:
attend.display();
break;
case 4:
attend.sort();
break;
case 5:
exit(0);
break;
default:
cout<<"Invalid input, try again."<<endl;
break;
}
}while ((choice>0)&&(choice<=5));
}
if(option1 == 2){
do
{
dispMenuStudent();
cout << "\nEnter your choice [1-2]: ";
cin >> choice;
cin.ignore();
switch (choice)
{
case 1:
attend.push();
break;
default:
cout<<"Invalid input, try again."<<endl;
break;
}
}while ((choice>0)&&(choice<=1));
}
}while(option1 != 3);
cout << "Thank you for choosing our system!\n";
return 0;
}