-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentManagementSystem.cpp
265 lines (223 loc) · 7.82 KB
/
StudentManagementSystem.cpp
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
//
// Created by Claudio Delgado on 2024-11-11.
//
// StudentManagementSystem.cpp
#include "StudentManagementSystem.h"
#include "DataRepository.h"
#include "Student.h"
#include "Course.h"
#include "Grade.h"
#include "GradeType.h"
#include "GradeFactory.h"
#include "GradeCalculationStrategy.h"
#include "SimpleGradeCalculationStrategy.h"
#include <iostream>
#include <string>
#include <memory>
void StudentManagementSystem::run() {
int choice;
do {
displayMenu();
std::cin >> choice;
std::cin.ignore(); // Clear the newline character from the input buffer
handleUserChoice(choice);
} while (choice != 9); // Assuming 9 is the option to exit
}
void StudentManagementSystem::displayMenu() {
std::cout << "Student Management System\n";
std::cout << "1. Register Student\n";
std::cout << "2. Add Course\n";
std::cout << "3. Enroll Student in Course\n";
std::cout << "4. View Student Records\n";
std::cout << "5. Mark Attendance\n";
std::cout << "6. View Attendance Records\n";
std::cout << "7. Assign Grades\n";
std::cout << "8. View Student Grades\n";
std::cout << "9. Exit\n";
std::cout << "Enter choice: ";
}
void StudentManagementSystem::handleUserChoice(int choice) {
switch (choice) {
case 1:
registerStudent();
break;
case 2:
addCourse();
break;
case 3:
enrollStudentInCourse();
break;
case 4:
viewStudentRecords();
break;
case 5:
markAttendance();
break;
case 6:
viewAttendanceRecords();
break;
case 7:
assignGrades();
break;
case 8:
viewStudentGrades();
break;
case 9:
std::cout << "Exiting program.\n";
break;
default:
std::cout << "Invalid choice.\n";
break;
}
std::cout << std::endl;
}
void StudentManagementSystem::registerStudent() {
std::string name, rollNumber, contactInfo;
int age;
std::cout << "Enter student name: ";
std::getline(std::cin, name);
std::cout << "Enter roll number: ";
std::getline(std::cin, rollNumber);
std::cout << "Enter age: ";
std::cin >> age;
std::cin.ignore(); // Clear the newline character
std::cout << "Enter contact info: ";
std::getline(std::cin, contactInfo);
auto student = std::make_shared<Student>(name, rollNumber, age, contactInfo);
DataRepository::getInstance().addStudent(student);
std::cout << "Student registered successfully.\n";
}
void StudentManagementSystem::addCourse() {
std::string name, code;
std::cout << "Enter course name: ";
std::getline(std::cin, name);
std::cout << "Enter course code: ";
std::getline(std::cin, code);
auto course = std::make_shared<Course>(name, code);
DataRepository::getInstance().addCourse(course);
std::cout << "Course added successfully.\n";
}
void StudentManagementSystem::enrollStudentInCourse() {
std::string rollNumber, courseCode;
std::cout << "Enter student roll number: ";
std::getline(std::cin, rollNumber);
std::cout << "Enter course code: ";
std::getline(std::cin, courseCode);
auto& repository = DataRepository::getInstance();
auto student = repository.getStudentByRollNumber(rollNumber);
auto course = repository.getCourseByCode(courseCode);
if (student && course) {
course->enrollStudent(student);
student->enrollInCourse(course);
std::cout << "Student enrolled in course successfully.\n";
} else {
std::cout << "Invalid student roll number or course code.\n";
}
}
void StudentManagementSystem::viewStudentRecords() {
std::string rollNumber;
std::cout << "Enter student roll number: ";
std::getline(std::cin, rollNumber);
auto student = DataRepository::getInstance().getStudentByRollNumber(rollNumber);
if (student) {
student->printInfo();
} else {
std::cout << "Student not found.\n";
}
}
void StudentManagementSystem::markAttendance() {
std::string rollNumber, courseCode, date;
int statusInt;
std::cout << "Enter student roll number: ";
std::getline(std::cin, rollNumber);
std::cout << "Enter course code: ";
std::getline(std::cin, courseCode);
std::cout << "Enter date (YYYY-MM-DD): ";
std::getline(std::cin, date);
std::cout << "Enter attendance status (1 for Present, 0 for Absent): ";
std::cin >> statusInt;
std::cin.ignore(); // Clear the newline character
AttendanceStatus status = (statusInt == 1) ? AttendanceStatus::Present : AttendanceStatus::Absent;
auto& repository = DataRepository::getInstance();
auto student = repository.getStudentByRollNumber(rollNumber);
auto course = repository.getCourseByCode(courseCode);
if (student && course) {
course->markAttendance(student, date, status);
std::cout << "Attendance recorded successfully.\n";
} else {
std::cout << "Invalid student roll number or course code.\n";
}
}
void StudentManagementSystem::viewAttendanceRecords() {
std::string rollNumber, courseCode;
std::cout << "Enter student roll number: ";
std::getline(std::cin, rollNumber);
std::cout << "Enter course code: ";
std::getline(std::cin, courseCode);
auto student = DataRepository::getInstance().getStudentByRollNumber(rollNumber);
if (student) {
student->viewAttendance(courseCode); // Pass the courseCode argument
} else {
std::cout << "Student not found.\n";
}
}
void StudentManagementSystem::assignGrades() {
std::string studentRoll, courseCode, gradeName;
int gradeTypeInt;
double score;
std::cout << "Enter student roll number: ";
std::getline(std::cin, studentRoll);
std::cout << "Enter course code: ";
std::getline(std::cin, courseCode);
std::cout << "Enter grade name: ";
std::getline(std::cin, gradeName);
std::cout << "Enter grade type (1: Assignment, 2: Quiz, 3: Exam): ";
std::cin >> gradeTypeInt;
std::cout << "Enter score: ";
std::cin >> score;
std::cin.ignore(); // Clear the newline character
GradeType gradeType;
switch (gradeTypeInt) {
case 1:
gradeType = GradeType::Assignment;
break;
case 2:
gradeType = GradeType::Quiz;
break;
case 3:
gradeType = GradeType::Exam;
break;
default:
std::cout << "Invalid grade type.\n";
return;
}
auto& repository = DataRepository::getInstance();
auto student = repository.getStudentByRollNumber(studentRoll);
auto course = repository.getCourseByCode(courseCode);
if (student && course) {
// Create a simple calculation strategy
auto strategy = std::make_shared<SimpleGradeCalculationStrategy>();
// Create the grade using the factory
auto grade = GradeFactory::createGrade(student, course, gradeType, gradeName, score, strategy);
// Calculate the total grade
grade->calculateTotalGrade();
// Assign the grade to the course and student
course->assignGrade(studentRoll, grade);
std::cout << "Grade assigned successfully.\n";
} else {
std::cout << "Invalid student roll number or course code.\n";
}
}
void StudentManagementSystem::viewStudentGrades() {
std::string studentRoll, courseCode;
std::cout << "Enter student roll number: ";
std::getline(std::cin, studentRoll);
std::cout << "Enter course code: ";
std::getline(std::cin, courseCode);
auto student = DataRepository::getInstance().getStudentByRollNumber(studentRoll);
if (student) {
student->viewGrades(courseCode); // This method was updated in Student.cpp
} else {
std::cout << "Student not found.\n";
}
}