-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent_grade_mansys.c
162 lines (123 loc) · 3.04 KB
/
student_grade_mansys.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int count;
typedef struct{
char name[50];
int ID;
float cgpa;
char grade;
} Student;
void display(){
printf("\nWelcome to the Student Grade Management System");
printf("\n ----- Made By 0x00S30")
;
printf("\n----------------------------------------------");
}
void display_menu(){
printf("\n\nMENU: \n1.ADD STUDENT DETAILS \n2.DISPLAY STUDENT DETAILS \n3.EXIT");
}
void calculate_grade(Student *student){
if(student->cgpa > 8.0){
student->grade = 'A';
}
else if(student->cgpa > 6.0){
student->grade = 'B';
}
else if(student->cgpa > 4.0){
student->grade = 'C';
}
else if(student->cgpa > 2.0){
student->grade = 'D';
}
else{
student->grade = 'U';
}
}
void display_details(Student student_array){
printf("-------------------------------");
printf("\nName: %s", student_array.name);
printf("\nID: %d", student_array.ID);
printf("\nCGPA: %.2f", student_array.cgpa);
printf("\nGRADE: %c", student_array.grade);
printf("\n-------------------------------\n");
}
void clear_input_buffer() {
int c;
while ((c = getchar()) != '\n' && c != EOF);
}
void add_students(Student student_array[]){
printf("\nADDING STUDENT DETAILS");
printf("\nEnter total number of students: ");
scanf("%d", &count);
clear_input_buffer();
if(count < 1 || count > 100){
printf("\nInvalid number of students");
return;
}
for(int i = 0; i < count; i++){
printf("\n\nEnter details for Student %d", i + 1);
printf("\n\nName: ");
fgets(student_array[i].name, 50, stdin);
student_array[i].name[strcspn(student_array[i].name, "\n")] = '\0';
printf("ID: ");
scanf("%d", &student_array[i].ID);
clear_input_buffer();
printf("CGPA: ");
scanf("%f", &student_array[i].cgpa);
clear_input_buffer();
calculate_grade(&student_array[i]);
}
}
void disp_tot_details(Student student_array[]){
for(int i = 0; i < count; i++){
printf("\n\n\nDetails of student[%d]: \n", i + 1);
display_details(student_array[i]);
}
}
int main(){
int choice;
int counter = 0;
display();
display_menu();
Student student_array[100];
while(1){
printf("\n\nOption: ");
scanf("%d", &choice);
clear_input_buffer();
switch(choice){
case 1:
add_students(student_array);
printf("\nStudent Data Added successfully into the Database");
break;
case 2:
if(counter == 0){
printf("No Data to Show");
printf("\nAdd some data first!");
char s_opt;
printf("\nWant to add data? (y/n): ");
scanf(" %c", &s_opt);
clear_input_buffer();
if(s_opt == 'y' || s_opt == 'Y'){
add_students(student_array);
break;
}
else if(s_opt == 'n' || s_opt == 'N'){
printf("\nNo available data. \nExiting Display Operation.....");
break;
}
}
disp_tot_details(student_array);
break;
case 3:
printf("----------Thank you for using our service----------");
printf("\nExiting......");
exit(0);
default:
printf("\nInvalid Choice");
break;
}
counter++;
}
return 0;
}