forked from koko89090k-design/Student_Management_System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcourse.cpp
More file actions
193 lines (144 loc) · 5.55 KB
/
Copy pathcourse.cpp
File metadata and controls
193 lines (144 loc) · 5.55 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
#include "course.h"
#include "student.h"
#include "color.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void addCourse(vector<Course>& courses) {
Course c;
// دخل الكود وشوف موجود قبل كده ولا لا
cout << CYAN<< "Enter Course ID: " << RESET;
cin >> c.id;
if (findCourseById(courses, c.id) != nullptr) {
cout << RED << "Error: Course with ID " << c.id << " already exists!" << RESET << '\n';
return;
}
//دخل اسم الماده كله
cout << CYAN << "Enter Title: " << RESET;
cin.ignore();
getline(cin, c.title);
// دخل عدد الساعات
cout << CYAN << "Enter Credit Hours: " << RESET;
while (!(cin >> c.credit_hours) || c.credit_hours < 1 || c.credit_hours > 6) {
cout << RED << "Invalid input! Enter valid credit hours (1-6): " << RESET;
cin.clear();
cin.ignore(10000, '\n');
}
courses.push_back(c);
cout << GREEN << "Course Added Successfully!" << RESET << '\n';
//تمت بخيرررررررررر
}
Course* findCourseById(vector<Course>& courses, const string& id) {
for (int i = 0; i < courses.size(); ++i) {
if (courses[i].id == id) {
return &courses[i];
}
}
return nullptr;
}
void recordGrade(vector<Course>& courses, vector<Student>& students) {
string courseId, studentId;
double grade;
// دخل كود الماده
cout << CYAN<< "Enter Course ID: " << RESET;
cin >> courseId;
Course* c = findCourseById(courses, courseId);
if (c == nullptr) {
cout << RED << "Course not found!" << RESET << '\n';
return;
}
// دخل رقم الطالب
cout << CYAN << "Enter Student ID: " << RESET;
cin >> studentId;
Student* s = findStudentById(students, studentId);
if (s == nullptr) {
cout << RED<< "Student not found!" << RESET << '\n';
return;
}
// نتأكد انه مش موجود قبل كده
for (int i = 0; i < c->grades.size(); ++i) {
if (c->grades[i].first == studentId) {
cout << RED<< "Error: Grade already recorded for this student in this course!" << RESET << '\n';
return;
}
}
cout << CYAN << "Enter Grade (0-100): " << RESET;
while (!(cin >> grade) || grade < 0 || grade > 100) {
cout << RED << "Invalid input! Enter a valid grade (0-100): " << RESET;
cin.clear();
cin.ignore(10000, '\n');
}
// ضيف الدرجه
c->grades.push_back({studentId, grade});
bool alreadyEnrolled = false;
for (int i = 0; i < s->enrolledCourseIds.size(); ++i) {
if (s->enrolledCourseIds[i] == courseId) {
alreadyEnrolled = true;
break;
}
}
//بنضيف الماده لو مش موجوده
if (!alreadyEnrolled) {
s->enrolledCourseIds.push_back(courseId);
}
cout << GREEN << "Grade recorded successfully!" << RESET << '\n';
}
void printCourseReport(vector<Course>& courses, vector<Student>& students) {
string courseId;
cout << CYAN<< "Enter Course ID: " << RESET;
cin >> courseId;
Course* c = findCourseById(courses, courseId);
if (c == nullptr) {
cout << RED<< "Course not found!" << RESET << '\n';
return;
}
cout << BLUE<< "==========================================" << RESET << '\n';
cout <<CYAN << "Course Report: " << RESET << c->title << " (" << c->id << ")\n";
cout << CYAN<< "Credit Hours: " << RESET << c->credit_hours << '\n';
cout << BLUE<< "==========================================" << RESET << '\n';
if (c->grades.empty()) {
cout << RED<< "No grades recorded yet." << RESET << '\n';
cout << BLUE<< "==========================================" << RESET << '\n';
return;
}
double total = 0.0;
double highest = c->grades[0].second;
double lowest = c->grades[0].second;
string topStudent = c->grades[0].first;
string lastStudent = c->grades[0].first;
cout << CYAN<< "Student ID | Name | Grade" << RESET << '\n';
cout << BLUE<< "===============================================" << RESET << '\n';
for (int i = 0; i < c->grades.size(); ++i) {
string sid = c->grades[i].first;
double g = c->grades[i].second;
total += g;
string studentName = "Unknown";
Student* s = findStudentById(students, sid);
if (s != nullptr) {
studentName = s->name;
}
cout << CYAN << sid << RESET;
// شويه مسافات
for (int j = sid.length(); j < 14; ++j) cout << ' ';
cout << "| " << studentName;
for (int j = studentName.length(); j < 20; ++j) cout << ' ';
cout << "| " << g << '\n';
// اعلي واقل واحد
if (g > highest) {
highest = g;
topStudent = sid;
}
if (g < lowest) {
lowest = g;
lastStudent = sid;
}
}
double average = total / c->grades.size();
cout << BLUE << "------------------------------------------" << RESET << '\n';
cout << CYAN << "Total Students: " << RESET << c->grades.size() << '\n';
cout << CYAN << "Average Grade: " << RESET << average << '\n';
cout << CYAN << "Highest Grade: " << RESET << highest << " (Student: " << topStudent << ")\n";
cout << CYAN << "Lowest Grade: " << RESET << lowest << " (Student: " << lastStudent << ")\n";
cout << BLUE << "------------------------------------------" << RESET << '\n';
}