71 lines
1.6 KiB
C++
71 lines
1.6 KiB
C++
#include "Student.hpp"
|
|
|
|
Student::Student()
|
|
: number(0), name(""), _isAnyName(true), _isAnyNumber(true){};
|
|
|
|
Student::Student(const int _number, const std::string _name)
|
|
: number(_number), name(_name), _isAnyNumber(false), _isAnyName(false){};
|
|
|
|
const int Student::getNumber() const {
|
|
return this->number;
|
|
}
|
|
|
|
const std::string Student::getNumberString() const {
|
|
if (this->_isAnyNumber) {
|
|
return "[Any]";
|
|
}
|
|
return std::to_string(this->number);
|
|
}
|
|
|
|
const std::string Student::getName() const {
|
|
if (this->_isAnyName) {
|
|
return "[Any]";
|
|
}
|
|
return this->name;
|
|
}
|
|
|
|
void Student::setNumber(const int newNumber) {
|
|
this->_isAnyNumber = false;
|
|
this->number = newNumber;
|
|
}
|
|
|
|
void Student::setName(const std::string newName) {
|
|
this->_isAnyName = false;
|
|
this->name = newName;
|
|
}
|
|
|
|
void Student::setAnyNumber() {
|
|
this->_isAnyNumber = true;
|
|
this->number = 0;
|
|
}
|
|
|
|
bool Student::isAnyNumber() const {
|
|
return this->_isAnyNumber;
|
|
}
|
|
|
|
void Student::setAnyName() {
|
|
this->_isAnyName = true;
|
|
this->name = "";
|
|
}
|
|
|
|
bool Student::isAnyName() const {
|
|
return this->_isAnyName;
|
|
}
|
|
|
|
bool Student::matchesNumber(const Student &otherStu) const {
|
|
return (this->_isAnyNumber || otherStu._isAnyNumber) ||
|
|
this->number == otherStu.number;
|
|
}
|
|
|
|
bool Student::matchesName(const Student &otherStu) const {
|
|
return (this->_isAnyName || otherStu._isAnyName) ||
|
|
this->name == otherStu.name;
|
|
}
|
|
|
|
bool Student::matches(const Student &otherStu) const {
|
|
return this->matchesNumber(otherStu) && this->matchesName(otherStu);
|
|
}
|
|
|
|
bool Student::operator==(const Student &otherStu) const {
|
|
return this->matches(otherStu);
|
|
} |