forked from koko89090k-design/Student_Management_System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.cpp
More file actions
169 lines (130 loc) · 4.71 KB
/
Copy pathstudent.cpp
File metadata and controls
169 lines (130 loc) · 4.71 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
#include "student.h"
#include "course.h"
#include "color.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void addStudent(vector<Student>& students) {
Student s;
// دخل id الطالب
cout << CYAN << "Enter Student ID: " << RESET;
cin >> s.id;
// نتأكد إن الـ ID مش موجود قبل كده
if (findStudentById(students, s.id) != nullptr) {
cout << RED << "Error: Student with ID " << s.id
<< " already exists!" << RESET << '\n';
return;
}
// دخل الاسم كامل
cout << CYAN << "Enter Name: " << RESET;
cin.ignore();
getline(cin, s.name);
// دخل السنه وتأكد منها
cout << CYAN << "Enter Year: " << RESET;
while (!(cin >> s.year) || s.year < 1 || s.year > 7) {
cout << RED << "Invalid input! Enter a valid year (1-7): "
<< RESET;
cin.clear();
cin.ignore(10000, '\n');
}
students.push_back(s);
cout << GREEN << "Student Added Successfully!" << RESET << '\n';
}
// دور علي الطالب بأستخدام ال ID
Student* findStudentById(vector<Student>& students, const string& id) {
for (int i = 0; i < students.size(); ++i) {
if (students[i].id == id) {
return &students[i];
}
}
return nullptr;
}
// اطبع كل معلومات الطالب
void printStudent(const Student& s) {
cout << BLUE << "===========================" << RESET << '\n';
cout << CYAN << "ID: " << RESET << s.id << '\n';
cout << CYAN << "Name: " << RESET << s.name << '\n';
cout << CYAN << "Year: " << RESET << s.year << '\n';
cout << CYAN << "Enrolled Courses: " << RESET;
if (s.enrolledCourseIds.empty()) {
cout << RED << "None" << RESET;
} else {
for (int i = 0; i < s.enrolledCourseIds.size(); ++i) {
cout << GREEN << s.enrolledCourseIds[i] << RESET;
if (i < s.enrolledCourseIds.size() - 1) {
cout << ", ";
}
}
}
cout << '\n';
cout << BLUE << "===========================" << RESET << '\n';
}
void printStudentGPA(vector<Student>& students, vector<Course>& courses) {
string studentId;
cout << CYAN << "Enter Student ID: " << RESET;
cin >> studentId;
Student* s = findStudentById(students, studentId);
if (s == nullptr) {
cout << RED << "Student not found!" << RESET << '\n';
return;
}
// لو الطالب مش مسجل في أي مادة
if (s->enrolledCourseIds.empty()) {
cout << RED << "Student " << s->name << " is not enrolled in any course." << RESET << '\n';
return;
}
double totalPoints = 0.0;
int totalCredits = 0;
bool hasGrades = false;
// ندور على كل مادة الطالب مسجل فيها
for (int i = 0; i < s->enrolledCourseIds.size(); ++i) {
string courseId = s->enrolledCourseIds[i];
Course* c = nullptr;
for (int j = 0; j < courses.size(); ++j) {
if (courses[j].id == courseId) {
c = &courses[j];
break;
}
}
if (c == nullptr) continue;
for (int k = 0; k < c->grades.size(); ++k) {
if (c->grades[k].first == studentId) {
double grade = c->grades[k].second;
double gradePoint = 0.0;
if (grade >= 90)
gradePoint = 4.0;
else if (grade >= 85)
gradePoint = 3.7;
else if (grade >= 80)
gradePoint = 3.3;
else if (grade >= 75)
gradePoint = 3.0;
else if (grade >= 70)
gradePoint = 2.7;
else if (grade >= 65)
gradePoint = 2.3;
else if (grade >= 60)
gradePoint = 2.0;
else if (grade >= 50)
gradePoint = 1.0;
else
gradePoint = 0.0;
totalPoints += gradePoint * c->credit_hours;
totalCredits += c->credit_hours;
hasGrades = true;
break;
}
}
}
if (!hasGrades) {
cout << RED << "No grades recorded for " << s->name << " yet." << RESET << '\n';
return;
}
double gpa = totalPoints / totalCredits;
cout << BLUE << "===========================" << RESET << '\n';
cout << CYAN << "Student: " << RESET << s->name << '\n';
cout << CYAN << "ID: " << RESET << s->id << '\n';
cout << GREEN << "GPA: " << RESET << gpa << " / 4.0\n";
cout << BLUE << "===========================" << RESET << '\n';
}