uni

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

commit b7a1771f667b398482277888a0b259b436e1032b
parent 4e70607607e0d1fa945314c0f26f1e099a6211aa
Author: Christos Margiolis <christos@margiolis.net>
Date:   Thu,  2 Apr 2020 20:00:13 +0300

changed some cout msgs

Diffstat:
Massignment-2.2-classes/classes.cpp | 60+++++++++++++++++++++++++++++++-----------------------------
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/src/main.cpp | 75+++++++++++++++++++++++++++++++++++----------------------------------------
Massignment-2.3-operoverloading/src/student.cpp | 12++++++------
Massignment-2.3-operoverloading/src/student.h | 2+-
7 files changed, 73 insertions(+), 76 deletions(-)

diff --git a/assignment-2.2-classes/classes.cpp b/assignment-2.2-classes/classes.cpp @@ -42,6 +42,8 @@ class Student delete[] this->grades; } + friend std::ostream& operator<< (std::ostream& stream, const Student& s); + inline const char *get_AM() const {return AM;} inline const std::string& get_name() const {return name;} inline unsigned int get_semester() const {return semester;} @@ -138,7 +140,7 @@ int main(int argc, char **argv) ostream_overload(*s1); cont(); delete s1; - Student *s2 = new Student("12345678", "Name Surname", 2); + Student *s2 = new Student("92345678", "Name Surname", 2); constructor2(*s2); cont(); Student *copystud = new Student(*s2); @@ -147,7 +149,7 @@ int main(int argc, char **argv) delete s2; float grd[4] = {9.4f, 8.4f, 5.5f, 6.3f}; - Student *s3 = new Student("12345678", "Name Surname", 2, 4, grd); + Student *s3 = new Student("72345678", "Name Surname", 2, 4, grd); constructor3(*s3); cont(); detprint(*s3); cont(); setters(*s3); @@ -168,10 +170,10 @@ void constructor1(const Student& s1) { std::cout << "Constructor for s1 (AM, Name)" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "s1.get_AM(): " << s1.get_AM() << std::endl; - std::cout << "s1.get_name(): " << s1.get_name() << std::endl; - std::cout << "s1.get_semester(): " << s1.get_semester() << std::endl; - std::cout << "s1.get_psubj(): " << s1.get_psubj() << std::endl << std::endl; + std::cout << "AM: " << s1.get_AM() << std::endl; + std::cout << "Name: " << s1.get_name() << std::endl; + std::cout << "Semester (default value): " << s1.get_semester() << std::endl; + std::cout << "Subjects passed (default value): " << s1.get_psubj() << std::endl << std::endl; } void ostream_overload(const Student& s1) @@ -185,38 +187,40 @@ void constructor2(const Student& s2) { std::cout << "Constructor for s2 (AM, Name, Semester)" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "s2.get_AM(): " << s2.get_AM() << std::endl; - std::cout << "s2.get_name(): " << s2.get_name() << std::endl; - std::cout << "s2.get_semester(): " << s2.get_semester() << std::endl; - std::cout << "s2.get_psubj(): " << s2.get_psubj() << std::endl << std::endl; + std::cout << "AM: " << s2.get_AM() << std::endl; + std::cout << "Name: " << s2.get_name() << std::endl; + std::cout << "Semester: " << s2.get_semester() << std::endl; + std::cout << "Subjects passed (default value): " << s2.get_psubj() << std::endl << std::endl; } void copy_constructor(const Student& copystud) { std::cout << "Copy Constructor using copystud object as a copy of s2" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "copystud.get_AM(): " << copystud.get_AM() << std::endl; - std::cout << "copystud.get_name(): " << copystud.get_name() << std::endl; - std::cout << "copystud.get_semester(): " << copystud.get_semester() << std::endl; - std::cout << "copystud.get_psubj(): " << copystud.get_psubj() << std::endl << std::endl; + std::cout << "AM: " << copystud.get_AM() << std::endl; + std::cout << "Name: " << copystud.get_name() << std::endl; + std::cout << "Semester: " << copystud.get_semester() << std::endl; + std::cout << "Subjects passed (default value): " << copystud.get_psubj() << std::endl << std::endl; } void constructor3(const Student& s3) { std::cout << "Constructor for s3 (AM, Name, Semester, Subjects Passed, Grades)" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "s3.get_AM(): " << s3.get_AM() << std::endl; - std::cout << "s3.get_name(): " << s3.get_name() << std::endl; - std::cout << "s3.get_semester(): " << s3.get_semester() << std::endl; - std::cout << "s3.get_psubj(): " << s3.get_psubj() << std::endl; + std::cout << "AM: " << s3.get_AM() << std::endl; + std::cout << "Name: " << s3.get_name() << std::endl; + std::cout << "Semester: " << s3.get_semester() << std::endl; + std::cout << "Subjects passed: " << s3.get_psubj() << std::endl; - float *gr = s3.get_grades(); - std::cout << "s3.get_grades(): "; + float *gr = new float[s3.get_psubj()]; + gr = s3.get_grades(); + std::cout << "Grades: "; for (unsigned int i = 0; i < s3.get_psubj(); i++) { if (i != s3.get_psubj()-1) std::cout << gr[i] << ", "; else std::cout << gr[i] << std::endl << std::endl; } + delete[] gr; } void detprint (const Student& s3) @@ -238,24 +242,23 @@ void setters(Student& s3) std::cout << "Setters example using s3" << std::endl; std::cout << "----------------------------" << std::endl; std::cout << "Input: s3.set_AM(\"01010101\")" << '\t'; - std::cout << "Output: s3.get_AM(): " << s3.get_AM() << std::endl; + std::cout << "New AM: " << s3.get_AM() << std::endl; std::cout << "Input: s3.set_name(\"AAAAAAA\")" << '\t'; - std::cout << "Output: s3.get_name(): " << s3.get_name() << std::endl; + std::cout << "New name: " << s3.get_name() << std::endl; std::cout << "Input: s3.set_semester(100):" << '\t'; - std::cout << "Output: s3.get_semester(): " << s3.get_semester() << std::endl; - std::cout << "Input: s3.set_psubj(2):" << '\t'; - std::cout << "Output: s3.get_psubj(): " << s3.get_psubj() << std::endl; + std::cout << "New semester: " << s3.get_semester() << std::endl; + std::cout << "Input: s3.set_psubj(2):" << '\t' << '\t'; + std::cout << "New subjects passed: " << s3.get_psubj() << std::endl; float *gr = new float[s3.get_psubj()]; gr = s3.get_grades(); std::cout << "Input: {0.1f, 2.2f}" << '\t' << '\t'; - std::cout << "Output: s3.get_grades(): "; + std::cout << "New grades: "; for (unsigned int i = 0; i < s3.get_psubj(); i++) { if (i != s3.get_psubj()-1) std::cout << gr[i] << ", "; else std::cout << gr[i] << std::endl; } - delete[] gr; } @@ -265,12 +268,11 @@ void addgrd(Student& s3) float *gr = new float[s3.get_psubj()]; gr = s3.get_grades(); std::cout << "Input: s3.add_grade(7.5f)" << '\t'; - std::cout << "Output: s3.get_grades(): "; + std::cout << "Updated grades: "; for (unsigned int i = 0; i < s3.get_psubj(); i++) { if (i != s3.get_psubj()-1) std::cout << gr[i] << ", "; else std::cout << gr[i] << std::endl; } - delete[] gr; } 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/src/main.cpp b/assignment-2.3-operoverloading/src/main.cpp @@ -23,7 +23,6 @@ void equals_overload(Student& s3); void getters(const Subject& s3); void setters(Subject& sb); - int main(int argc, char **argv) { Student *s1 = new Student("12345678", "Name Surname"); @@ -31,7 +30,7 @@ int main(int argc, char **argv) constructor1(*s1); cont(); ostream_overload(*s1); cont(); - Student *s2 = new Student("12345678", "Name Surname", 2); + Student *s2 = new Student("92345678", "Name Surname", 2); constructor2(*s2); cont(); Student *copystud = new Student(*s2); @@ -42,7 +41,7 @@ int main(int argc, char **argv) delete s2; float grd[4] = {9.4f, 8.4f, 5.5f, 6.3f}; - Student *s3 = new Student("12345678", "Name Surname", 2, 4, grd); + Student *s3 = new Student("72345678", "Name Surname", 2, 4, grd); constructor3(*s3); cont(); detprint(*s3); cont(); setters(*s3); @@ -71,10 +70,10 @@ void constructor1(const Student& s1) { std::cout << "Constructor for s1 (AM, Name)" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "s1.get_AM(): " << s1.get_AM() << std::endl; - std::cout << "s1.get_name(): " << s1.get_name() << std::endl; - std::cout << "s1.get_semester(): " << s1.get_semester() << std::endl; - std::cout << "s1.get_psubj(): " << s1.get_psubj() << std::endl << std::endl; + std::cout << "AM: " << s1.get_AM() << std::endl; + std::cout << "Name: " << s1.get_name() << std::endl; + std::cout << "Semester (default value): " << s1.get_semester() << std::endl; + std::cout << "Subjects passed (default value): " << s1.get_psubj() << std::endl << std::endl; } void ostream_overload(const Student& s1) @@ -88,20 +87,20 @@ void constructor2(const Student& s2) { std::cout << "Constructor for s2 (AM, Name, Semester)" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "s2.get_AM(): " << s2.get_AM() << std::endl; - std::cout << "s2.get_name(): " << s2.get_name() << std::endl; - std::cout << "s2.get_semester(): " << s2.get_semester() << std::endl; - std::cout << "s2.get_psubj(): " << s2.get_psubj() << std::endl << std::endl; + std::cout << "AM: " << s2.get_AM() << std::endl; + std::cout << "Name: " << s2.get_name() << std::endl; + std::cout << "Semester: " << s2.get_semester() << std::endl; + std::cout << "Subjects passed (default value): " << s2.get_psubj() << std::endl << std::endl; } void copy_constructor(const Student& copystud) { std::cout << "Copy Constructor using copystud object as a copy of s2" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "copystud.get_AM(): " << copystud.get_AM() << std::endl; - std::cout << "copystud.get_name(): " << copystud.get_name() << std::endl; - std::cout << "copystud.get_semester(): " << copystud.get_semester() << std::endl; - std::cout << "copystud.get_psubj(): " << copystud.get_psubj() << std::endl << std::endl; + std::cout << "AM: " << copystud.get_AM() << std::endl; + std::cout << "Name: " << copystud.get_name() << std::endl; + std::cout << "Semester: " << copystud.get_semester() << std::endl; + std::cout << "Subjects passed (default value): " << copystud.get_psubj() << std::endl << std::endl; } void conditional_overload(const Student& s1, const Student& s2, const Student& copystud) @@ -121,14 +120,14 @@ void constructor3(const Student& s3) { std::cout << "Constructor for s3 (AM, Name, Semester, Subjects Passed, Grades)" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "s3.get_AM(): " << s3.get_AM() << std::endl; - std::cout << "s3.get_name(): " << s3.get_name() << std::endl; - std::cout << "s3.get_semester(): " << s3.get_semester() << std::endl; - std::cout << "s3.get_psubj(): " << s3.get_psubj() << std::endl; + std::cout << "AM: " << s3.get_AM() << std::endl; + std::cout << "Name: " << s3.get_name() << std::endl; + std::cout << "Semester: " << s3.get_semester() << std::endl; + std::cout << "Subjects passed: " << s3.get_psubj() << std::endl; float *gr = new float[s3.get_psubj()]; gr = s3.get_grades(); - std::cout << "s3.get_grades(): "; + std::cout << "Grades: "; for (unsigned int i = 0; i < s3.get_psubj(); i++) { if (i != s3.get_psubj()-1) std::cout << gr[i] << ", "; @@ -156,24 +155,23 @@ void setters(Student& s3) std::cout << "Setters example using s3" << std::endl; std::cout << "----------------------------" << std::endl; std::cout << "Input: s3.set_AM(\"01010101\")" << '\t'; - std::cout << "Output: s3.get_AM(): " << s3.get_AM() << std::endl; + std::cout << "New AM: " << s3.get_AM() << std::endl; std::cout << "Input: s3.set_name(\"AAAAAAA\")" << '\t'; - std::cout << "Output: s3.get_name(): " << s3.get_name() << std::endl; + std::cout << "New name: " << s3.get_name() << std::endl; std::cout << "Input: s3.set_semester(100):" << '\t'; - std::cout << "Output: s3.get_semester(): " << s3.get_semester() << std::endl; - std::cout << "Input: s3.set_psubj(2):" << '\t'; - std::cout << "Output: s3.get_psubj(): " << s3.get_psubj() << std::endl; + std::cout << "New semester: " << s3.get_semester() << std::endl; + std::cout << "Input: s3.set_psubj(2):" << '\t' << '\t'; + std::cout << "New subjects passed: " << s3.get_psubj() << std::endl; float *gr = new float[s3.get_psubj()]; gr = s3.get_grades(); std::cout << "Input: {0.1f, 2.2f}" << '\t' << '\t'; - std::cout << "Output: s3.get_grades(): "; + std::cout << "New grades: "; for (unsigned int i = 0; i < s3.get_psubj(); i++) { if (i != s3.get_psubj()-1) std::cout << gr[i] << ", "; else std::cout << gr[i] << std::endl; } - delete[] gr; } @@ -183,13 +181,12 @@ void addgrd(Student& s3) float *gr = new float[s3.get_psubj()]; gr = s3.get_grades(); std::cout << "Input: s3.add_grade(7.5f)" << '\t'; - std::cout << "Output: s3.get_grades(): "; + std::cout << "Updated grades: "; for (unsigned int i = 0; i < s3.get_psubj(); i++) { if (i != s3.get_psubj()-1) std::cout << gr[i] << ", "; else std::cout << gr[i] << std::endl; } - delete[] gr; } @@ -202,18 +199,17 @@ void submsubj(Student& s3) std::cout << "Submitted subjects example" << std::endl; std::cout << "----------------------------" << std::endl; std::cout << "Input: s3.set_num_submitted_subjects(3)" << std::endl;; - std::cout << "Output: s3.get_num_submitted_subjects(): " << s3.get_num_submitted_subjects() << std::endl << std::endl; + std::cout << "Number of submitted subjects: " << s3.get_num_submitted_subjects() << std::endl << std::endl; std::string *ssj = new std::string[s3.get_num_submitted_subjects()]; ssj = s3.get_submitted_subjects(); std::cout << "Input: {\"Math\", \"Physics\", \"Programming\"}" << std::endl;; - std::cout << "Output: s3.get_submitted_subjects(): "; + std::cout << "Submitted subjects: "; for (unsigned int i = 0; i < s3.get_num_submitted_subjects(); i++) { if (i != s3.get_num_submitted_subjects()-1) std::cout << ssj[i] << ", "; else std::cout << ssj[i] << std::endl; } - delete[] ssj; } @@ -225,13 +221,12 @@ void plusequals_overload(Student& s3) std::cout << "+= operator overload" << std::endl; std::cout << "----------------------------" << std::endl; std::cout << "Input: s3 += \"Discrete Maths\"" << std::endl;; - std::cout << "Output: s3.get_submitted_subjects(): "; + std::cout << "Updated submitted subjects: "; for (unsigned int i = 0; i < s3.get_num_submitted_subjects(); i++) { if (i != s3.get_num_submitted_subjects()-1) std::cout << ssj[i] << ", "; else std::cout << ssj[i] << std::endl; } - delete[] ssj; } @@ -245,9 +240,9 @@ void getters(const Subject& sb) std::cout << "Getters example using Subject object" << std::endl; std::cout << "----------------------------" << std::endl; std::cout << "Constructor: Subject(\"35643\", \"OOP\", 2)" << std::endl; - std::cout << "sb.get_code(): " << sb.get_code() << std::endl; - std::cout << "sb.get_sname(): " << sb.get_sname() << std::endl; - std::cout << "sb.get_subjsemester(): " << sb.get_subjsemester() << std::endl; + std::cout << "Code: " << sb.get_code() << std::endl; + std::cout << "Subject name: " << sb.get_sname() << std::endl; + std::cout << "Subject semester: " << sb.get_subjsemester() << std::endl; } void setters(Subject& sb) @@ -259,9 +254,9 @@ void setters(Subject& sb) std::cout << "Setters example using Subject object" << std::endl; std::cout << "----------------------------" << std::endl; std::cout << "Input: sb.set_code(\"14556\")" << '\t' << '\t'; - std::cout << "Output: sb.get_code(): " << sb.get_code() << std::endl; + std::cout << "New code: " << sb.get_code() << std::endl; std::cout << "Input: sb.set_sname(\"Calculus I\")" << '\t'; - std::cout << "Output: sb.get_sname(): " << sb.get_sname() << std::endl; + std::cout << "New subject name: " << sb.get_sname() << std::endl; std::cout << "Input: sb.set_subjsemester(1):" << '\t' << '\t'; - std::cout << "Output: sb.get_subjsemester(): " << sb.get_subjsemester() << std::endl; + std::cout << "New subject semester: " << sb.get_subjsemester() << std::endl; } diff --git a/assignment-2.3-operoverloading/src/student.cpp b/assignment-2.3-operoverloading/src/student.cpp @@ -47,12 +47,6 @@ float *Student::get_grades() const return ret; } -void Student::set_submitted_subjects(std::string* submittedSubjects) -{ - this->submittedSubjects = new std::string[numSubmittedSubjects]; - std::copy(submittedSubjects, submittedSubjects+numSubmittedSubjects, this->submittedSubjects); -} - std::string *Student::get_submitted_subjects() const { std::string *ret = new std::string[numSubmittedSubjects]; @@ -60,6 +54,12 @@ std::string *Student::get_submitted_subjects() const return ret; } +void Student::set_submitted_subjects(std::string* submittedSubjects) +{ + this->submittedSubjects = new std::string[numSubmittedSubjects]; + std::copy(submittedSubjects, submittedSubjects+numSubmittedSubjects, this->submittedSubjects); +} + char *Student::convert_AM(const char *AM) { int len = strlen(AM); diff --git a/assignment-2.3-operoverloading/src/student.h b/assignment-2.3-operoverloading/src/student.h @@ -24,8 +24,8 @@ class Student Student(const Student& s); ~Student(); + friend std::ostream& operator<< (std::ostream& stream, const Student& s); void operator+= (const std::string& s); - // = overload 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;}