uni

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

commit 7f9f269f2148b12b4158cb39dc361150855e4ee8
parent a4085ca61e85ad6fa12a8ae2e57812c9e29786b2
Author: Christos Margiolis <christos@margiolis.net>
Date:   Sat,  2 May 2020 01:43:44 +0300

brought back 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/office.o | 0
Massignment-2.4-inheritance/src/app.h | 7-------
Massignment-2.4-inheritance/src/appsystem.cpp | 15+++++++++------
Massignment-2.4-inheritance/src/game.h | 8++++----
Massignment-2.4-inheritance/src/main.cpp | 21+++++++++++++--------
Massignment-2.4-inheritance/src/office.h | 4++--
11 files changed, 28 insertions(+), 27 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/office.o b/assignment-2.4-inheritance/obj/office.o Binary files differ. diff --git a/assignment-2.4-inheritance/src/app.h b/assignment-2.4-inheritance/src/app.h @@ -39,13 +39,6 @@ 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 @@ -130,22 +130,25 @@ void AppSystem::chprice(const std::string& appname, int price) void AppSystem::chgenre(const std::string& appname, const std::string& genre) { for (auto& app : apps) - if (app->get_name() == appname) - app->set_genre(genre); + if (Game *o = dynamic_cast<Game *>(app)) + if (o->get_name() == appname) + o->set_genre(genre); } void AppSystem::chonline(const std::string& appname, bool online) { for (auto& app : apps) - if (app->get_name() == appname) - app->set_online(online); + if (Game *o = dynamic_cast<Game *>(app)) + if (o->get_name() == appname) + o->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) - app->set_exts(exts); + if (Office *o = dynamic_cast<Office *>(app)) + if (o->get_name() == appname) + o->set_exts(exts); } void AppSystem::removebad(Manufacturer *man) 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 override; - bool get_online() const override; + const std::string get_genre() const; + bool get_online() const; - void set_genre(const std::string& genre) override; - void set_online(bool online) override; + void set_genre(const std::string& genre); + void set_online(bool online); }; #endif /* GAME_H */ diff --git a/assignment-2.4-inheritance/src/main.cpp b/assignment-2.4-inheritance/src/main.cpp @@ -12,14 +12,19 @@ std::ostream& operator<< (std::ostream& stream, const AppSystem& sys) app->get_os() << " " << app->get_price() << " "; - std::vector<std::string> exts = app->get_exts(); - if (!exts.empty()) - for (auto& ext : exts) - stream << ext << " "; - - stream << - app->get_genre() << " " << - app->get_online() << " "; + if (Office *o = dynamic_cast<Office *>(app)) + { + std::vector<std::string> exts = o->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() << " "; + } std::vector<Review *> revs = app->get_revs(); if (!revs.empty()) diff --git a/assignment-2.4-inheritance/src/office.h b/assignment-2.4-inheritance/src/office.h @@ -15,8 +15,8 @@ class Office: public App int price, const std::vector<std::string>& ext); ~Office(); - const std::vector<std::string> get_exts() const override; - void set_exts(const std::vector<std::string>& extensions) override; + const std::vector<std::string> get_exts() const; + void set_exts(const std::vector<std::string>& extensions); }; #endif /* OFFICE_H */