-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystem.c
More file actions
181 lines (179 loc) · 4.62 KB
/
System.c
File metadata and controls
181 lines (179 loc) · 4.62 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
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
#include "System.h"
static int tries = 0;
Adminpass *ad;
void Admin()
{
for (int i = 0; i < 3 && tries < 3; i++)
{
char *pass = (char *)malloc(strlen(ad->password) + 1);
printf("Enter Admin Passwords\n");
scanf(" %[^\n]s", pass);
if (strcmp(pass, ad->password) == 0)
{
while (1)
{
printf("Welcome ,Admin \n\
1. Add student record\n\
2. Remove student record\n\
3. View student record\n\
4. View all records\n\
5. Edit admin password\n\
6. Edit student grade\n\
7. Exit\n\
");
unsigned int choice = 3;
printf("Your Choice : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
{
Student *std = readStudent();
// viewStudentRecord(std->id);
break;
}
case 2:
{
printf("Enter ID to Remove\n");
int id = 0;
scanf("%d", &id);
removeStudentRecord(id);
break;
}
case 3:
{
printf("Enter ID to View\n");
int id = 0;
scanf("%d", &id);
viewStudentRecord(id);
break;
}
case 4:
viewAllStudentRecord();
break;
case 5:
editAdminPassword();
break;
case 6:
editStudentGrade();
break;
case 7:
return;
default:
printf("Enter Valid Choice");
}
}
}
else
{
tries++;
printf("Invalid Password\n");
}
}
if (tries == 3)
{
printf("U run out of tries\n");
printf("U can't Enter Admin Mode\n");
}
return;
}
void User(int id)
{
int useraction = 4;
printf("Welcome in user mode.\n");
rechoose:
printf("Please, Choose the number for a certain action.\n"
"1- View your record \n2- Edit your password \n3- Edit your name \n0- Exit\n");
printf("Your Choice: ");
scanf("%d", &useraction);
int i = findPosition(id);
switch (useraction)
{
case 0:
return; // break
case 1:
viewStudentRecord(id);
break;
case 2:
editStudentPassword(i);
break;
case 3:
editStudentName(i);
break;
default:
{
printf("Invalid mode number. \nPlease, Enter a valid number");
}
}
goto rechoose;
}
void ChooseControl()
{
ad = (Adminpass *)malloc(sizeof(Adminpass));
ad->password = "1234";
printf("WelCome To Student Record System: \t\n");
unsigned int choice = 3;
while (1)
{
printf("\n 0 -Admin \n 1-User \n 2-Exit\n");
printf("Your Choice: ");
scanf("%u", &choice);
switch (choice)
{
case 0:
Admin();
break;
case 1:
checkmethod();
break;
case 2:
return;
default:
printf("Enter Valid Choice\n");
}
}
}
void checkmethod()
{
int id;
char *pass = (char *)malloc(strlen(ad->password) + 1);
printf("Please enter your ID: \t\n");
scanf("%d", &id);
for (int i = 0; i < classSize; ++i)
{
if (allRecords[i] != 0 || allRecords[i] != NULL)
{
if (id == allRecords[i]->id)
{
int count = 0;
re_pass:
printf("Please enter your password: \t\n");
scanf(" %[^\n]c", pass);
if (strcmp(pass, allRecords[i]->password) == 0)
{
User(id);
}
else
{
printf("Invalid password");
count++;
if (count < 4)
{
goto re_pass;
}
else
{
break; // break
}
}
return;
}
// else
// {
// printf("Invalid ID");
// checkmethod();
// }
}
}
printf("Invalid ID!");
}