uni

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

commit a4085ca61e85ad6fa12a8ae2e57812c9e29786b2
parent 52138f3c391a49cf7442f80a60d506f6857d0acb
Author: Christos Margiolis <christos@margiolis.net>
Date:   Fri,  1 May 2020 22:19:52 +0300

removed some dynamic_cast

Diffstat:
Massignment-2.4-inheritance/bin/inheritance | 0
Massignment-2.4-inheritance/obj/app.o | 0
Massignment-2.4-inheritance/obj/appsystem.o | 0
Massignment-2.4-inheritance/obj/game.o | 0
Massignment-2.4-inheritance/obj/main.o | 0
Massignment-2.4-inheritance/obj/manufacturer.o | 0
Massignment-2.4-inheritance/obj/office.o | 0
Massignment-2.4-inheritance/obj/review.o | 0
Massignment-2.4-inheritance/src/app.h | 9++++++++-
Massignment-2.4-inheritance/src/appsystem.cpp | 9+++------
Massignment-2.4-inheritance/src/game.cpp | 2+-
Massignment-2.4-inheritance/src/game.h | 8++++----
Massignment-2.4-inheritance/src/main.cpp | 16++++++----------
Massignment-2.4-inheritance/src/office.cpp | 2+-
Massignment-2.4-inheritance/src/office.h | 5++---
Massignment-2.5-spreadsheets/bin/spreadsheets | 0
Massignment-2.5-spreadsheets/obj/main.o | 0
17 files changed, 25 insertions(+), 26 deletions(-)

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/obj/appsystem.o b/assignment-2.4-inheritance/obj/appsystem.o Binary files differ. diff --git a/assignment-2.4-inheritance/obj/game.o b/assignment-2.4-inheritance/obj/game.o Binary files differ. diff --git a/assignment-2.4-inheritance/obj/main.o b/assignment-2.4-inheritance/obj/main.o Binary files differ. diff --git a/assignment-2.4-inheritance/obj/manufacturer.o b/assignment-2.4-inheritance/obj/manufacturer.o Binary files differ. diff --git a/assignment-2.4-inheritance/obj/office.o b/assignment-2.4-inheritance/obj/office.o Binary files differ. diff --git a/assignment-2.4-inheritance/obj/review.o b/assignment-2.4-inheritance/obj/review.o Binary files differ. diff --git a/assignment-2.4-inheritance/src/app.h b/assignment-2.4-inheritance/src/app.h @@ -21,7 +21,7 @@ class App public: App(); App(const char *serialnum, const std::string& name, - const std::string& os, Manufacturer *manf, int price); + const std::string& os, Manufacturer *manf, int price); virtual ~App(); char *convsn(const char *serialnum); @@ -39,6 +39,13 @@ class App void set_os(const std::string& os); void set_manf(Manufacturer *manf); void set_price(int price); + + virtual const std::string get_genre() const {return {};} + virtual bool get_online() const {return false;} // not good + virtual void set_genre(const std::string& genre) {} + virtual void set_online(bool online) {} + virtual const std::vector<std::string> get_exts() const {return {};} + virtual void set_exts(const std::vector<std::string>& extensions) {} }; #endif /* APP_H */ diff --git a/assignment-2.4-inheritance/src/appsystem.cpp b/assignment-2.4-inheritance/src/appsystem.cpp @@ -131,24 +131,21 @@ void AppSystem::chgenre(const std::string& appname, const std::string& genre) { for (auto& app : apps) if (app->get_name() == appname) - if (Game *o = dynamic_cast<Game *>(app)) - o->set_genre(genre); + app->set_genre(genre); } void AppSystem::chonline(const std::string& appname, bool online) { for (auto& app : apps) if (app->get_name() == appname) - if (Game *o = dynamic_cast<Game *>(app)) - o->set_online(online); + app->set_online(online); } void AppSystem::chexts(const std::string& appname, const std::vector<std::string> exts) { for (auto& app : apps) if (app->get_name() == appname) - if (Office *o = dynamic_cast<Office *>(app)) - o->set_exts(exts); + app->set_exts(exts); } void AppSystem::removebad(Manufacturer *man) diff --git a/assignment-2.4-inheritance/src/game.cpp b/assignment-2.4-inheritance/src/game.cpp @@ -8,7 +8,7 @@ Game::Game(const char *serialnum, const std::string& name, const std::string& genre, bool online) :App(serialnum, name, os, manf, price), genre(genre), online(online) {} -const std::string& Game::get_genre() const +const std::string Game::get_genre() const { return genre; } diff --git a/assignment-2.4-inheritance/src/game.h b/assignment-2.4-inheritance/src/game.h @@ -15,11 +15,11 @@ class Game: public App const std::string& os, Manufacturer *manf, int price, const std::string& genre, bool online); - const std::string& get_genre() const; - bool get_online() const; + const std::string get_genre() const override; + bool get_online() const override; - void set_genre(const std::string& genre); - void set_online(bool online); + void set_genre(const std::string& genre) override; + void set_online(bool online) override; }; #endif /* GAME_H */ diff --git a/assignment-2.4-inheritance/src/main.cpp b/assignment-2.4-inheritance/src/main.cpp @@ -12,18 +12,14 @@ std::ostream& operator<< (std::ostream& stream, const AppSystem& sys) app->get_os() << " " << app->get_price() << " "; - if (Office *o = dynamic_cast<Office *>(app)) - { - std::vector<std::string> exts = o->get_exts(); + std::vector<std::string> exts = app->get_exts(); + if (!exts.empty()) for (auto& ext : exts) stream << ext << " "; - } - else if (Game *o = dynamic_cast<Game *>(app)) - { - stream << - o->get_genre() << " " << - o->get_online() << " "; - } + + stream << + app->get_genre() << " " << + app->get_online() << " "; std::vector<Review *> revs = app->get_revs(); if (!revs.empty()) diff --git a/assignment-2.4-inheritance/src/office.cpp b/assignment-2.4-inheritance/src/office.cpp @@ -13,7 +13,7 @@ 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; } diff --git a/assignment-2.4-inheritance/src/office.h b/assignment-2.4-inheritance/src/office.h @@ -15,9 +15,8 @@ class Office: public App int price, const std::vector<std::string>& ext); ~Office(); - const std::vector<std::string>& get_exts() const; - - void set_exts(const std::vector<std::string>& extensions); + const std::vector<std::string> get_exts() const override; + void set_exts(const std::vector<std::string>& extensions) override; }; #endif /* OFFICE_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/main.o b/assignment-2.5-spreadsheets/obj/main.o Binary files differ.