-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass_Timetable_Generator.Cpp.txt
More file actions
91 lines (69 loc) · 2.48 KB
/
Copy pathClass_Timetable_Generator.Cpp.txt
File metadata and controls
91 lines (69 loc) · 2.48 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
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
int days = 5;
int periods = 6;
int subjects;
cout << "===== Smart Class Timetable Generator =====" << endl;
cout << "Enter number of subjects: ";
cin >> subjects;
cin.ignore();
vector<string> subjectNames(subjects);
vector<string> facultyNames(subjects);
vector<string> roomNames(subjects);
vector<int> subjectHours(subjects);
for (int i = 0; i < subjects; i++) {
cout << "\nEnter subject name " << i + 1 << ": ";
getline(cin, subjectNames[i]);
cout << "Enter faculty name for " << subjectNames[i] << ": ";
getline(cin, facultyNames[i]);
cout << "Enter room name for " << subjectNames[i] << ": ";
getline(cin, roomNames[i]);
cout << "Enter required periods per week for " << subjectNames[i] << ": ";
cin >> subjectHours[i];
cin.ignore();
}
vector<vector<string>> timetable(days, vector<string>(periods, "Free"));
string dayNames[5] = {
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday"
};
int currentSubject = 0;
for (int i = 0; i < days; i++) {
for (int j = 0; j < periods; j++) {
if (j == 3) {
timetable[i][j] = "Lunch Break";
continue;
}
int attempts = 0;
while (attempts < subjects) {
if (subjectHours[currentSubject] > 0) {
timetable[i][j] =
subjectNames[currentSubject] + " | " +
facultyNames[currentSubject] + " | " +
roomNames[currentSubject];
subjectHours[currentSubject]--;
currentSubject = (currentSubject + 1) % subjects;
break;
}
currentSubject = (currentSubject + 1) % subjects;
attempts++;
}
}
}
cout << "\n===== Generated Smart Class Timetable =====\n" << endl;
for (int i = 0; i < days; i++) {
cout << dayNames[i] << ":" << endl;
for (int j = 0; j < periods; j++) {
cout << "Period " << j + 1 << " -> " << timetable[i][j] << endl;
}
cout << endl;
}
cout << "Timetable generated successfully using Greedy Algorithm!" << endl;
return 0;
}