uni

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

commit 23aaa0847bd8c70d343cf95e9282d53bbad499d2
parent 6adae5b189f33f5f922cba276429295de5814548
Author: Christos Margiolis <christos@margiolis.net>
Date:   Thu,  2 Apr 2020 08:44:17 +0300

improved code

Diffstat:
Massignment-2.2-classes/classes.cpp | 16+++++++++++++++-
Massignment-2.3-operoverloading/bin/operoverloading | 0
Massignment-2.3-operoverloading/obj/main.o | 0
Massignment-2.3-operoverloading/src/main.cpp | 3++-
Massignment-2.3-operoverloading/src/student.h | 1-
5 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/assignment-2.2-classes/classes.cpp b/assignment-2.2-classes/classes.cpp @@ -53,7 +53,6 @@ class Student 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 print_3first() {std::cout << AM << " " << name << " " << semester << std::endl;} char *convert_AM(const char *AM); float *convert_PSG(const float *grades); @@ -108,8 +107,15 @@ float Student::calc_average() const return average; } +inline std::ostream& operator<< (std::ostream& stream, const Student& s) +{ + return stream << "AM: " << s.get_AM() << std::endl << "Name: " << s.get_name() << std::endl + << "Semester: " << s.get_semester() << std::endl; +} + void cont(); void constructor1(const Student& s1); +void ostream_overload(const Student& s1); void constructor2(const Student& s2); void copy_constructor(const Student& copystud); void constructor3(const Student& s3); @@ -121,6 +127,7 @@ int main(int argc, char **argv) Student *s1 = new Student("12345678", "Name Surname"); system("clear"); constructor1(*s1); cont(); + ostream_overload(*s1); cont(); delete s1; Student *s2 = new Student("12345678", "Name Surname", 2); @@ -158,6 +165,13 @@ void constructor1(const Student& s1) std::cout << "s1.get_psubj(): " << s1.get_psubj() << std::endl << std::endl; } +void ostream_overload(const Student& s1) +{ + std::cout << "std::ostream overload" << std::endl; + std::cout << "----------------------------" << std::endl; + std::cout << s1 << std::endl; +} + void constructor2(const Student& s2) { std::cout << "Constructor for s2 (AM, Name, Semester)" << std::endl; 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/src/main.cpp b/assignment-2.3-operoverloading/src/main.cpp @@ -3,7 +3,8 @@ inline std::ostream& operator<< (std::ostream& stream, const Student& s) { - return stream << "AM: " << s.get_AM() << std::endl << "Name: " << s.get_name() << std::endl; + return stream << "AM: " << s.get_AM() << std::endl << "Name: " << s.get_name() << std::endl + << "Semester: " << s.get_semester() << std::endl; } void cont(); diff --git a/assignment-2.3-operoverloading/src/student.h b/assignment-2.3-operoverloading/src/student.h @@ -49,7 +49,6 @@ class Student inline void set_grades(float *grades) {this->grades = convert_PSG(grades);} inline void set_num_submitted_subjects(unsigned int numSubmittedSubjects) {this->numSubmittedSubjects = numSubmittedSubjects;} inline void set_submitted_subjects(std::string* submittedSubjects) {this->submittedSubjects = submittedSubjects;} - inline void print_3first() const {std::cout << this->AM << " " << this->name << " " << this->semester << std::endl;} char *convert_AM(const char *AM); float *convert_PSG(const float *grades);