uni

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

commit a12cb82f80d726096a34367afb212921f7568007
parent 43e84fc9e2a5fca6741d72e9d080ec7a1459dff7
Author: Christos Margiolis <christos@margiolis.net>
Date:   Sun, 10 May 2020 16:37:18 +0300

added return types above function name

Diffstat:
Massignment-2.2-classes/classes.cpp | 78++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------
Massignment-2.3-operoverloading/src/course.cpp | 18++++++++++++------
Massignment-2.3-operoverloading/src/main.cpp | 53+++++++++++++++++++++++++++++++++++------------------
Massignment-2.3-operoverloading/src/student.cpp | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Massignment-2.4-inheritance/bin/inheritance | 0
Massignment-2.4-inheritance/obj/app.o | 0
Massignment-2.4-inheritance/src/app.cpp | 42++++++++++++++++++++++++++++--------------
Massignment-2.4-inheritance/src/appsystem.cpp | 72++++++++++++++++++++++++++++++++++++++++++++++++------------------------
Massignment-2.4-inheritance/src/game.cpp | 15++++++++++-----
Massignment-2.4-inheritance/src/main.cpp | 21++++++++++++++-------
Massignment-2.4-inheritance/src/manufacturer.cpp | 21++++++++++++++-------
Massignment-2.4-inheritance/src/office.cpp | 9++++++---
Massignment-2.4-inheritance/src/review.cpp | 18++++++++++++------
Massignment-2.5-spreadsheets/bin/spreadsheets | 0
Massignment-2.5-spreadsheets/obj/main.o | 0
Massignment-2.5-spreadsheets/src/app.cpp | 12++++++++----
Massignment-2.5-spreadsheets/src/course.cpp | 6++++--
Massignment-2.5-spreadsheets/src/main.cpp | 6++++--
Massignment-2.5-spreadsheets/src/student.cpp | 9++++++---
Massignment-2.5-spreadsheets/src/xstring.cpp | 126+++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
20 files changed, 391 insertions(+), 196 deletions(-)

