-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinal.c
326 lines (281 loc) · 8.6 KB
/
final.c
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
317
318
319
320
321
322
323
324
325
326
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
void registration()
{
FILE *file;
char profession[15], id[15], fname[15], lname[15], password[15];
printf("\nWhat is your profession?\n");
printf("If you are a teacher type (TEACHER) or if you are a student type (STUDENT) :: ");
scanf("%s",profession);
printf("Enter your ID :: ");
scanf("%s",id);
printf("Enter first name :: ");
scanf("%s",fname);
printf("Enter last name :: ");
scanf("%s",lname);
printf("Enter password :: ");
scanf("%s",password);
file=fopen("record.txt","a");
fprintf(file,"\n%s %s %s %s %s \n", profession, id, fname, lname, password);
printf(" Registration was successful. Please Log In.\n");
fclose(file);
}
int login()
{
char id[15],password[15];
printf("\nEnter your ID :: ");
scanf("%s",id);;
printf("Enter your password :: ");
scanf("%s",password);
int flag=0;
char prof2[15], id2[15], fname2[15], lname2[15], pass2[15];
FILE *file;
FILE *file2;
file=fopen("record.txt","r");
while(fscanf(file,"\n%s %s %s %s %s\n", prof2, id2, fname2, lname2, pass2)!= EOF)
{
if((strcmp(id2,id)==0) && (strcmp(pass2,password)==0))
{
flag=1;
printf(" Welcome %s %s\n",fname2, lname2);
file2=fopen("login.txt","w");
fprintf(file2,"\n%s %s %s %s\n", prof2, id2, fname2, lname2);
if(strcmp(prof2,"TEACHER")==0)
{
return 1;
}
else if(strcmp(prof2,"STUDENT")==0)
{
return 2;
}
else
printf("\n");
fclose(file2);
}
else
flag=2;
}
if(flag==2)
printf("\n \n Invalid credentials! Please try again.");
fclose(file);
}
void add_project()
{
FILE *file;
char pro_title[100], source[100], id[15];
char res[50] ="not_evaluated_yet.";
printf("\nPlease Enter your student ID :: ");
scanf("%s", id);
strcat(id,".txt");
printf("Write the title code of your Project :: ");
scanf("%s", pro_title);
printf("Type your source code link here :: ");
scanf("%s", source);
int length = strlen(source);
int i;
for (i =0; i<length; i++)
{
if(source[i]==',')
{
printf("\nYou can't insert a comma while taking the source code URL");
}
}
file=fopen(id,"a");
fprintf(file,"\n%s %s %s\n", pro_title, source, res);
if(file!=NULL)
printf(" Record written successfully\n");
fclose(file);
}
void teacher()
{
char id[15];
printf("\nWhich project do you wants to see? Please enter the student ID :: ");
scanf("%s", id);
strcat(id,".txt");
int ch;
char pt[20], sc[50], gd[50];
char pt2[20], sc2[50], gd2[50], gd3[50];
FILE *file;
FILE *file2;
file=fopen(id,"r");
if(file==NULL)
printf("\n Project not found");
else
{
while(fscanf(file,"%s %s %s\n", pt, sc, gd)!= EOF)
{
printf("Project title code :: %s\n",pt);
printf("Project url :: %s\n",sc);
printf("Grade :: %s\n",gd);
}
printf("\nDo you wants to evaluate? (yes=1 & no=0) :: ");
scanf("%d",&ch);
if(ch==1)
{
file2=fopen(id,"w");
printf("\nWhat grade do you wants to give? :: ");
scanf("%s",gd2);
fprintf(file2,"%s %s %s\n", pt, sc, gd2);
fclose(file2);
printf("Grade added successfully.");
}
fclose(file);
}
}
void result()
{
char id[10];
printf("\nEnter your student id to see your result :: ");
scanf("%s", id);
strcat(id,".txt");
FILE *file;
file=fopen(id,"r");
char pt[20], sc[50], res[50];
if(file==NULL)
printf("\nProject not found");
else
{
while(fscanf(file,"%s %s %s\n", pt, sc, res)!= EOF)
{
printf("\nYour grade is = %s",res);
}
fclose(file);
}
}
void logout()
{
char prof[15]="NULL";
char id[15]="NULL";
char fname[15]="NULL";
char lname[15]="NULL";
FILE *file;
file=fopen("login.txt","w");
fprintf(file,"\n%s %s %s %s\n", prof, id, fname, lname);
fclose(file);
printf("\n \n Logout successful.");
}
void menu()
{
int ch, ch2, ch3, ch4, ch5, ch6;
int res;
printf("\n\nWants to REGISTRATION again?\n");
printf("Enter (1) for REGISTRATION or (0) to LOGIN :: ");
scanf("%d",&ch);
if(ch==1)
registration();
system("CLS");
printf("\nDo you wants to LOGIN now?\n");
printf("Enter (1) for LOGIN or (0) to skip :: ");
scanf("%d",&ch2);
if(ch2==1)
{
res = login();
if(res==2)
{
printf("\n\nDo you wants to add a new project?\n");
printf("Enter (1) to add new project or (0) to skip :: ");
scanf("%d",&ch3);
if(ch3==1)
add_project();
printf("\n\nDo you wants to see your grade?\n");
printf("Enter (1) for YES or (0) to skip :: ");
scanf("%d",&ch4);
if(ch4==1)
result();
printf("\n\nDo you want to LOGOUT?\n");
printf("Enter (1) for YES or (0) to skip :: ");
scanf("%d",&ch5);
if(ch5==1)
{
logout();
}
else
{
system("CLS");
menu();
}
}
else if(res==1)
{
teacher();
printf("\n\nDo you want to LOGOUT?\n");
printf("Enter (1) for YES or (0) to skip :: ");
scanf("%d",&ch6);
if(ch6==1)
{
logout();
}
}
else
{
system("CLS");
menu();
}
}
}
void main()
{
system("color 9F");
printf(" <---MAIN MENU--->\n");
printf("\n");
printf(" 'IF YOU'RE NOT REGISTERED YET, PLEASE REGISTER FIRST TO LOGIN YOURSELF'\n");
int ch, ch2, ch3, ch4, ch5, ch6;
int res;
printf("\n\nDo you wants to REGISTRATION now?\n");
printf("Enter (1) for REGISTRATION or (0) to LOGIN :: ");
scanf("%d",&ch);
if(ch==1)
registration();
system("CLS");
printf("\nDo you wants to LOGIN now?\n");
printf("Enter (1) for LOGIN or (0) to skip :: ");
scanf("%d",&ch2);
if(ch2==1)
{
res = login();
if(res==2)
{
printf("\n\nDo you wants to add a new project?\n");
printf("Enter (1) to add new project or (0) to skip :: ");
scanf("%d",&ch3);
if(ch3==1)
add_project();
printf("\n\nDo you wants to see your grade?\n");
printf("Enter (1) for YES or (0) to skip :: ");
scanf("%d",&ch4);
if(ch4==1)
result();
printf("\n\nDo you want to LOGOUT?\n");
printf("Enter (1) for YES or (0) to skip :: ");
scanf("%d",&ch5);
if(ch5==1)
{
logout();
}
else
{
system("CLS");
menu();
}
}
else if(res==1)
{
teacher();
printf("\n\nDo you want to LOGOUT?\n");
printf("Enter (1) for YES or (0) to skip :: ");
scanf("%d",&ch6);
if(ch6==1)
{
logout();
}
else
{
system("CLS");
menu();
}
}
else
printf("Please enter your valid identity!");
}
}