uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

commit 30dec0f2579f320bc1ade02a230d1498e3de511a
parent ff36fbf8493141e157bc2467e2471cb403b5fee7
Author: Christos Margiolis <christos@margiolis.net>
Date:   Mon, 20 Apr 2020 16:34:49 +0300

removed inlines

Diffstat:
Massignment-2.2-classes/classes.cpp | 129+++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Massignment-2.3-operoverloading/bin/operoverloading | 0
Massignment-2.3-operoverloading/obj/main.o | 0
Massignment-2.3-operoverloading/obj/student.o | 0
Massignment-2.3-operoverloading/obj/subject.o | 0
Massignment-2.3-operoverloading/src/student.cpp | 96++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Massignment-2.3-operoverloading/src/student.h | 40++++++++++++++++++++--------------------
Massignment-2.3-operoverloading/src/subject.cpp | 30++++++++++++++++++++++++++++++
Massignment-2.3-operoverloading/src/subject.h | 12++++++------
9 files changed, 244 insertions(+), 63 deletions(-)

diff --git a/assignment-2.2-classes/classes.cpp b/assignment-2.2-classes/classes.cpp @@ -15,43 +15,24 @@ class Student int size; public: - Student(const char *AM, const std::string& name) - :AM(convert_AM(AM)), name(name), semester(1), psubj(0) {} - - Student(const char *AM, const std::string& name, unsigned int semester) - :AM(convert_AM(AM)), name(name), semester(semester), psubj(0) {} - + Student(const char *AM, const std::string& name); + Student(const char *AM, const std::string& name, unsigned int semester); Student(const char *AM, const std::string& name, unsigned int semester, - unsigned int psubj, const float *grades) - :AM(convert_AM(AM)), name(name), semester(semester), psubj(psubj), grades(convert_PSG(grades)) {} - - Student(const Student& s) - :name(s.name), semester(s.semester), psubj(s.psubj) - { - int sl = strlen(s.AM); - AM = new char[sl + 1]; - memcpy(AM, s.AM, sizeof(s.AM) + (sl+1)); - this->grades = new float[s.psubj]; - memcpy(grades, s.grades, sizeof(float) * s.psubj); - } - - ~Student() - { - delete[] this->AM; - delete[] this->grades; - } - - inline const char *get_AM() const {return this->AM;} - inline const std::string& get_name() const {return this->name;} - inline unsigned int get_semester() const {return this->semester;} - inline unsigned int get_psubj() const {return this->psubj;} - float *get_grades() const {return this->grades;} - - inline void set_AM(const char *AM) {this->AM = convert_AM(AM);} - inline void set_name(const std::string& name) {this->name = name;} - inline void set_semester(unsigned int semester) {this->semester = semester;} - inline void set_psubj(unsigned int psubj) {this->psubj = psubj;} - inline void set_grades(float *grades) {this->grades = convert_PSG(grades);} + unsigned int psubj, const float *grades); + Student(const Student& s); + ~Student(); + + const char *get_AM() const; + const std::string& get_name() const; + unsigned int get_semester() const; + unsigned int get_psubj() const; + float *get_grades() const; + + void set_AM(const char *AM); + void set_name(const std::string& name); + void set_semester(unsigned int semester); + void set_psubj(unsigned int psubj); + void set_grades(float *grades); char *convert_AM(const char *AM); float *convert_PSG(const float *grades); @@ -60,6 +41,82 @@ class Student float calc_average() const; }; +Student::Student(const char *AM, const std::string& name) + :AM(convert_AM(AM)), name(name), semester(1), psubj(0) {} + +Student::Student(const char *AM, const std::string& name, unsigned int semester) + :AM(convert_AM(AM)), name(name), semester(semester), psubj(0) {} + +Student::Student(const char *AM, const std::string& name, unsigned int semester, + unsigned int psubj, const float *grades) + :AM(convert_AM(AM)), name(name), semester(semester), psubj(psubj), grades(convert_PSG(grades)) {} + +Student::Student(const Student& s) + :name(s.name), semester(s.semester), psubj(s.psubj) +{ + int sl = strlen(s.AM); + AM = new char[sl + 1]; + memcpy(AM, s.AM, sizeof(s.AM) + (sl+1)); + this->grades = new float[s.psubj]; + memcpy(grades, s.grades, sizeof(float) * s.psubj); +} + +Student::~Student() +{ + delete[] this->AM; + delete[] this->grades; +} + +const char *Student::get_AM() const +{ + return this->AM; +} + +const std::string& Student::get_name() const +{ + return this->name; +} + +unsigned int Student::get_semester() const +{ + return this->semester; +} + +unsigned int Student::get_psubj() const +{ + return this->psubj; +} + +float *Student::get_grades() const +{ + return this->grades; +} + +void Student::set_AM(const char *AM) +{ + this->AM = convert_AM(AM); +} + +void Student::set_name(const std::string& name) +{ + this->name = name; +} + +void Student::set_semester(unsigned int semester) +{ + this->semester = semester; +} + +void Student::set_psubj(unsigned int psubj) +{ + this->psubj = psubj; +} + +void Student::set_grades(float *grades) +{ + this->grades = convert_PSG(grades); +} + char *Student::convert_AM(const char *AM) { int len = strlen(AM); diff --git a/assignment-2.3-operoverloading/bin/operoverloading b/assignment-2.3-operoverloading/bin/operoverloading Binary files differ. diff --git a/assignment-2.3-operoverloading/obj/main.o b/assignment-2.3-operoverloading/obj/main.o Binary files differ. diff --git a/assignment-2.3-operoverloading/obj/student.o b/assignment-2.3-operoverloading/obj/student.o Binary files differ. diff --git a/assignment-2.3-operoverloading/obj/subject.o b/assignment-2.3-operoverloading/obj/subject.o Binary files differ. diff --git a/assignment-2.3-operoverloading/src/student.cpp b/assignment-2.3-operoverloading/src/student.cpp @@ -79,9 +79,103 @@ Student Student::operator= (const Student& s) return *this; } +bool Student::operator== (const Student& s) const +{ + return this->semester == s.semester; +} + +bool Student::operator!= (const Student& s) const +{ + return this->semester != s.semester; +} + +bool Student::operator< (const Student& s) const +{ + return this->semester < s.semester; +} + +bool Student::operator<= (const Student& s) const +{ + return this->semester <= s.semester; +} + +bool Student::operator> (const Student& s) const +{ + return this->semester > s.semester; +} + +bool Student::operator>= (const Student& s) const +{ + return this->semester >= s.semester; +} + +const char *Student::get_AM() const +{ + return this->AM; +} + +const std::string& Student::get_name() const +{ + return this->name; +} + +unsigned int Student::get_semester() const +{ + return this->semester; +} + +unsigned int Student::get_psubj() const +{ + return this->psubj; +} + +float *Student::get_grades() const +{ + return (this->psubj > 0) ? this->grades : nullptr; +} + +Subject **Student::get_submitted_subjects() const +{ + return this->ssubj; +} + +unsigned int Student::get_num_submitted_subjects() const +{ + return this->nssubj; +} + +void Student::set_AM(const char *AM) +{ + this->AM = convert_AM(AM); +} + +void Student::set_name(const std::string& name) +{ + this->name = name; +} + +void Student::set_semester(unsigned int semester) +{ + this->semester = semester; +} + +void Student::set_psubj(unsigned int psubj) +{ + this->psubj = psubj; +} + +void Student::set_grades(float *grades) +{ + this->grades = convert_PSG(grades); +} + +void Student::set_num_submitted_subjects(unsigned nssubj) +{ + this->nssubj = nssubj; +} + void Student::set_submitted_subjects(Subject **ssubj) { - // handle 0 subj this->ssubj = new Subject *[nssubj]; memcpy(this->ssubj, ssubj, sizeof(Subject *) * nssubj); } diff --git a/assignment-2.3-operoverloading/src/student.h b/assignment-2.3-operoverloading/src/student.h @@ -31,29 +31,29 @@ class Student void operator+= (Subject *s); Student operator= (const Student& s); - inline bool operator== (const Student& s) const {return (this->semester == s.semester) ? true : false;} - inline bool operator!= (const Student& s) const {return (this->semester != s.semester) ? true : false;} - inline bool operator< (const Student& s) const {return (this->semester < s.semester) ? true : false;} - inline bool operator<= (const Student& s) const {return (this->semester <= s.semester) ? true : false;} - inline bool operator> (const Student& s) const {return (this->semester > s.semester) ? true : false;} - inline bool operator>= (const Student& s) const {return (this->semester >= s.semester) ? true : false;} + bool operator== (const Student& s) const; + bool operator!= (const Student& s) const; + bool operator< (const Student& s) const; + bool operator<= (const Student& s) const; + bool operator> (const Student& s) const; + bool operator>= (const Student& s) const; - inline const char *get_AM(void) const {return this->AM;} - inline const std::string& get_name(void) const {return this->name;} - inline unsigned int get_semester(void) const {return this->semester;} - inline unsigned int get_psubj(void) const {return this->psubj;} - inline float *get_grades(void) const {return (this->psubj > 0) ? this->grades : nullptr;} - inline Subject **get_submitted_subjects(void) const {return this->ssubj;} - inline unsigned int get_num_submitted_subjects(void) const {return this->nssubj;} - - inline void set_AM(const char *AM) {this->AM = convert_AM(AM);} - inline void set_name(const std::string& name) {this->name = name;} - inline void set_semester(unsigned int semester) {this->semester = semester;} - inline void set_psubj(unsigned int psubj) {this->psubj = psubj;} - inline void set_grades(float *grades) {this->grades = convert_PSG(grades);} - inline void set_num_submitted_subjects(unsigned int nssubj) {this->nssubj = nssubj;} + const char *get_AM() const; + const std::string& get_name() const; + unsigned int get_semester() const; + unsigned int get_psubj() const; + float *get_grades() const; + Subject **get_submitted_subjects() const; + unsigned int get_num_submitted_subjects() const; + void set_AM(const char *AM); + void set_name(const std::string& name); + void set_semester(unsigned int semester); + void set_psubj(unsigned int psubj); + void set_grades(float *grades); + void set_num_submitted_subjects(unsigned int nssubj); void set_submitted_subjects(Subject **ssubj); + char *convert_AM(const char *AM); float *convert_PSG(const float *grades); void add_grade(float grade); diff --git a/assignment-2.3-operoverloading/src/subject.cpp b/assignment-2.3-operoverloading/src/subject.cpp @@ -8,3 +8,33 @@ Subject::Subject(const std::string& code, const std::string& sname, unsigned int Subject::Subject(const Subject& s) :code(s.code), sname(s.sname), subjsemester(s.subjsemester) {} + +const std::string& Subject::get_code() const +{ + return this->code; +} + +const std::string& Subject::get_sname() const +{ + return this->sname; +} + +unsigned int Subject::get_subjsemester() const +{ + return this->subjsemester; +} + +void Subject::set_code(const std::string& code) +{ + this->code = code; +} + +void Subject::set_sname(const std::string& sname) +{ + this->sname = sname; +} + +void Subject::set_subjsemester(unsigned int subjsemester) +{ + this->subjsemester = subjsemester; +} diff --git a/assignment-2.3-operoverloading/src/subject.h b/assignment-2.3-operoverloading/src/subject.h @@ -16,13 +16,13 @@ class Subject Subject(const std::string& code, const std::string& sname, unsigned int subjsemester); Subject(const Subject& s); - inline const std::string& get_code(void) const {return this->code;} - inline const std::string& get_sname(void) const {return this->sname;} - inline unsigned int get_subjsemester(void) const {return this->subjsemester;} + const std::string& get_code() const; + const std::string& get_sname() const; + unsigned int get_subjsemester() const; - inline void set_code(const std::string& code) {this->code = code;} - inline void set_sname(const std::string& sname) {this->sname = sname;} - inline void set_subjsemester(unsigned int subjsemester) {this->subjsemester = subjsemester;} + void set_code(const std::string& code); + void set_sname(const std::string& sname); + void set_subjsemester(unsigned int subjsemester); }; #endif /* SUBJECT_H */