-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlacement_Logic_Code.c
More file actions
237 lines (206 loc) · 6.59 KB
/
Placement_Logic_Code.c
File metadata and controls
237 lines (206 loc) · 6.59 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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define MAX_STUDENTS 100
#define NAME_LEN 50
#define REGNO_LEN 15
#define PHONE_LEN 15
typedef struct {
char name[NAME_LEN];
char regno[REGNO_LEN];
float per10;
float per12;
float cgpa;
int tier;
int eligible;
} Student;
Student students[MAX_STUDENTS];
int student_count = 0;
void get_line(const char *prompt, char *buf, int len) {
printf("%s", prompt);
if (fgets(buf, len, stdin)) {
size_t l = strlen(buf);
if (l && buf[l-1] == '\n') buf[l-1] = '\0';
}
}
int valid_regno(const char *r) {
if (strlen(r) != 10) return 0;
for (int i = 0; i < 2; i++) if (!isdigit(r[i])) return 0;
for (int i = 2; i < 5; i++) if (!isalpha(r[i])) return 0;
for (int i = 5; i < 10; i++) if (!isdigit(r[i])) return 0;
return 1;
}
void classify_student(Student *s) {
if (s->cgpa > 9.0 && s->per10 > 90.0 && s->per12 > 90.0) {
s->tier = 1;
s->eligible = 1;
}
else if (s->cgpa > 8.0 && s->per10 > 80.0 && s->per12 > 80.0) {
s->tier = 2;
s->eligible = 1;
}
else if (s->cgpa > 7.0 && s->per10 > 70.0 && s->per12 > 70.0) {
s->tier = 3;
s->eligible = 1;
}
else {
s->tier = 4;
s->eligible = 0;
}
}
//Reclassification to show the Added or the edited details
void classify_all() {
for (int i = 0; i < student_count; i++)
classify_student(&students[i]);
}
// print one student
void print_student(const Student *s, int idx) {
printf("%2d. %-15s | %-10s | 10th: %.2f%% | 12th: %.2f%% | CGPA: %.2f | Tier: %d | %s\n",
idx+1, s->name, s->regno, s->per10, s->per12, s->cgpa, s->tier,
s->eligible ? "Eligible" : "Ineligible");
}
// show all students
void show_students() {
if (student_count == 0) {
printf("No students to display.\n");
return;
}
puts("\nCurrent Students:");
for (int i = 0; i < student_count; i++)
print_student(&students[i], i);
puts("");
}
// Adding of the student
void add_student() {
if (student_count >= MAX_STUDENTS) {
printf("Max students reached (%d).\n", MAX_STUDENTS);
return;
}
Student tmp;
get_line("Enter name: ", tmp.name, NAME_LEN);
do {
get_line("Enter regno : ", tmp.regno, REGNO_LEN);
if (!valid_regno(tmp.regno))
printf("Invalid format. Try again.\n");
} while (!valid_regno(tmp.regno));
printf("Enter 10th %%: ");
if (scanf("%f", &tmp.per10)!=1) tmp.per10=0;
printf("Enter 12th %%: ");
if (scanf("%f", &tmp.per12)!=1) tmp.per12=0;
printf("Enter final CGPA: ");
if (scanf("%f", &tmp.cgpa)!=1) tmp.cgpa=0;
while(getchar()!='\n');
classify_student(&tmp);
students[student_count++] = tmp;
printf("Student added (now %d students).\n\n", student_count);
}
int find_by_regno(const char *r) {
for (int i = 0; i < student_count; i++)
if (strcmp(students[i].regno, r) == 0)
return i;
return -1;
}
// modification of the details
void modify_student() {
char r[REGNO_LEN];
get_line("Enter regno of student to modify: ", r, REGNO_LEN);
int idx = find_by_regno(r);
if (idx < 0) {
printf("Not found.\n");
return;
}
Student *s = &students[idx];
printf("Modifying %s (%s)\n", s->name, s->regno);
get_line(" New name (blank to keep): ", r, REGNO_LEN);
if (r[0]) strncpy(s->name, r, NAME_LEN);
get_line(" New 10th %% (blank to keep): ", r, REGNO_LEN);
if (r[0]) s->per10 = atof(r);
get_line(" New 12th %% (blank to keep): ", r, REGNO_LEN);
if (r[0]) s->per12 = atof(r);
get_line(" New CGPA (blank to keep): ", r, REGNO_LEN);
if (r[0]) s->cgpa = atof(r);
classify_student(s);
printf("Student updated.\n");
}
// remove student
void remove_student() {
char r[REGNO_LEN];
get_line("Enter regno of student to remove: ", r, REGNO_LEN);
int idx = find_by_regno(r);
if (idx < 0) {
printf("Not found.\n");
return;
}
for (int i = idx; i < student_count - 1; i++)
students[i] = students[i+1];
student_count--;
printf("Student removed.\n");
}
// Changing the eligiblity
void toggle_eligibility() {
char r[REGNO_LEN];
get_line("Enter regno to toggle eligibility: ", r, REGNO_LEN);
int idx = find_by_regno(r);
if (idx < 0) {
printf("Not found.\n");
return;
}
students[idx].eligible = !students[idx].eligible;
printf("Now %s is %s for placement.\n",
students[idx].name,
students[idx].eligible ? "eligible" : "ineligible");
}
int main() {
// login
char user[20], pass[20];
printf(" Placement Cell \n");
printf("Username: ");
if (!fgets(user, sizeof user, stdin)) return 0;
user[strcspn(user, "\n")] = 0;
printf("Password: ");
if (!fgets(pass, sizeof pass, stdin)) return 0;
pass[strcspn(pass, "\n")] = 0;
if (strcmp(user, "pcell") || strcmp(pass, "pcell")) {
printf("Login failed.\n");
return 0;
}
// Prefill 7 Avengers
Student defaults[] = {
{"Tony Stark", "23BCY10001", 95.0, 93.0, 9.5, 0, 0},
{"Steve Rogers", "23BAI10002", 85.0, 88.0, 8.4, 0, 0},
{"Bruce Banner", "23BCE10003", 72.5, 75.0, 7.5, 0, 0},
{"Natasha Romanoff", "23MEI10004", 68.0, 70.0, 6.8, 0, 0},
{"Clint Barton", "23BCY10005", 91.0, 89.0, 8.2, 0, 0},
{"Peter Parker", "23BAI10006", 92.0, 92.0, 9.0, 0, 0},
{"Wanda Maximoff", "23BCE10007", 98.0, 97.0, 9.6, 0, 0}
};
for (int i = 0; i < 7; i++) {
classify_student(&defaults[i]);
students[student_count++] = defaults[i];
}
// main menu
int choice;
do {
printf("\nMenu:\n"
" 1. Show all students\n"
" 2. Add student\n"
" 3. Modify student\n"
" 4. Remove student\n"
" 5. Toggle eligibility\n"
" 0. Exit\n"
"Enter choice: ");
if (scanf("%d", &choice) != 1) choice = -1;
while (getchar() != '\n'); // clear
switch (choice) {
case 1: show_students(); break;
case 2: add_student(); break;
case 3: modify_student();break;
case 4: remove_student();break;
case 5: toggle_eligibility(); break;
case 0: printf("Goodbye.\n \xE2\x84\xA2 Snehil Shourya"); break;
default: printf("Invalid choice.\n");
}
} while (choice != 0);
return 0;
}