commit 3c3207b3691ebe7d36effb318c42fe7418d00d8f parent 24e3f432004425f5e8be6f3e4f10ceaff9355205 Author: Christos Margiolis <christos@margiolis.net> Date: Tue, 5 May 2020 00:38:53 +0300 changed subject to course Diffstat:
20 files changed, 270 insertions(+), 236 deletions(-)
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/course.o b/assignment-2.3-operoverloading/obj/course.o 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/course.cpp b/assignment-2.3-operoverloading/src/course.cpp @@ -0,0 +1,40 @@ +#include "course.h" + + +Course::Course() {} + +Course::Course(const std::string& code, const std::string& cname, unsigned int csemester) + :code(code), cname(cname), csemester(csemester) {} + +Course::Course(const Course& c) + :code(c.code), cname(c.cname), csemester(c.csemester) {} + +const std::string& Course::get_code() const +{ + return this->code; +} + +const std::string& Course::get_cname() const +{ + return this->cname; +} + +unsigned int Course::get_csemester() const +{ + return this->csemester; +} + +void Course::set_code(const std::string& code) +{ + this->code = code; +} + +void Course::set_cname(const std::string& cname) +{ + this->cname = cname; +} + +void Course::set_csemester(unsigned int csemester) +{ + this->csemester = csemester; +} diff --git a/assignment-2.3-operoverloading/src/course.h b/assignment-2.3-operoverloading/src/course.h @@ -0,0 +1,28 @@ +#ifndef COURSE_H +#define COURSE_H + +#include <iostream> +#include <string> + +class Course +{ + private: + std::string code; // Course code + std::string cname; // Course name + unsigned int csemester; // Corresponding semester of course + + public: + Course(); + Course(const std::string& code, const std::string& cname, unsigned int csemester); + Course(const Course& s); + + const std::string& get_code() const; + const std::string& get_cname() const; + unsigned int get_csemester() const; + + void set_code(const std::string& code); + void set_cname(const std::string& cname); + void set_csemester(unsigned int csemester); +}; + +#endif /* COURSE_H */ diff --git a/assignment-2.3-operoverloading/src/main.cpp b/assignment-2.3-operoverloading/src/main.cpp @@ -1,11 +1,12 @@ #include "student.h" -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; -} +const int W_AM = 15; +const int W_NAME = 20; +const int W_SEM = 10; +const int W_PC = 20; +const int W_GRADES = 15; +std::ostream& operator<< (std::ostream& stream, const Student& s); static void cont(void); static void constructor1(const Student& s1); static void ostream_overload(const Student& s1); @@ -17,10 +18,10 @@ static void constructor3(const Student& s3); static void detprint (const Student& s3); static void setters(Student& s3); static void addgrd(Student& s3); -static void submsubj(Student& s3); -static void plusequals_overload(Student& s3, Subject *s); -static void getters(const Subject& s3); -static void setters(Subject& sb); +static void submcourses(Student& s3); +static void plusequals_overload(Student& s3, Course *c); +static void getters(const Course& s3); +static void setters(Course& c); int main(int argc, char **argv) { @@ -51,12 +52,12 @@ int main(int argc, char **argv) detprint(*s3); cont(); setters(*s3); addgrd(*s3); cont(); - submsubj(*s3); cont(); + submcourses(*s3); cont(); Student *s4 = new Student(*s3); std::string c = "356431"; std::string n = "OOP"; - Subject *oop = new Subject(c, n, 2); + Course *oop = new Course(c, n, 2); plusequals_overload(*s3, oop); cont(); getters(*oop); cont(); @@ -69,6 +70,14 @@ int main(int argc, char **argv) return 0; } +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(); +} + static void cont(void) { std::cout << std::endl; @@ -83,7 +92,7 @@ static void constructor1(const Student& s1) 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; + std::cout << "Courses passed (default value): " << s1.get_pcourses() << std::endl; } static void ostream_overload(const Student& s1) @@ -100,7 +109,7 @@ static void constructor2(const Student& s2) 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; + std::cout << "Courses passed (default value): " << s2.get_pcourses() << std::endl; } static void copy_constructor(const Student& copystud) @@ -110,7 +119,7 @@ static void copy_constructor(const Student& copystud) 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; + std::cout << "Courses passed (default value): " << copystud.get_pcourses() << std::endl; } static void conditional_overload(const Student& s1, const Student& s2, const Student& copystud) @@ -129,31 +138,31 @@ static void conditional_overload(const Student& s1, const Student& s2, const Stu static void equals_overload(const Student& s1, Student& s2) { s2 = s1; - std::cout << "= operator overload using s2 = s1" << std::endl; + std::cout << "= operator overload (s2 = s1)" << std::endl; std::cout << "----------------------------" << 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; + std::cout << "Courses passed (default value): " << s2.get_pcourses() << std::endl; } static void constructor3(const Student& s3) { - std::cout << "Constructor for s3 (AM, Name, Semester, Subjects passed, Grades)" << std::endl; + std::cout << "Constructor for s3 (AM, Name, Semester, Courses passed, Grades)" << std::endl; std::cout << "----------------------------" << 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; + std::cout << "Courses passed: " << s3.get_pcourses() << std::endl; + std::cout << "Grades: "; float *gr = s3.get_grades(); if (gr != nullptr) { - std::cout << "Grades: "; - for (unsigned int i = 0; i < s3.get_psubj(); i++) + for (unsigned int i = 0; i < s3.get_pcourses(); i++) { - if (i != s3.get_psubj()-1) std::cout << gr[i] << ", "; - else std::cout << gr[i] << std::endl << std::endl; + if (i != s3.get_pcourses()-1) std::cout << gr[i] << ", "; + else std::cout << gr[i] << std::endl; } } } @@ -167,34 +176,38 @@ static void detprint (const Student& s3) static void setters(Student& s3) { - s3.set_AM("01010101"); - s3.set_name("AAAAAAA"); + s3.set_AM("010101"); + s3.set_name("AAAA"); s3.set_semester(100); - s3.set_psubj(2); // πρώτα η set_psubj() και μετα η set_grades() !!!!! + s3.set_pcourses(2); float *gg = new float[2]{0.1f, 2.2f}; s3.set_grades(gg); delete[] gg; std::cout << "Setters example using s3" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "Input: s3.set_AM(\"01010101\")" << '\t'; + std::cout << "Input: 010101 " << std::endl; std::cout << "New AM: " << s3.get_AM() << std::endl; - std::cout << "Input: s3.set_name(\"AAAAAAA\")" << '\t'; + std::cout << std::endl; + std::cout << "Input: AAAA " << std::endl; std::cout << "New name: " << s3.get_name() << std::endl; - std::cout << "Input: s3.set_semester(100):" << '\t'; + std::cout << std::endl; + std::cout << "Input: 100" << 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; + std::cout << std::endl; + std::cout << "Input: 2" << std::endl; + std::cout << "New courses passed: " << s3.get_pcourses() << std::endl; + std::cout << std::endl; + std::cout << "Input: 0.1, 2.2" << std::endl; + std::cout << "New grades: "; float *gr = s3.get_grades(); if (gr != nullptr) { - std::cout << "Input: {0.1f, 2.2f}" << '\t' << '\t'; - std::cout << "New grades: "; - for (unsigned int i = 0; i < s3.get_psubj(); i++) + for (unsigned int i = 0; i < s3.get_pcourses(); i++) { - if (i != s3.get_psubj()-1) std::cout << gr[i] << ", "; - else std::cout << gr[i] << std::endl; + if (i != s3.get_pcourses()-1) std::cout << gr[i] << ", "; + else std::cout << gr[i] << std::endl << std::endl; } } } @@ -205,90 +218,93 @@ static void addgrd(Student& s3) float *gr = s3.get_grades(); if (gr != nullptr) { - std::cout << "Input: s3.add_grade(7.5f)" << '\t'; - std::cout << "Updated grades: "; - for (unsigned int i = 0; i < s3.get_psubj(); i++) + std::cout << "Input: 7.5" << std::endl; + std::cout << "Updated new grades: "; + for (unsigned int i = 0; i < s3.get_pcourses(); i++) { - if (i != s3.get_psubj()-1) std::cout << gr[i] << ", "; + if (i != s3.get_pcourses()-1) std::cout << gr[i] << ", "; else std::cout << gr[i] << std::endl; } } } -static void submsubj(Student& s3) +static void submcourses(Student& s3) { std::string c1 = "11231"; std::string c2 = "56562"; std::string n1 = "Discrete Math"; std::string n2 = "Physics"; - Subject *a = new Subject(c1, n1, 1); - Subject *b = new Subject(c2, n2, 1); - Subject **sb = new Subject *[2]{a, b}; - s3.set_num_submitted_subjects(2); - s3.set_submitted_subjects(sb); + Course *a = new Course(c1, n1, 1); + Course *b = new Course(c2, n2, 1); + Course **c = new Course *[2]{a, b}; + s3.set_num_submitted_courses(2); + s3.set_submitted_courses(c); - std::cout << "Submitted subjects example" << std::endl; + std::cout << "Submitted courses example" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "Input: s3.set_num_submitted_subjects(2)" << std::endl; - std::cout << "Number of submitted subjects: " << s3.get_num_submitted_subjects() << std::endl << std::endl; + std::cout << "Input: 2" << std::endl; + std::cout << "Number of submitted courses: " << s3.get_num_submitted_courses(); + std::cout << std::endl << std::endl; - Subject **ssj = s3.get_submitted_subjects(); - if (ssj != nullptr) + Course **sc = s3.get_submitted_courses(); + if (sc != nullptr) { - std::cout << "Input: {\"Discrete Math\", \"Physics\"}" << std::endl; - std::cout << "Submitted subjects: "; - for (unsigned int i = 0; i < s3.get_num_submitted_subjects(); i++) + std::cout << "Input: Discrete Math, Physics" << std::endl; + std::cout << "Submitted courses: "; + for (unsigned int i = 0; i < s3.get_num_submitted_courses(); i++) { - if (i != s3.get_num_submitted_subjects()-1) std::cout << ssj[i][0].get_sname() << ", "; - else std::cout << ssj[i][0].get_sname() << std::endl; + if (i != s3.get_num_submitted_courses()-1) std::cout << sc[i][0].get_cname() << ", "; + else std::cout << sc[i][0].get_cname() << std::endl; } } } -static void plusequals_overload(Student& s3, Subject *s) +static void plusequals_overload(Student& s3, Course *c) { - s3 += s; - Subject **ssj = s3.get_submitted_subjects(); - if (ssj != nullptr) + s3 += c; + Course **sc = s3.get_submitted_courses(); + if (sc != nullptr) { std::cout << "+= operator overload" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "Input: s3 += \"OOP\"" << std::endl;; - std::cout << "Updated submitted subjects: "; - for (unsigned int i = 0; i < s3.get_num_submitted_subjects(); i++) + std::cout << "Input: OOP" << std::endl;; + std::cout << "Updated submitted courses: "; + for (unsigned int i = 0; i < s3.get_num_submitted_courses(); i++) { - if (i != s3.get_num_submitted_subjects()-1) std::cout << ssj[i][0].get_sname() << ", "; - else std::cout << ssj[i][0].get_sname() << std::endl; + if (i != s3.get_num_submitted_courses()-1) std::cout << sc[i][0].get_cname() << ", "; + else std::cout << sc[i][0].get_cname() << std::endl; } } } -static void getters(const Subject& sb) +static void getters(const Course& c) { - std::cout << "Getters example using Subject object" << std::endl; + std::cout << "Getters example using Course object" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "Constructor: Subject(\"356431\", \"OOP\", 2)" << 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; + std::cout << "Constructor: Course(\"356431\", \"OOP\", 2)" << std::endl; + std::cout << "Code: " << c.get_code() << std::endl; + std::cout << "Course name: " << c.get_cname() << std::endl; + std::cout << "Course semester: " << c.get_csemester() << std::endl; } -static void setters(Subject& sb) +static void setters(Course& c) { - std::string c = "14556"; - std::string n = "Calculus I"; + std::string code = "14556"; + std::string name = "Calculus I"; - sb.set_code(c); - sb.set_sname(n); - sb.set_subjsemester(1); + c.set_code(code); + c.set_cname(name); + c.set_csemester(1); - std::cout << "Setters example using Subject object" << std::endl; + std::cout << "Setters example using Course object" << std::endl; std::cout << "----------------------------" << std::endl; - std::cout << "Input: sb.set_code(\"14556\")" << '\t' << '\t'; - std::cout << "New code: " << sb.get_code() << std::endl; - std::cout << "Input: sb.set_sname(\"Calculus I\")" << '\t'; - std::cout << "New subject name: " << sb.get_sname() << std::endl; - std::cout << "Input: sb.set_subjsemester(1):" << '\t' << '\t'; - std::cout << "New subject semester: " << sb.get_subjsemester() << std::endl; + std::cout << "Input: 14556" << std::endl; + std::cout << "New code: " << c.get_code() << std::endl; + std::cout << std::endl; + std::cout << "Input: Calculus I" << std::endl; + std::cout << "New course name: " << c.get_cname() << std::endl; + std::cout << std::endl; + std::cout << "Input: 1" << std::endl; + std::cout << "New course semester: " << c.get_csemester() << std::endl; } diff --git a/assignment-2.3-operoverloading/src/student.cpp b/assignment-2.3-operoverloading/src/student.cpp @@ -1,45 +1,45 @@ #include "student.h" Student::Student(const char *AM, const std::string& name) - :AM(convert_AM(AM)), name(name), semester(1), psubj(0) + :AM(convert_AM(AM)), name(name), semester(1), pcourses(0) { - nssubj = 0; - ssubj = nullptr; + nsc = 0; + sc = nullptr; } Student::Student(const char *AM, const std::string& name, unsigned int semester) - :AM(convert_AM(AM)), name(name), semester(semester), psubj(0) + :AM(convert_AM(AM)), name(name), semester(semester), pcourses(0) { - nssubj = 0; - ssubj = nullptr; + nsc = 0; + sc = nullptr; } 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)) + unsigned int pcourses, const float *grades) + :AM(convert_AM(AM)), name(name), semester(semester), pcourses(pcourses), grades(convert_PSG(grades)) { - nssubj = 0; - ssubj = nullptr; + nsc = 0; + sc = nullptr; } Student::Student(const Student& s) - :name(s.name), semester(s.semester), psubj(s.psubj) + :name(s.name), semester(s.semester), pcourses(s.pcourses) { int sl = strlen(s.AM); this->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); + this->grades = new float[s.pcourses]; + memcpy(grades, s.grades, sizeof(float) * s.pcourses); - if (s.nssubj <= 0) + if (s.nsc <= 0) { - nssubj = 0; - ssubj = nullptr; + nsc = 0; + sc = nullptr; } else { - this->ssubj = new Subject *[s.nssubj]; - memcpy(ssubj, s.ssubj, sizeof(s.ssubj) * s.nssubj); + this->sc = new Course *[s.nsc]; + memcpy(sc, s.sc, sizeof(s.sc) * s.nsc); } } @@ -47,20 +47,20 @@ Student::~Student() { if (this->AM != nullptr) delete[] this->AM; if (this->grades != nullptr) delete[] this->grades; - if (this->ssubj != nullptr) delete[] this->ssubj; + if (this->sc != nullptr) delete[] this->sc; } -void Student::operator+= (Subject *s) +void Student::operator+= (Course *c) { - Subject **tmp = new Subject *[nssubj+1]; - if (ssubj != nullptr) + Course **tmp = new Course *[nsc+1]; + if (sc != nullptr) { - memcpy(tmp, ssubj, sizeof(Subject *) * nssubj); - delete[] ssubj; + memcpy(tmp, sc, sizeof(Course *) * nsc); + delete[] sc; } - tmp[nssubj] = s; - ssubj = tmp; - nssubj++; + tmp[nsc] = c; + sc = tmp; + nsc++; } Student Student::operator= (const Student& s) @@ -69,12 +69,12 @@ Student Student::operator= (const Student& s) this->AM = convert_AM(s.AM); this->name = s.name; this->semester = s.semester; - this->psubj = s.psubj; + this->pcourses = s.pcourses; if (s.grades != nullptr) this->grades = convert_PSG(s.grades); - if (s.ssubj != nullptr) + if (s.sc != nullptr) { - this->nssubj = s.nssubj; - this->ssubj = s.ssubj; + this->nsc = s.nsc; + this->sc = s.sc; } return *this; } @@ -124,24 +124,24 @@ unsigned int Student::get_semester() const return this->semester; } -unsigned int Student::get_psubj() const +unsigned int Student::get_pcourses() const { - return this->psubj; + return this->pcourses; } float *Student::get_grades() const { - return (this->psubj > 0) ? this->grades : nullptr; + return (this->pcourses > 0) ? this->grades : nullptr; } -Subject **Student::get_submitted_subjects() const +Course **Student::get_submitted_courses() const { - return this->ssubj; + return this->sc; } -unsigned int Student::get_num_submitted_subjects() const +unsigned int Student::get_num_submitted_courses() const { - return this->nssubj; + return this->nsc; } void Student::set_AM(const char *AM) @@ -160,9 +160,9 @@ void Student::set_semester(unsigned int semester) this->semester = semester; } -void Student::set_psubj(unsigned int psubj) +void Student::set_pcourses(unsigned int pcourses) { - this->psubj = psubj; + this->pcourses = pcourses; } void Student::set_grades(float *grades) @@ -170,17 +170,17 @@ void Student::set_grades(float *grades) this->grades = convert_PSG(grades); } -void Student::set_num_submitted_subjects(unsigned nssubj) +void Student::set_num_submitted_courses(unsigned nsc) { - this->nssubj = nssubj; + this->nsc = nsc; } -void Student::set_submitted_subjects(Subject **ssubj) +void Student::set_submitted_courses(Course **sc) { - if (ssubj != nullptr) + if (sc != nullptr) { - this->ssubj = new Subject *[nssubj]; - memcpy(this->ssubj, ssubj, sizeof(Subject *) * nssubj); + this->sc = new Course *[nsc]; + memcpy(this->sc, sc, sizeof(Course *) * nsc); } } @@ -194,10 +194,10 @@ char *Student::convert_AM(const char *AM) float *Student::convert_PSG(const float *grades) { - if (psubj > 0 && grades != nullptr) + if (pcourses > 0 && grades != nullptr) { - float *tmp = new float[psubj]; - memcpy(tmp, grades, sizeof(float) * psubj); + float *tmp = new float[pcourses]; + memcpy(tmp, grades, sizeof(float) * pcourses); if (this->grades != nullptr) delete[] this->grades; return tmp; } @@ -206,24 +206,24 @@ float *Student::convert_PSG(const float *grades) void Student::add_grade(float grade) { - float *tmp = new float[psubj+1]; + float *tmp = new float[pcourses+1]; if (grades != nullptr) { - memcpy(tmp, grades, sizeof(float) * psubj); + memcpy(tmp, grades, sizeof(float) * pcourses); delete[] grades; } - tmp[psubj] = grade; + tmp[pcourses] = grade; grades = tmp; - psubj++; + pcourses++; } void Student::detailed_print() const { if (grades != nullptr) { - for (unsigned int i = 0; i < psubj; i++) + for (unsigned int i = 0; i < pcourses; i++) { - std::cout << "Subject " << i+1 << ": "; + std::cout << "Course " << i+1 << ": "; std::cout << grades[i] << std::endl; } std::cout << "Average grade: " << std::setprecision(2) << calc_average() << std::endl; @@ -235,9 +235,9 @@ float Student::calc_average() const if (grades != nullptr) { float sum = 0; - for (unsigned int i = 0; i < psubj; i++) + for (unsigned int i = 0; i < pcourses; i++) sum += grades[i]; - float average = sum / psubj; + float average = sum / pcourses; return average; } else return 0.0f; diff --git a/assignment-2.3-operoverloading/src/student.h b/assignment-2.3-operoverloading/src/student.h @@ -6,17 +6,17 @@ #include <string> #include <string.h> -#include "subject.h" +#include "course.h" class Student { private: char *AM; // AM std::string name; // Name - Subject **ssubj; // Submitted subjects - unsigned int nssubj; // Number of submitted subjects + Course **sc; // Submitted courses + unsigned int nsc; // Number of submitted courses unsigned int semester; // Current semester - unsigned int psubj; // Passed subjects + unsigned int pcourses; // Passed courses float *grades; // Grades int size; @@ -24,11 +24,11 @@ class Student 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); + unsigned int pcourses, const float *grades); Student(const Student& s); ~Student(); - void operator+= (Subject *s); + void operator+= (Course *c); Student operator= (const Student& s); bool operator== (const Student& s) const; @@ -41,18 +41,18 @@ class Student const char *get_AM() const; const std::string& get_name() const; unsigned int get_semester() const; - unsigned int get_psubj() const; + unsigned int get_pcourses() const; float *get_grades() const; - Subject **get_submitted_subjects() const; - unsigned int get_num_submitted_subjects() const; + Course **get_submitted_courses() const; + unsigned int get_num_submitted_courses() 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_pcourses(unsigned int pcourses); void set_grades(float *grades); - void set_num_submitted_subjects(unsigned int nssubj); - void set_submitted_subjects(Subject **ssubj); + void set_num_submitted_courses(unsigned int nsc); + void set_submitted_courses(Course **sc); void add_grade(float grade); void detailed_print() const; diff --git a/assignment-2.3-operoverloading/src/subject.cpp b/assignment-2.3-operoverloading/src/subject.cpp @@ -1,40 +0,0 @@ -#include "subject.h" - - -Subject::Subject() {} - -Subject::Subject(const std::string& code, const std::string& sname, unsigned int subjsemester) - :code(code), sname(sname), subjsemester(subjsemester) {} - -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 @@ -1,28 +0,0 @@ -#ifndef SUBJECT_H -#define SUBJECT_H - -#include <iostream> -#include <string> - -class Subject -{ - private: - std::string code; // Subject code - std::string sname; // Subject name - unsigned int subjsemester; // Corresponding semester of subject - - public: - Subject(); - Subject(const std::string& code, const std::string& sname, unsigned int subjsemester); - Subject(const Subject& s); - - const std::string& get_code() const; - const std::string& get_sname() const; - unsigned int get_subjsemester() const; - - void set_code(const std::string& code); - void set_sname(const std::string& sname); - void set_subjsemester(unsigned int subjsemester); -}; - -#endif /* SUBJECT_H */ diff --git a/assignment-2.5-spreadsheets/bin/spreadsheets b/assignment-2.5-spreadsheets/bin/spreadsheets Binary files differ. diff --git a/assignment-2.5-spreadsheets/obj/course.o b/assignment-2.5-spreadsheets/obj/course.o Binary files differ. diff --git a/assignment-2.5-spreadsheets/obj/student.o b/assignment-2.5-spreadsheets/obj/student.o Binary files differ. diff --git a/assignment-2.5-spreadsheets/obj/xstring.o b/assignment-2.5-spreadsheets/obj/xstring.o Binary files differ. diff --git a/assignment-2.5-spreadsheets/src/course.cpp b/assignment-2.5-spreadsheets/src/course.cpp @@ -0,0 +1,3 @@ +#include "course.h" + +Course::Course() {} diff --git a/assignment-2.5-spreadsheets/src/course.h b/assignment-2.5-spreadsheets/src/course.h @@ -0,0 +1,12 @@ +#ifndef COURSE_H +#define COURSE_H + +class Course +{ + private: + + public: + Course(); +}; + +#endif /* COURSE_H */ diff --git a/assignment-2.5-spreadsheets/src/student.cpp b/assignment-2.5-spreadsheets/src/student.cpp @@ -0,0 +1,3 @@ +#include "student.h" + +Student::Student() {} diff --git a/assignment-2.5-spreadsheets/src/student.h b/assignment-2.5-spreadsheets/src/student.h @@ -0,0 +1,12 @@ +#ifndef STUDENT_H +#define STUDENT_H + +class Student +{ + private: + + public: + Student(); +}; + +#endif /* STUDENT_H */ diff --git a/assignment-2.5-spreadsheets/src/xstring.cpp b/assignment-2.5-spreadsheets/src/xstring.cpp @@ -9,16 +9,8 @@ xstring::xstring(const char *s) xstring::xstring(const xstring& s) { - if (!this->empty()) - { - str = conv(s.str); - len = size(); - } - else - { - str = new char[1]; - len = 0; - } + this->str = conv(s.str); + this->len = s.len; } xstring::~xstring() @@ -160,11 +152,8 @@ bool xstring::operator>= (const char *s) const char& xstring::operator[] (std::size_t i) const { - if (i >= len) - { - std::cerr << "Out of bounds." << std::endl; - exit(1); - } + try {if (i >= len) throw i;} + catch (int i) {throw std::runtime_error("Out of bounds.");} return str[i]; } @@ -250,7 +239,6 @@ char *xstring::conv(const char *s) char *xstring::conv(char c) { - // 2 for '\0' char *tmp = new char[1]; tmp[0] = c; return tmp;