-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
392 lines (348 loc) · 10.6 KB
/
main.c
File metadata and controls
392 lines (348 loc) · 10.6 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
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <conio.h>
#define MAX_STUDENTS 100
typedef struct
{
char CourseName[50];
int rating;
bool registration;
}Course;
typedef struct
{
char TeacherName[50];
int rating;
}Teacher;
typedef struct
{
char studentID[7];
char password[50];
}Student;
void registerStudent(Student students[], int *numStudents);
void saveStudentToFile(Student student);
void registerCourses(Course courses[]);
void viewRegisteredCourses(Course courses[]);
void courseFeedback(Course courses[]);
void teacherFeedback(Teacher teachers[], Course courses[]);
void printFeedback(Course courses[], Teacher teachers[]);
bool signInUser(Student students[], int *numStudents);
bool isNumeric(const char *str);
int main()
{
Student students[MAX_STUDENTS];
int numStudents = 0;
bool Login = false;
bool registered = false;
do
{
Login = signInUser(students, &numStudents);
if (!Login)
{
printf("\nInvalid Student ID or Password, Please Try Again!\n\n");
}
else
{
system("cls");
break;
}
} while (!Login);
Course courses[9];
Teacher teachers[9];
for(int i=0; i<9; i++)
{
strcpy(courses[i].CourseName," ");
courses[i].rating = 0;
courses[i].registration = false;
}
//Assigning names of courses
strcpy(courses[0].CourseName,"Fundamentals Of Programming");
strcpy(courses[1].CourseName,"Applied Physics");
strcpy(courses[2].CourseName,"Calculus and Analytical Geometry");
strcpy(courses[3].CourseName,"Introduction to Computer Science");
strcpy(courses[4].CourseName,"Pakistan Studies");
strcpy(courses[5].CourseName,"English");
strcpy(courses[6].CourseName,"Lab, Fundamentals Of Programming");
strcpy(courses[7].CourseName,"Lab, Introduction to Computer Science");
strcpy(courses[8].CourseName,"Lab, Applied Physics");
//Assigning names of course instructors
strcpy(teachers[0].TeacherName,"Sheikh-Usama-Khalid");
strcpy(teachers[1].TeacherName,"Naveed Ghani");
strcpy(teachers[2].TeacherName,"Tahir Abbasi");
strcpy(teachers[3].TeacherName,"Khalil-ur-Rehman");
strcpy(teachers[4].TeacherName,"Koonj-Altaf");
strcpy(teachers[5].TeacherName,"Laila-Rizwan");
strcpy(teachers[6].TeacherName,"Qambar Ali");
strcpy(teachers[7].TeacherName,"Shehzad Abbasi");
strcpy(teachers[8].TeacherName,"Ashar Tariq");
int option;
do
{
printf("\n--- Menu ---\n");
printf("1. Register Courses\n");
printf("2. View Registered Courses\n");
printf("3. Evaluate courses\n");
printf("4. Evaluate teachers\n");
printf("5. Print evaluation\n");
printf("6. Exit\n");
printf("Enter your choice(1-6): ");
scanf("%d", &option);
switch(option)
{
case 1:
registerCourses(courses);
registered=true;
break;
case 2:
if(registered)
{
viewRegisteredCourses(courses);
}
else
{
printf("\nNo Courses have been Registered Yet!\n");
}
break;
case 3:
if(registered)
{
printf("\nEnter Course Rating(1-5): \n");
courseFeedback(courses);
}
else
{
printf("\nYou need to Register for Courses First!\n");
}
break;
case 4:
if(registered)
{
printf("\nEnter Course Instructor Rating(1-5): \n");
teacherFeedback(teachers, courses);
}
else
{
printf("\nYou need to Register for Courses First!\n");
}
break;
case 5:
if(registered)
{
printFeedback(courses, teachers);
}
else
{
printf("\nYou need to Register for Courses First!\n");
}
break;
case 6:
printf("You chose to Exit the Program! \n");
break;
default:
printf("Invalid option! Should be(1-6).\n");
break;
}
}
while (option != 6);
return 0;
}
void registerStudent(Student students[], int *numStudents)
{
Student newStudent;
printf("\nEnter Student ID (6 digits): ");
while (scanf("%6s", newStudent.studentID) != 1 || strlen(newStudent.studentID) != 6 || !isNumeric(newStudent.studentID))
{
printf("Invalid input. Please enter a valid 6-digit number: ");
while (getchar() != '\n');
}
printf("Enter Password (at least 8 characters): ");
while (scanf("%s", newStudent.password) != 1 || strlen(newStudent.password)<8)
{
printf("Invalid input. Please enter a password with at least 8 characters: ");
while (getchar() != '\n');
}
students[*numStudents] = newStudent;
(*numStudents)++;
saveStudentToFile(newStudent);
printf("\nRegistration successful!\n");
system("cls");
}
bool isNumeric(const char *str)
{
while(*str)
{
if(!isdigit(*str))
{
return false;
}
str++;
}
return true;
}
void saveStudentToFile(Student student)
{
FILE *file = fopen("students.txt", "a");
if (file != NULL)
{
fprintf(file, "%s %s\n", student.studentID, student.password);
fclose(file);
}
}
bool signInUser(Student students[], int *numStudents)
{
char studentID[7];
char password[50];
printf("Enter Student ID: ");
scanf("%s", studentID);
for (int i=0; i<*numStudents; ++i)
{
if (strcmp(studentID, students[i].studentID)==0)
{
printf("Enter Password: ");
scanf("%s", password);
if (strcmp(password, students[i].password)==0)
{
return true;
}
else
{
printf("Invalid Password! Please Try Again.\n");
return false;
}
}
}
if(*numStudents<MAX_STUDENTS)
{
printf("Student ID not found. Create a new account? (Y/N): ");
char choice;
scanf(" %c", &choice);
if (choice == 'Y' || choice == 'y')
{
registerStudent(students, numStudents);
return true;
}
}
return false;
}
void registerCourses(Course courses[])
{
printf("\nAvailable Courses:\n");
for (int i=0; i<9; i++)
{
printf("%d. %s\n", i+1, courses[i].CourseName);
}
printf("\nEnter the numbers of the courses you want to register (up to 9, enter 0 to finish): ");
int courseNumber;
int count = 0;
while(count<9)
{
if(scanf("%d", &courseNumber)==1)
{
if(courseNumber==0)
{
break;
}
else if(courseNumber>=1 && courseNumber<=9 && !courses[courseNumber-1].registration)
{
courses[courseNumber-1].registration=true;
count++;
printf("%s has been registered.\n", courses[courseNumber-1].CourseName);
}
else
{
printf("Invalid course number or course already registered.\n");
}
}
else
{
printf("Invalid input. Please enter a number.\n");
while (getchar() != '\n');
}
}
system("cls");
}
void viewRegisteredCourses(Course courses[])
{
printf("\nRegistered Courses:\n");
int count = 0;
for (int i=0; i<9; i++)
{
if (courses[i].registration)
{
printf("%s\n", courses[i].CourseName);
count++;
}
}
if (count==0)
{
printf("None.\n");
}
}
void courseFeedback(Course courses[])
{
for(int i=0; i<9; i++)
{
if(courses[i].registration)
{
printf("%s: ", courses[i].CourseName);
scanf("%d", &courses[i].rating);
while(courses[i].rating<1 || courses[i].rating>5)
{
printf("Invalid Rating! Should be (1-5)\n");
printf("%s: ", courses[i].CourseName);
scanf("%d", &courses[i].rating);
}
}
}
system("cls");
}
void teacherFeedback(Teacher teachers[], Course courses[])
{
for(int i=0; i<9; i++)
{
if(courses[i].registration)
{
printf("%s: ", teachers[i].TeacherName);
scanf("%d", &teachers[i].rating);
while(teachers[i].rating<1 || teachers[i].rating>5)
{
printf("Invalid Rating! Should be (1-5)\n");
printf("%s: ", teachers[i].TeacherName);
scanf("%d", &teachers[i].rating);
}
}
}
system("cls");
}
void printFeedback(Course courses[],Teacher teachers[])
{
int coursesRating = 0;
int teachersRating = 0;
printf("\nCourse Evaluation: \n");
for(int i=0; i<9; i++)
{
if(courses[i].registration && courses[i].rating >=1 && courses[i].rating<=5)
{
printf("%s: %d\n", courses[i].CourseName, courses[i].rating);
coursesRating = 1;
}
}
if(!coursesRating)
{
printf("\nCourses have not been Evaluated therefore, Can not be Printed! \n");
}
printf("\nTeachers' Evaluation: \n");
for(int i=0; i<9; i++)
{
if(courses[i].registration && teachers[i].rating >=1 && teachers[i].rating<=5)
{
printf("%s: %d\n", teachers[i].TeacherName, teachers[i].rating);
teachersRating = 1;
}
}
if(!teachersRating)
{
printf("\nTeachers have not been Evaluated therefore, Can not be Printed! \n");
}
}