Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit e06ef6e

Browse files
Adding the structure of Student and introducing the OperationResult enum
1 parent 4d66e1b commit e06ef6e

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

src/Student.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include "Student.hpp"
2+
#include "Utils.hpp"
3+
#include <cstdint>
4+
#include <string>
5+
#include <vector>
6+
7+
Student::Student(uint32_t code, std::string name) {
8+
this->code = code;
9+
this->name = name;
10+
this->classes = std::vector<ClassSchedule *>();
11+
}
12+
13+
std::vector<ClassSchedule *> *Student::get_schedule() { return &this->classes; }
14+
15+
OperationResult Student::add_to_class(ClassSchedule *c) {
16+
std::vector<Class *> *new_lessons = c->get_class_schedule();
17+
// return false;
18+
for (ClassSchedule *a : this->classes) {
19+
std::vector<Class *> *lessons = a->get_class_schedule();
20+
for (Class *lesson : *lessons) {
21+
for (Class *new_lesson : *new_lessons) {
22+
if (lesson->get_start_hour() < new_lesson->get_start_hour() &&
23+
new_lesson->get_start_hour() <
24+
(lesson->get_start_hour() + lesson->get_duration())) {
25+
if (lesson->get_type() == Type::T ||
26+
new_lesson->get_type() == Type::T) {
27+
return OperationResult::Conlicts; // We return conflicts so that the
28+
// handler function can ask the
29+
// user whether or not they want
30+
// to proceed.
31+
}
32+
return OperationResult::Error;
33+
}
34+
if (lesson->get_start_hour() <
35+
(new_lesson->get_start_hour() + new_lesson->get_duration()) &&
36+
(new_lesson->get_start_hour() + new_lesson->get_duration()) <
37+
(lesson->get_start_hour() + lesson->get_duration())) {
38+
if (lesson->get_type() == Type::T ||
39+
new_lesson->get_type() == Type::T) {
40+
return OperationResult::Conlicts;
41+
}
42+
return OperationResult::Error;
43+
}
44+
}
45+
}
46+
}
47+
c->add_student();
48+
this->classes.push_back(c);
49+
return OperationResult::Success;
50+
}
51+
52+
void Student::remove_from_class(ClassSchedule *c) {
53+
c->remove_student();
54+
for (std::vector<ClassSchedule*>::iterator itr = this->classes.begin(); itr != this->classes.end(); ++itr) {
55+
if (c == *itr) {
56+
this->classes.erase(itr);
57+
return;
58+
}
59+
}
60+
this->classes.push_back(c);
61+
}
62+
63+
OperationResult Student::switch_class_with(Student other, ClassSchedule *thisone,
64+
ClassSchedule *theoother) {
65+
return OperationResult::Success; //TODO
66+
}

src/Student.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <cstdint>
2+
#include "ClassSchedule.hpp"
3+
#include "Utils.hpp"
4+
#include <string>
5+
6+
class Student {
7+
private:
8+
uint32_t code;
9+
std::string name;
10+
std::vector<ClassSchedule*> classes;
11+
public:
12+
Student(uint32_t code, std::string name);
13+
std::vector<ClassSchedule*>* get_schedule();
14+
OperationResult add_to_class(ClassSchedule* c);
15+
void remove_from_class(ClassSchedule* c);
16+
OperationResult switch_class_with(Student other, ClassSchedule* thisone, ClassSchedule* theother);
17+
};

src/Utils.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@
99
uint8_t hash_str(std::string s);
1010
bool isnum(uint32_t c);
1111
void parse_csv_line(std::string s, std::vector<std::string> &res);
12+
13+
enum class OperationResult {
14+
Success,
15+
Conlicts,
16+
Error,
17+
};
18+
1219
#endif // !UTILS_HPP

0 commit comments

Comments
 (0)