diff --git a/assignment-2.2-classes/classes.cpp b/assignment-2.2-classes/classes.cpp @@ -69,58 +69,69 @@ Student::~Student() if (this->AM != nullptr) delete[] this->grades; } -const char *Student::get_AM() const +const char * +Student::get_AM() const { return this->AM; } -const std::string& Student::get_name() const +const std::string& +Student::get_name() const { return this->name; } -unsigned int Student::get_semester() const +unsigned int +Student::get_semester() const { return this->semester; } -unsigned int Student::get_pcourses() const +unsigned int +Student::get_pcourses() const { return this->pcourses; } -float *Student::get_grades() const +float * +Student::get_grades() const { return this->grades; } -void Student::set_AM(const char *AM) +void +Student::set_AM(const char *AM) { if (this->AM != nullptr) delete[] this->AM; this->AM = convert_AM(AM); } -void Student::set_name(const std::string& name) +void +Student::set_name(const std::string& name) { this->name = name; } -void Student::set_semester(unsigned int semester) +void +Student::set_semester(unsigned int semester) { this->semester = semester; } -void Student::set_pcourses(unsigned int pcourses) +void +Student::set_pcourses(unsigned int pcourses) { this->pcourses = pcourses; } -void Student::set_grades(float *grades) +void +Student::set_grades(float *grades) { this->grades = convert_PSG(grades); } -char *Student::convert_AM(const char *AM) +char * +Student::convert_AM(const char *AM) { int len = strlen(AM); char *tmp = new char[len+1]; @@ -128,7 +139,8 @@ char *Student::convert_AM(const char *AM) return tmp; } -float *Student::convert_PSG(const float *grades) +float * +Student::convert_PSG(const float *grades) { if (pcourses > 0 && grades != nullptr) { @@ -140,7 +152,8 @@ float *Student::convert_PSG(const float *grades) else return nullptr; } -void Student::add_grade(float grade) +void +Student::add_grade(float grade) { float *tmp = new float[pcourses+1]; if (grades != nullptr) @@ -153,7 +166,8 @@ void Student::add_grade(float grade) pcourses++; } -void Student::detailed_print() const +void +Student::detailed_print() const { if (grades != nullptr) { @@ -166,7 +180,8 @@ void Student::detailed_print() const } } -float Student::calc_average() const +float +Student::calc_average() const { if (grades != nullptr) { @@ -190,7 +205,8 @@ static void detprint (const Student& s3); static void setters(Student& s3); static void addgrd(Student& s3); -int main(int argc, char **argv) +int +main(int argc, char **argv) { std::string n1 = "Name Surname"; std::string n2 = "Name Surnamington"; @@ -222,7 +238,8 @@ int main(int argc, char **argv) return 0; } -std::ostream& operator<< (std::ostream& stream, const Student& s) +std::ostream& +operator<< (std::ostream& stream, const Student& s) { return stream << "AM: " << s.get_AM() << std::endl << @@ -230,14 +247,16 @@ std::ostream& operator<< (std::ostream& stream, const Student& s) "Semester: " << s.get_semester() << std::endl; } -static void cont(void) +static void +cont(void) { std::cout << std::endl; std::cout << "Press <ENTER> to continue. . ."; if (std::cin.get()) system("clear || cls"); } -static void constructor1(const Student& s1) +static void +constructor1(const Student& s1) { std::cout << "Constructor for s1 (AM, Name)" << std::endl; std::cout << "----------------------------" << std::endl; @@ -247,14 +266,16 @@ static void constructor1(const Student& s1) std::cout << "Courses passed (default value): " << s1.get_pcourses() << std::endl; } -static void ostream_overload(const Student& s1) +static void +ostream_overload(const Student& s1) { std::cout << "std::ostream overload" << std::endl; std::cout << "----------------------------" << std::endl; std::cout << s1 << std::endl; } -static void constructor2(const Student& s2) +static void +constructor2(const Student& s2) { std::cout << "Constructor for s2 (AM, Name, Semester)" << std::endl; std::cout << "----------------------------" << std::endl; @@ -264,7 +285,8 @@ static void constructor2(const Student& s2) std::cout << "Courses passed (default value): " << s2.get_pcourses() << std::endl; } -static void copy_constructor(const Student& copystud) +static void +copy_constructor(const Student& copystud) { std::cout << "Copy Constructor using copystud object as a copy of s2" << std::endl; std::cout << "----------------------------" << std::endl; @@ -274,7 +296,8 @@ static void copy_constructor(const Student& copystud) std::cout << "Courses passed (default value): " << copystud.get_pcourses() << std::endl; } -static void constructor3(const Student& s3) +static void +constructor3(const Student& s3) { std::cout << "Constructor for s3 (AM, Name, Semester, Courses passed, Grades)" << std::endl; std::cout << "----------------------------" << std::endl; @@ -295,14 +318,16 @@ static void constructor3(const Student& s3) } } -static void detprint (const Student& s3) +static void +detprint (const Student& s3) { std::cout << "Detailed print of s3's grades" << std::endl; std::cout << "----------------------------" << std::endl; s3.detailed_print(); } -static void setters(Student& s3) +static void +setters(Student& s3) { s3.set_AM("010101"); s3.set_name("AAAA"); @@ -340,7 +365,8 @@ static void setters(Student& s3) } } -static void addgrd(Student& s3) +static void +addgrd(Student& s3) { s3.add_grade(7.5f); float *gr = s3.get_grades(); diff --git a/assignment-2.3-operoverloading/src/course.cpp b/assignment-2.3-operoverloading/src/course.cpp @@ -9,32 +9,38 @@ Course::Course(const std::string& code, const std::string& cname, unsigned int c Course::Course(const Course& c) :code(c.code), cname(c.cname), csemester(c.csemester) {} -const std::string& Course::get_code() const +const std::string& +Course::get_code() const { return this->code; } -const std::string& Course::get_cname() const +const std::string& +Course::get_cname() const { return this->cname; } -unsigned int Course::get_csemester() const +unsigned int +Course::get_csemester() const { return this->csemester; } -void Course::set_code(const std::string& code) +void +Course::set_code(const std::string& code) { this->code = code; } -void Course::set_cname(const std::string& cname) +void +Course::set_cname(const std::string& cname) { this->cname = cname; } -void Course::set_csemester(unsigned int csemester) +void +Course::set_csemester(unsigned int csemester) { this->csemester = csemester; } diff --git a/assignment-2.3-operoverloading/src/main.cpp b/assignment-2.3-operoverloading/src/main.cpp @@ -9,7 +9,7 @@ static void copy_constructor(const Student& copystud); static void conditional_overload(const Student& s1, const Student& s2, const Student& copystud); static void equals_overload(const Student& s1, Student& s2); static void constructor3(const Student& s3); -static void detprint (const Student& s3); +static void detprint(const Student& s3); static void setters(Student& s3); static void addgrd(Student& s3); static void submcourses(Student& s3); @@ -17,7 +17,8 @@ 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) +int +main(int argc, char **argv) { std::string n1 = "Name Surname"; std::string n2 = "Name Surnamington"; @@ -64,7 +65,8 @@ int main(int argc, char **argv) return 0; } -std::ostream& operator<< (std::ostream& stream, const Student& s) +std::ostream& +operator<< (std::ostream& stream, const Student& s) { return stream << "AM: " << s.get_AM() << std::endl << @@ -72,14 +74,16 @@ std::ostream& operator<< (std::ostream& stream, const Student& s) "Semester: " << s.get_semester(); } -static void cont(void) +static void +cont(void) { std::cout << std::endl; std::cout << "Press <ENTER> to continue. . ."; if (std::cin.get()) system("clear || cls"); } -static void constructor1(const Student& s1) +static void +constructor1(const Student& s1) { std::cout << "Constructor for s1 (AM, Name)" << std::endl; std::cout << "----------------------------" << std::endl; @@ -89,14 +93,16 @@ static void constructor1(const Student& s1) std::cout << "Courses passed (default value): " << s1.get_pcourses() << std::endl; } -static void ostream_overload(const Student& s1) +static void +ostream_overload(const Student& s1) { std::cout << "std::ostream overload" << std::endl; std::cout << "----------------------------" << std::endl; std::cout << s1 << std::endl; } -static void constructor2(const Student& s2) +static void +constructor2(const Student& s2) { std::cout << "Constructor for s2 (AM, Name, Semester)" << std::endl; std::cout << "----------------------------" << std::endl; @@ -106,7 +112,8 @@ static void constructor2(const Student& s2) std::cout << "Courses passed (default value): " << s2.get_pcourses() << std::endl; } -static void copy_constructor(const Student& copystud) +static void +copy_constructor(const Student& copystud) { std::cout << "Copy Constructor using copystud object as a copy of s2" << std::endl; std::cout << "----------------------------" << std::endl; @@ -116,7 +123,8 @@ static void copy_constructor(const Student& copystud) std::cout << "Courses passed (default value): " << copystud.get_pcourses() << std::endl; } -static void conditional_overload(const Student& s1, const Student& s2, const Student& copystud) +static void +conditional_overload(const Student& s1, const Student& s2, const Student& copystud) { std::cout << "Conditional operator overloading" << std::endl; std::cout << "----------------------------" << std::endl; @@ -129,7 +137,8 @@ static void conditional_overload(const Student& s1, const Student& s2, const Stu std::cout << std::endl; } -static void equals_overload(const Student& s1, Student& s2) +static void +equals_overload(const Student& s1, Student& s2) { s2 = s1; std::cout << "= operator overload (s2 = s1)" << std::endl; @@ -140,7 +149,8 @@ static void equals_overload(const Student& s1, Student& s2) std::cout << "Courses passed (default value): " << s2.get_pcourses() << std::endl; } -static void constructor3(const Student& s3) +static void +constructor3(const Student& s3) { std::cout << "Constructor for s3 (AM, Name, Semester, Courses passed, Grades)" << std::endl; std::cout << "----------------------------" << std::endl; @@ -161,14 +171,16 @@ static void constructor3(const Student& s3) } } -static void detprint (const Student& s3) +static void +detprint(const Student& s3) { std::cout << "Detailed print of s3's grades" << std::endl; std::cout << "----------------------------" << std::endl; s3.detailed_print(); } -static void setters(Student& s3) +static void +setters(Student& s3) { s3.set_AM("010101"); s3.set_name("AAAA"); @@ -206,7 +218,8 @@ static void setters(Student& s3) } } -static void addgrd(Student& s3) +static void +addgrd(Student& s3) { s3.add_grade(7.5f); float *gr = s3.get_grades(); @@ -222,7 +235,8 @@ static void addgrd(Student& s3) } } -static void submcourses(Student& s3) +static void +submcourses(Student& s3) { std::string c1 = "11231"; std::string c2 = "56562"; @@ -254,7 +268,8 @@ static void submcourses(Student& s3) } } -static void plusequals_overload(Student& s3, Course *c) +static void +plusequals_overload(Student& s3, Course *c) { s3 += c; Course **sc = s3.get_submitted_courses(); @@ -272,7 +287,8 @@ static void plusequals_overload(Student& s3, Course *c) } } -static void getters(const Course& c) +static void +getters(const Course& c) { std::cout << "Getters example using Course object" << std::endl; std::cout << "----------------------------" << std::endl; @@ -282,7 +298,8 @@ static void getters(const Course& c) std::cout << "Course semester: " << c.get_csemester() << std::endl; } -static void setters(Course& c) +static void +setters(Course& c) { std::string code = "14556"; std::string name = "Calculus I"; diff --git a/assignment-2.3-operoverloading/src/student.cpp b/assignment-2.3-operoverloading/src/student.cpp @@ -50,7 +50,8 @@ Student::~Student() if (this->sc != nullptr) delete[] this->sc; } -void Student::operator+= (Course *c) +void +Student::operator+= (Course *c) { Course **tmp = new Course *[nsc+1]; if (sc != nullptr) @@ -63,7 +64,8 @@ void Student::operator+= (Course *c) nsc++; } -Student Student::operator= (const Student& s) +Student +Student::operator= (const Student& s) { if (this == &s) return *this; this->AM = convert_AM(s.AM); @@ -79,103 +81,123 @@ Student Student::operator= (const Student& s) return *this; } -bool Student::operator== (const Student& s) const +bool +Student::operator== (const Student& s) const { return this->semester == s.semester; } -bool Student::operator!= (const Student& s) const +bool +Student::operator!= (const Student& s) const { return this->semester != s.semester; } -bool Student::operator< (const Student& s) const +bool +Student::operator< (const Student& s) const { return this->semester < s.semester; } -bool Student::operator<= (const Student& s) const +bool +Student::operator<= (const Student& s) const { return this->semester <= s.semester; } -bool Student::operator> (const Student& s) const +bool +Student::operator> (const Student& s) const { return this->semester > s.semester; } -bool Student::operator>= (const Student& s) const +bool +Student::operator>= (const Student& s) const { return this->semester >= s.semester; } -const char *Student::get_AM() const +const char * +Student::get_AM() const { return this->AM; } -const std::string& Student::get_name() const +const std::string& +Student::get_name() const { return this->name; } -unsigned int Student::get_semester() const +unsigned int +Student::get_semester() const { return this->semester; } -unsigned int Student::get_pcourses() const +unsigned int +Student::get_pcourses() const { return this->pcourses; } -float *Student::get_grades() const +float * +Student::get_grades() const { return (this->pcourses > 0) ? this->grades : nullptr; } -Course **Student::get_submitted_courses() const +Course ** +Student::get_submitted_courses() const { return this->sc; } -unsigned int Student::get_num_submitted_courses() const +unsigned int +Student::get_num_submitted_courses() const { return this->nsc; } -void Student::set_AM(const char *AM) +void +Student::set_AM(const char *AM) { if (this->AM != nullptr) delete[] this->AM; this->AM = convert_AM(AM); } -void Student::set_name(const std::string& name) +void +Student::set_name(const std::string& name) { this->name = name; } -void Student::set_semester(unsigned int semester) +void +Student::set_semester(unsigned int semester) { this->semester = semester; } -void Student::set_pcourses(unsigned int pcourses) +void +Student::set_pcourses(unsigned int pcourses) { this->pcourses = pcourses; } -void Student::set_grades(float *grades) +void +Student::set_grades(float *grades) { this->grades = convert_PSG(grades); } -void Student::set_num_submitted_courses(unsigned nsc) +void +Student::set_num_submitted_courses(unsigned nsc) { this->nsc = nsc; } -void Student::set_submitted_courses(Course **sc) +void +Student::set_submitted_courses(Course **sc) { if (sc != nullptr) { @@ -184,7 +206,8 @@ void Student::set_submitted_courses(Course **sc) } } -char *Student::convert_AM(const char *AM) +char * +Student::convert_AM(const char *AM) { int len = strlen(AM); char *tmp = new char[len+1]; @@ -192,7 +215,8 @@ char *Student::convert_AM(const char *AM) return tmp; } -float *Student::convert_PSG(const float *grades) +float * +Student::convert_PSG(const float *grades) { if (pcourses > 0 && grades != nullptr) { @@ -204,7 +228,8 @@ float *Student::convert_PSG(const float *grades) else return nullptr; } -void Student::add_grade(float grade) +void +Student::add_grade(float grade) { float *tmp = new float[pcourses+1]; if (grades != nullptr) @@ -217,7 +242,8 @@ void Student::add_grade(float grade) pcourses++; } -void Student::detailed_print() const +void +Student::detailed_print() const { if (grades != nullptr) { @@ -230,7 +256,8 @@ void Student::detailed_print() const } } -float Student::calc_average() const +float +Student::calc_average() const { if (grades != nullptr) { diff --git a/assignment-2.4-inheritance/bin/inheritance b/assignment-2.4-inheritance/bin/inheritance Binary files differ. diff --git a/assignment-2.4-inheritance/obj/app.o b/assignment-2.4-inheritance/obj/app.o Binary files differ. diff --git a/assignment-2.4-inheritance/src/app.cpp b/assignment-2.4-inheritance/src/app.cpp @@ -32,7 +32,8 @@ App::~App() } } -char *App::convsn(const char *serialnum) +char * +App::convsn(const char *serialnum) { int len = strlen(serialnum); char *tmp = new char[len + 1]; @@ -40,68 +41,81 @@ char *App::convsn(const char *serialnum) return tmp; } -void App::addrev(Review *rev) +void +App::addrev(Review *rev) { reviews.push_back(rev); } -void App::addrevs(const std::vector<Review *> revs) +void +App::addrevs(const std::vector<Review *> revs) { reviews.insert(reviews.end(), revs.begin(), revs.end()); } -const char *App::get_serialnum() const +const char * +App::get_serialnum() const { return serialnum; } -const std::string& App::get_name() const +const std::string& +App::get_name() const { return name; } -const std::string& App::get_os() const +const std::string& +App::get_os() const { return os; } -const Manufacturer App::get_manf() const +const Manufacturer +App::get_manf() const { return Manufacturer(*manf); } -const std::vector<Review *>& App::get_revs() const +const std::vector<Review *>& +App::get_revs() const { return reviews; } -int App::get_price() const +int +App::get_price() const { return price; } -void App::set_serialnum(const char *serialnum) +void +App::set_serialnum(const char *serialnum) { if (this->serialnum != nullptr) delete[] this->serialnum; this->serialnum = convsn(serialnum); } -void App::set_name(const std::string& name) +void +App::set_name(const std::string& name) { this->name = name; } -void App::set_os(const std::string& os) +void +App::set_os(const std::string& os) { this->os = os; } -void App::set_manf(Manufacturer *manf) +void +App::set_manf(Manufacturer *manf) { this->manf = manf; } -void App::set_price(int price) +void +App::set_price(int price) { this->price = price; } diff --git a/assignment-2.4-inheritance/src/appsystem.cpp b/assignment-2.4-inheritance/src/appsystem.cpp @@ -8,19 +8,22 @@ AppSystem::~AppSystem() dealloc<Manufacturer>(manfs); } -AppSystem& AppSystem::operator+= (App *app) +AppSystem& +AppSystem::operator+= (App *app) { apps.push_back(app); return *this; } -AppSystem& AppSystem::operator+= (Manufacturer *man) +AppSystem& +AppSystem::operator+= (Manufacturer *man) { manfs.push_back(man); return *this; } -const std::vector<std::string> AppSystem::parse_office_exts(std::ifstream& f) +const std::vector<std::string> +AppSystem::parse_office_exts(std::ifstream& f) { std::vector<std::string> exts; std::string ext; @@ -30,63 +33,72 @@ const std::vector<std::string> AppSystem::parse_office_exts(std::ifstream& f) return exts; } -void AppSystem::write_office_exts(Office *of, std::ofstream& f) +void +AppSystem::write_office_exts(Office *of, std::ofstream& f) { std::vector<std::string> exts = of->get_exts(); for (auto& ext : exts) f << ext << '|'; } -void AppSystem::newrev(const std::string& appname, Review *rev) +void +AppSystem::newrev(const std::string& appname, Review *rev) { for (auto& app : apps) if (app->get_name() == appname) app->addrev(rev); } -void AppSystem::newrevs(const std::string& appname, const std::vector<Review *> revs) +void +AppSystem::newrevs(const std::string& appname, const std::vector<Review *> revs) { for (auto& app : apps) if (app->get_name() == appname) app->addrevs(revs); } -void AppSystem::chserialnum(const std::string& appname, const char *serialnum) +void +AppSystem::chserialnum(const std::string& appname, const char *serialnum) { for (auto& app : apps) if (app->get_name() == appname) app->set_serialnum(serialnum); } -void AppSystem::chname(const std::string& appname, const std::string& name) +void +AppSystem::chname(const std::string& appname, const std::string& name) { for (auto& app : apps) if (app->get_name() == appname) app->set_name(name); } -void AppSystem::chos(const std::string& appname, const std::string& os) +void +AppSystem::chos(const std::string& appname, const std::string& os) { for (auto& app : apps) if (app->get_name() == appname) app->set_os(os); } -void AppSystem::chmanf(const std::string& appname, Manufacturer *manf) +void +AppSystem::chmanf(const std::string& appname, Manufacturer *manf) { for (auto& app : apps) if (app->get_name() == appname) app->set_manf(manf); } -void AppSystem::chprice(const std::string& appname, int price) +void +AppSystem::chprice(const std::string& appname, int price) { for (auto& app : apps) if (app->get_name() == appname) app->set_price(price); } -void AppSystem::chgenre(const std::string& appname, const std::string& genre) +void +AppSystem::chgenre(const std::string& appname, const std::string& genre) { for (auto& app : apps) if (Game *o = dynamic_cast<Game *>(app)) @@ -94,7 +106,8 @@ void AppSystem::chgenre(const std::string& appname, const std::string& genre) o->set_genre(genre); } -void AppSystem::chonline(const std::string& appname, bool online) +void +AppSystem::chonline(const std::string& appname, bool online) { for (auto& app : apps) if (Game *o = dynamic_cast<Game *>(app)) @@ -102,7 +115,8 @@ void AppSystem::chonline(const std::string& appname, bool online) o->set_online(online); } -void AppSystem::chexts(const std::string& appname, const std::vector<std::string> exts) +void +AppSystem::chexts(const std::string& appname, const std::vector<std::string> exts) { for (auto& app : apps) if (Office *o = dynamic_cast<Office *>(app)) @@ -110,7 +124,8 @@ void AppSystem::chexts(const std::string& appname, const std::vector<std::string o->set_exts(exts); } -void AppSystem::removebad(Manufacturer *man) +void +AppSystem::removebad(Manufacturer *man) { apps.erase(std::remove_if(apps.begin(), apps.end(), [&](App *app) { @@ -121,7 +136,8 @@ void AppSystem::removebad(Manufacturer *man) }), apps.end()); } -void AppSystem::removebad(const char *manfname) +void +AppSystem::removebad(const char *manfname) { apps.erase(std::remove_if(apps.begin(), apps.end(), [&](App *app) { @@ -132,7 +148,8 @@ void AppSystem::removebad(const char *manfname) }), apps.end()); } -const std::vector<Office *> AppSystem::get_freeapps() const +const std::vector<Office *> +AppSystem::get_freeapps() const { std::vector<Office *> fapps; for (auto& app : apps) @@ -142,7 +159,8 @@ const std::vector<Office *> AppSystem::get_freeapps() const return fapps; } -const std::vector<Game *> AppSystem::get_goodgames() const +const std::vector<Game *> +AppSystem::get_goodgames() const { std::vector<Game *> ggames; for (auto& app : apps) @@ -165,33 +183,39 @@ const std::vector<Game *> AppSystem::get_goodgames() const return ggames; } -const std::vector<App *>& AppSystem::get_apps() const +const std::vector<App *>& +AppSystem::get_apps() const { return apps; } -const std::vector<Manufacturer *>& AppSystem::get_manfs() const +const std::vector<Manufacturer *>& +AppSystem::get_manfs() const { return manfs; } -bool AppSystem::valid_path(const std::string& strpath) +bool +AppSystem::valid_path(const std::string& strpath) { return (strpath.find(".csv") != std::string::npos); } -const std::string AppSystem::err_csv(const std::string& strpath) +const std::string +AppSystem::err_csv(const std::string& strpath) { return "Error. File must be of format \'.csv\'. (" + strpath + ")."; } -const std::string AppSystem::err_read(const char *fpath) +const std::string +AppSystem::err_read(const char *fpath) { return "Error reading file \'" + std::string(fpath) + "\'."; } -const std::string AppSystem::err_write(const char *fpath) +const std::string +AppSystem::err_write(const char *fpath) { return "Error writing to file (" + std::string(fpath) + ")."; } diff --git a/assignment-2.4-inheritance/src/game.cpp b/assignment-2.4-inheritance/src/game.cpp @@ -16,27 +16,32 @@ Game::Game(const Game& g) :App(g.serialnum, g.name, g.os, g.manf, g.price), genre(g.genre), online(g.online) {} -const std::string Game::get_genre() const +const std::string +Game::get_genre() const { return genre; } -bool Game::get_online() const +bool +Game::get_online() const { return online; } -void Game::set_genre(const std::string& genre) +void +Game::set_genre(const std::string& genre) { this->genre = genre; } -void Game::set_online(bool online) +void +Game::set_online(bool online) { this->online = online; } -void Game::print(std::ostream& stream) const +void +Game::print(std::ostream& stream) const { stream << std::left << std::setw(7) << serialnum << diff --git a/assignment-2.4-inheritance/src/main.cpp b/assignment-2.4-inheritance/src/main.cpp @@ -7,7 +7,8 @@ static void edit(AppSystem& sys); static void remove(AppSystem& sys); static void getapps(const AppSystem& sys); -int main(int argc, char **argv) +int +main(int argc, char **argv) { AppSystem sys; if (!sys.import_data<Manufacturer>("res/manfdata.csv")) return -1; @@ -27,7 +28,8 @@ int main(int argc, char **argv) return 0; } -std::ostream& operator<< (std::ostream& stream, const AppSystem& sys) +std::ostream& +operator<< (std::ostream& stream, const AppSystem& sys) { stream << std::left << std::setw(7) << "SN" << @@ -46,14 +48,16 @@ std::ostream& operator<< (std::ostream& stream, const AppSystem& sys) return stream; } -static void cont() +static void +cont() { std::cout << std::endl; std::cout << "Press <ENTER> to continue. . ."; if (std::cin.get()) system("clear || cls"); } -static void pluseqs(AppSystem& sys) +static void +pluseqs(AppSystem& sys) { Manufacturer *comp = new Manufacturer("0004", "Company", "comp@comp.com"); Manufacturer *chris = new Manufacturer("0005", "Chris", "chris@chris.com"); @@ -64,7 +68,8 @@ static void pluseqs(AppSystem& sys) sys += new Game("0005", "minecurses", "MAD Robot 1.0", chris, 0, "Puzzle", false); } -static void edit(AppSystem& sys) +static void +edit(AppSystem& sys) { sys.newrev("minecurses", new Review(5, "gamer", "Good game")); sys.newrevs("LibreOffice", {new Review(2, "user1", "Not so good"), new Review(4, "user2", "Good app")}); @@ -78,12 +83,14 @@ static void edit(AppSystem& sys) sys.chexts("zathura", {".exe", ".bin", ".dat"}); } -static void remove(AppSystem& sys) +static void +remove(AppSystem& sys) { sys.removebad("GNU"); } -static void getapps(const AppSystem& sys) +static void +getapps(const AppSystem& sys) { const std::vector<Office *>& fapps = sys.get_freeapps(); const std::vector<Game *>& ggames = sys.get_goodgames(); diff --git a/assignment-2.4-inheritance/src/manufacturer.cpp b/assignment-2.4-inheritance/src/manufacturer.cpp @@ -27,7 +27,8 @@ Manufacturer::~Manufacturer() if (name != nullptr) delete[] name; } -char *Manufacturer::convstr(const char *str) +char * +Manufacturer::convstr(const char *str) { int len = strlen(str); char *tmp = new char[len + 1]; @@ -35,34 +36,40 @@ char *Manufacturer::convstr(const char *str) return tmp; } -const char *Manufacturer::get_serialnum() const +const char * +Manufacturer::get_serialnum() const { return serialnum; } -const char *Manufacturer::get_name() const +const char * +Manufacturer::get_name() const { return name; } -const std::string& Manufacturer::get_email() const +const std::string& +Manufacturer::get_email() const { return email; } -void Manufacturer::set_serialnum(const char *serialnum) +void +Manufacturer::set_serialnum(const char *serialnum) { if (this->serialnum != nullptr) delete[] serialnum; this->serialnum = convstr(serialnum); } -void Manufacturer::set_name(const char *name) +void +Manufacturer::set_name(const char *name) { if (this->name != nullptr) delete[] name; this->name = convstr(name); } -void Manufacturer::set_email(const std::string& email) +void +Manufacturer::set_email(const std::string& email) { this->email = email; } diff --git a/assignment-2.4-inheritance/src/office.cpp b/assignment-2.4-inheritance/src/office.cpp @@ -16,18 +16,21 @@ Office::~Office() if (!extensions.empty()) extensions.clear(); } -const std::vector<std::string> Office::get_exts() const +const std::vector<std::string> +Office::get_exts() const { return extensions; } -void Office::set_exts(const std::vector<std::string>& extensions) +void +Office::set_exts(const std::vector<std::string>& extensions) { if (!this->extensions.empty()) this->extensions.clear(); this->extensions = extensions; } -void Office::print(std::ostream& stream) const +void +Office::print(std::ostream& stream) const { stream << std::left << std::setw(7) << serialnum << diff --git a/assignment-2.4-inheritance/src/review.cpp b/assignment-2.4-inheritance/src/review.cpp @@ -13,32 +13,38 @@ Review::Review(int stars, const std::string& username, const std::string& commen Review::Review(const Review& r) :stars(r.stars), username(r.username), comment(r.comment) {} -int Review::get_stars() const +int +Review::get_stars() const { return stars; } -const std::string& Review::get_username() const +const std::string& +Review::get_username() const { return username; } -const std::string& Review::get_comment() const +const std::string& +Review::get_comment() const { return comment; } -void Review::set_stars(int stars) +void +Review::set_stars(int stars) { this->stars = stars; } -void Review::set_username(const std::string& username) +void +Review::set_username(const std::string& username) { this->username = username; } -void Review::set_comment(const std::string& comment) +void +Review::set_comment(const std::string& comment) { this->comment = comment; } 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/main.o b/assignment-2.5-spreadsheets/obj/main.o Binary files differ. diff --git a/assignment-2.5-spreadsheets/src/app.cpp b/assignment-2.5-spreadsheets/src/app.cpp @@ -9,7 +9,8 @@ App::~App() dealloc<Student>(studs); } -bool App::import_matchings(const char *fpath) +bool +App::import_matchings(const char *fpath) { std::ifstream f; f.open(fpath); @@ -28,17 +29,20 @@ bool App::import_matchings(const char *fpath) return true; } -const std::vector<Course *>& App::get_courses() const +const std::vector<Course *>& +App::get_courses() const { return courses; } -const std::vector<Grades *>& App::get_grades() const +const std::vector<Grades *>& +App::get_grades() const { return grades; } -const std::vector<Student *>& App::get_studs() const +const std::vector<Student *>& +App::get_studs() const { return studs; } diff --git a/assignment-2.5-spreadsheets/src/course.cpp b/assignment-2.5-spreadsheets/src/course.cpp @@ -3,12 +3,14 @@ Course::Course(const lab::xstring& code, const lab::xstring& name) :code(code), name(name) {} -const lab::xstring& Course::get_code() const +const lab::xstring& +Course::get_code() const { return code; } -const lab::xstring& Course::get_name() const +const lab::xstring& +Course::get_name() const { return name; } diff --git a/assignment-2.5-spreadsheets/src/main.cpp b/assignment-2.5-spreadsheets/src/main.cpp @@ -2,7 +2,8 @@ std::ostream& operator<< (std::ostream& stream, const App& app); -int main(int argc, char **argv) +int +main(int argc, char **argv) { App app; if (!app.import_data<Course>("res/courses.csv")) return -1; @@ -19,7 +20,8 @@ int main(int argc, char **argv) return 0; } -std::ostream& operator<< (std::ostream& stream, const App& app) +std::ostream& +operator<< (std::ostream& stream, const App& app) { return stream; } diff --git a/assignment-2.5-spreadsheets/src/student.cpp b/assignment-2.5-spreadsheets/src/student.cpp @@ -5,17 +5,20 @@ Student::Student(const lab::xstring& AM, const lab::xstring& fname) :AM(AM), lname(lname), fname(fname) {} -const lab::xstring& Student::get_AM() const +const lab::xstring& +Student::get_AM() const { return AM; } -const lab::xstring& Student::get_lname() const +const lab::xstring& +Student::get_lname() const { return lname; } -const lab::xstring& Student::get_fname() const +const lab::xstring& +Student::get_fname() const { return fname; } diff --git a/assignment-2.5-spreadsheets/src/xstring.cpp b/assignment-2.5-spreadsheets/src/xstring.cpp @@ -29,7 +29,8 @@ xstring::~xstring() delete[] str; } -xstring xstring::operator= (const xstring& s) +xstring +xstring::operator= (const xstring& s) { if (this == &s) return *this; if (!s.empty()) @@ -46,7 +47,8 @@ xstring xstring::operator= (const xstring& s) return *this; } -xstring xstring::operator= (const char *s) +xstring +xstring::operator= (const char *s) { if (!empty()) delete[] str; str = conv(s); @@ -54,111 +56,132 @@ xstring xstring::operator= (const char *s) return *this; } -xstring xstring::operator+ (const xstring& s) +xstring +xstring::operator+ (const xstring& s) { return xstring(strcat(this->str, s.str)); } -xstring xstring::operator+ (const char *s) +xstring +xstring::operator+ (const char *s) { return xstring(strcat(this->str, s)); } -xstring& xstring::operator+= (const xstring& s) +xstring& +xstring::operator+= (const xstring& s) { append(s.str); return *this; } -xstring& xstring::operator+= (const char *s) +xstring& +xstring::operator+= (const char *s) { append(s); return *this; } -xstring& xstring::operator+= (char c) +xstring& +xstring::operator+= (char c) { push_back(c); return *this; } -bool xstring::operator== (const xstring& s) const +bool +xstring::operator== (const xstring& s) const { return strcmp(this->str, s.str) == 0; } -bool xstring::operator== (const char *s) const +bool +xstring::operator== (const char *s) const { return strcmp(this->str, s) == 0; } -bool xstring::operator!= (const xstring& s) const +bool +xstring::operator!= (const xstring& s) const { return strcmp(this->str, s.str) != 0; } -bool xstring::operator!= (const char *s) const +bool +xstring::operator!= (const char *s) const { return strcmp(this->str, s) != 0; } -bool xstring::operator< (const xstring& s) const +bool +xstring::operator< (const xstring& s) const { return strlen(this->str) < strlen(s.str); } -bool xstring::operator< (const char *s) const +bool +xstring::operator< (const char *s) const { return strlen(this->str) < strlen(s); } -bool xstring::operator<= (const xstring& s) const +bool +xstring::operator<= (const xstring& s) const { return strlen(this->str) <= strlen(s.str); } -bool xstring::operator<= (const char *s) const +bool +xstring::operator<= (const char *s) const { return strlen(this->str) <= strlen(s); } -bool xstring::operator> (const xstring& s) const +bool +xstring::operator> (const xstring& s) const { return strlen(this->str) > strlen(s.str); } -bool xstring::operator> (const char *s) const +bool +xstring::operator> (const char *s) const { return strlen(this->str) > strlen(s); } -bool xstring::operator>= (const xstring& s) const +bool +xstring::operator>= (const xstring& s) const { return strlen(this->str) >= strlen(s.str); } -bool xstring::operator>= (const char *s) const +bool +xstring::operator>= (const char *s) const { return strlen(this->str) >= strlen(s); } -char& xstring::operator[] (std::size_t i) const +char& +xstring::operator[] (std::size_t i) const { if (i >= len) throw std::runtime_error("Out of bounds."); return str[i]; } -std::ostream& operator<< (std::ostream& stream, const xstring& s) +std::ostream& +operator<< (std::ostream& stream, const xstring& s) { return stream << s.str; } -std::istream& operator>> (std::istream& stream, const xstring& s) +std::istream& +operator>> (std::istream& stream, const xstring& s) { return stream >> s.str; } -xstring& xstring::append(const xstring& s) +xstring& +xstring::append(const xstring& s) { if (!s.empty()) { @@ -169,7 +192,8 @@ xstring& xstring::append(const xstring& s) return *this; } -xstring& xstring::append(const xstring& s, std::size_t i) +xstring& +xstring::append(const xstring& s, std::size_t i) { if (!s.empty() && i < len) { @@ -189,7 +213,8 @@ xstring& xstring::append(const xstring& s, std::size_t i) return *this; } -xstring& xstring::append(const char *s) +xstring& +xstring::append(const char *s) { if (!strempty(s)) { @@ -200,7 +225,8 @@ xstring& xstring::append(const char *s) return *this; } -xstring& xstring::append(const char *s, std::size_t i) +xstring& +xstring::append(const char *s, std::size_t i) { if (!strempty(s) && i < len) { @@ -220,13 +246,15 @@ xstring& xstring::append(const char *s, std::size_t i) return *this; } -xstring& xstring::append(char c) +xstring& +xstring::append(char c) { push_back(c); return *this; } -void xstring::push_back(char c) +void +xstring::push_back(char c) { resize(1); str[len] = c; @@ -234,7 +262,8 @@ void xstring::push_back(char c) len = length(); } -void xstring::pop_back() +void +xstring::pop_back() { if (len - 1 > 0) { @@ -254,48 +283,57 @@ void xstring::pop_back() else return; } -void xstring::replace(std::size_t i, char c) +void +xstring::replace(std::size_t i, char c) { if (i < len) str[i] = c; } -bool xstring::find(const xstring& s) const +bool +xstring::find(const xstring& s) const { return (strstr(this->cstr(), s.cstr()) != nullptr); } -bool xstring::find(const char *s) const +bool +xstring::find(const char *s) const { return (strstr(this->cstr(), s) != nullptr); } -char *xstring::cstr() const +char * +xstring::cstr() const { return str; } -char& xstring::front() const +char& +xstring::front() const { return str[0]; } -char& xstring::back() const +char& +xstring::back() const { if (!this->empty()) return str[len-1]; else return str[0]; } -std::size_t xstring::length() const +std::size_t +xstring::length() const { return strlen(str); } -bool xstring::empty() const +bool +xstring::empty() const { return len == 0; } -void xstring::clear() +void +xstring::clear() { if (!this->empty()) delete[] str; str = new char[1]; @@ -304,7 +342,8 @@ void xstring::clear() len = 0; } -void xstring::resize(std::size_t n) +void +xstring::resize(std::size_t n) { if (!this->empty()) { @@ -317,7 +356,8 @@ void xstring::resize(std::size_t n) } } -char *xstring::conv(const char *s) const +char * +xstring::conv(const char *s) const { std::size_t l = strlen(s); char *tmp = new char[l + 1]; @@ -325,12 +365,14 @@ char *xstring::conv(const char *s) const return tmp; } -bool xstring::strempty(const char *s) const +bool +xstring::strempty(const char *s) const { return strlen(s) == 0; } -std::istream& getline(std::istream& stream, xstring& s, char delim) +std::istream& +getline(std::istream& stream, xstring& s, char delim) { char c; s.clear();