-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.cpp
More file actions
108 lines (96 loc) · 2.66 KB
/
Copy pathclasses.cpp
File metadata and controls
108 lines (96 loc) · 2.66 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
#include <iostream>
#include <cstdio>
using namespace std;
class session_class {
private:
string day; // e.g. "Thursday"
int hour; // 11 = 11am, 13 = 1pm, etc
string room; // e.g. "SNW300"
public:
void loaddata();
bool sametime(session_class other);
};
class course_class {
private:
int code; // e.g. 159101
bool core; // true if a core course, otherwise false
// only one session - maybe there should be more sessions?
session_class session;
public:
void loaddata();
int getcode() {return code;}
bool sametime(course_class other);
};
class student_class {
private:
string name; // name of the student_class
int num; // number of course_class
course_class courses[30];
public:
void loadname();
void loadcourses();
void checkclashes();
};
//assume one student for now - then modify for many students
student_class student;
int main() {
cout << "Check a student timetable for clashes\n";
student.loadname();
student.loadcourses();
cout << "\n This student has the following clashes\n";
student.checkclashes();
}
//------------METHODS FOR THE session_class -----------------
void session_class::loaddata() {
cout << "Enter the day: ";
cin >> day;
cout << "Enter the hour(e.g. 11 = 11am and 13 = 1pm): ";
cin >> hour;
}
bool session_class::sametime(session_class other) {
if((day == other.day) && (hour == other.hour)){
return true;
}
return false;
}
//-----------METHODS FOR THE course_class ----------------
void course_class::loaddata() {
cout << "Enter the course code: ";
cin >> code;
session.loaddata();
}
bool course_class::sametime(course_class other) {
// return true if both courses have a session at the same time
if(session.sametime(other.session) == true) {
return true;
}
return false;
}
//------------METHODS FOR THE student_class --------------
void student_class::loadname() {
cout << "Enter name of student ";
getline(cin, name);
}
void student_class::loadcourses() {
int i;
cout << "How many courses is this student doing? ";
cin >> num;
getchar(); // flush the input buffer
for(i=0;i<num;i++){
courses[i].loaddata();
}
}
void student_class::checkclashes() {
// check for timetable clashes across the courses
// WARNING -- this method could be improved
int code1, code2, i, k;
for(i = 0; i < num; i++){
for(k = 0; k < num; k++) {
if(courses[i].sametime(courses[k]) == true){
code1 = courses[i].getcode();
code2 = courses[k].getcode();
cout << "Clash - " << code1 << " against " << code2 << endl;
}
}
}
}