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

Commit

Permalink
Student
Browse files Browse the repository at this point in the history
  • Loading branch information
jvdcf committed Nov 3, 2023
1 parent 1e5deec commit 139ac0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
29 changes: 13 additions & 16 deletions src/Student.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
*/
#include "Student.hpp"
#include "Utils.hpp"
#include <cstdint>
#include <iterator>
#include <string>
#include <vector>
#include <iostream>
Expand All @@ -31,8 +29,7 @@ std::vector<ClassSchedule *> &Student::get_schedule() { return this->classes; }
* @brief Verifies if there are any time conflicts between the lessons of a given vector of classes.
* @details Theoretical complexity: O(n²), n being the number of lessons inside the vector.
* @param c_sched
* @param ignore_conflicts
* @return
* @return Error, Conflicts or Success
*/
OperationResult Student::is_overlapping(const std::vector<ClassSchedule *>& c_sched) {
OperationResult result = OperationResult::Success;
Expand All @@ -56,16 +53,6 @@ OperationResult Student::is_overlapping(const std::vector<ClassSchedule *>& c_sc
return result;
}

/**
* @brief Verifies if this Student is enrolled in a given class, so that it can be removed later.
* @details Theoretical complexity: O(log(n)), n being the number of classes.
* @param c
* @return bool
*/
bool Student::verify_remove(ClassSchedule* c) {
return std::binary_search(this->classes.begin(), this->classes.end(), c);
}

/**
* @brief Verifies if adding this class is legal or not.
* @details The following rules need to be followed:
Expand Down Expand Up @@ -103,6 +90,8 @@ OperationResult Student::verify_add(ClassSchedule *c) {
/**
* @brief Verifies if switching classes is legal or not.
* @details No time conflicts are allowed for both students.
* Theoretical complexity: O(n²), n being the number of lessons inside the vector.
* @return Error, Conflicts or Success
*/
OperationResult Student::verify_switch(Student& other, uint16_t uc_code) {
ClassSchedule* this_class = find_class(uc_code);
Expand All @@ -126,6 +115,7 @@ OperationResult Student::verify_switch(Student& other, uint16_t uc_code) {

/**
* @brief Add this Student to a particular class.
* @details Theoretical complexity: O(n log n), n being the number of classes.
* @param c
*/
void Student::add_to_class(ClassSchedule *c) {
Expand All @@ -137,6 +127,7 @@ void Student::add_to_class(ClassSchedule *c) {

/**
* @brief Remove this Student from a given class.
* @details Theoretical complexity: O(n), n being the number of classes.
* @param c
*/
void Student::remove_from_class(ClassSchedule *c) {
Expand All @@ -151,7 +142,8 @@ void Student::remove_from_class(ClassSchedule *c) {
}

/**
* Switch the classes of Student and other Student with a given uc_code
* @brief Switch the classes of Student and other Student with a given uc_code
* @details Theoretical complexity: O(n log n), n being the number of classes for each student.
* @param other
* @param uc_code
*/
Expand Down Expand Up @@ -188,7 +180,7 @@ uint32_t Student::get_code() const { return code; }
* @brief Find a class with a given uc_code.
* @details Theoretical complexity: O(log(n)), n being the number of classes.
* @param uc_code
* @return
* @return Pointer to the class or nullptr if not found.
*/
ClassSchedule* Student::find_class(uint16_t uc_code) {
size_t high = classes.size();
Expand All @@ -212,6 +204,11 @@ ClassSchedule* Student::find_class(uint16_t uc_code) {
*/
const std::string& Student::get_name() const {return name;}

/**
* @brief Sorts the classes vector.
* @details Order (from most important to least important): uc_code > class_code.
* Theoretical Complexity: O(n log n), n being the number of classes.
*/
void Student::sort() {
std::sort(this->classes.begin(), this->classes.end(), [](const ClassSchedule *a, const ClassSchedule *b) {
return a->get_id() < b->get_id();
Expand Down
5 changes: 1 addition & 4 deletions src/Student.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* @file Student.hpp
*/
#ifndef STUDENT_H
Expand Down Expand Up @@ -34,12 +34,9 @@ class Student {
void add_to_class(ClassSchedule* c);
OperationResult verify_add(ClassSchedule* c);
OperationResult verify_switch(Student& other, uint16_t uc_code);
bool verify_remove(ClassSchedule* c);
void remove_from_class(ClassSchedule* c);
void switch_class_with(Student& other, uint16_t uc_code);
void sort();


};


Expand Down

0 comments on commit 139ac0b

Please sign in to comment.