uni

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

commit 9c2c18b91edee63ae1c2b71bd186ff0eef7fb343
parent b5c1d3969844dda3bce2a05d4525d8d78db8af5b
Author: Christos Margiolis <christos@margiolis.net>
Date:   Thu, 30 Apr 2020 04:17:56 +0300

pending file read

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/res/data.csv | 13++++++++++---
Aassignment-2.4-inheritance/res/output.csv | 0
Massignment-2.4-inheritance/src/app.cpp | 7+++++++
Massignment-2.4-inheritance/src/app.h | 5+----
Massignment-2.4-inheritance/src/appsystem.cpp | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Massignment-2.4-inheritance/src/appsystem.h | 22++++++++++++++--------
Massignment-2.4-inheritance/src/game.cpp | 10++++++++++
Massignment-2.4-inheritance/src/game.h | 7+++++--
Massignment-2.4-inheritance/src/main.cpp | 18++++++++++++++----
Massignment-2.4-inheritance/src/manufacturer.cpp | 17+++++++++++++++++
Massignment-2.4-inheritance/src/manufacturer.h | 4++++
Massignment-2.4-inheritance/src/office.cpp | 11+++++++++++
Massignment-2.4-inheritance/src/office.h | 5++++-
Massignment-2.4-inheritance/src/review.cpp | 15+++++++++++++++
Massignment-2.4-inheritance/src/review.h | 6+++++-
Massignment-2.5-spreadsheets/res/courses.csv | 3+--
24 files changed, 209 insertions(+), 37 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/res/data.csv b/assignment-2.4-inheritance/res/data.csv @@ -1,4 +1,11 @@ SerialNum,Name,Email -12313,"GNU","gnu@gnu.com" -12313,"GNU","gnu@gnu.com" -12313,"GNU","gnu@gnu.com" +0001,GNU,gnu@gnu.com +0002,Chris,chris@chris.com +0003,John,john@john.com +0004,Ok,ok@ok.com +0005,Aa,aa@aa.com +0006,Lol,lol@lol.com +0007,XD,xd@xd.com +0008,Bruh,bruh@bruh.com +0009,Retard,ret@ret.com +0010,Nice,nice@nice.com diff --git a/assignment-2.4-inheritance/res/output.csv b/assignment-2.4-inheritance/res/output.csv diff --git a/assignment-2.4-inheritance/src/app.cpp b/assignment-2.4-inheritance/src/app.cpp @@ -11,6 +11,7 @@ App::App(const char *serialnum, const std::string& name, App::~App() { if (serialnum != nullptr) delete[] serialnum; + if (!reviews.empty()) reviews.clear(); } char *App::convsn(const char *serialnum) @@ -56,6 +57,12 @@ int App::get_price() const return price; } +void App::set_serialnum(const char *serialnum) +{ + if (this->serialnum != nullptr) delete[] serialnum; + this->serialnum = convsn(serialnum); +} + void App::set_name(const std::string& name) { this->name = name; diff --git a/assignment-2.4-inheritance/src/app.h b/assignment-2.4-inheritance/src/app.h @@ -34,14 +34,11 @@ class App const std::vector<Review *>& get_revs() const; int get_price() const; + void set_serialnum(const char *serialnum); void set_name(const std::string& name); void set_os(const std::string& os); void set_manf(Manufacturer *manf); void set_price(int price); - - virtual const std::string& get_genre() const {} - virtual bool get_online() const {} - virtual const std::vector<std::string>& get_exts() const {} }; #endif /* APP_H */ diff --git a/assignment-2.4-inheritance/src/appsystem.cpp b/assignment-2.4-inheritance/src/appsystem.cpp @@ -32,42 +32,53 @@ AppSystem& AppSystem::operator+= (Manufacturer *man) bool AppSystem::read_data(const char *fpath) { std::ifstream f; - f.exceptions(std::ifstream::failbit | std::ifstream::badbit); + // bug??? + //f.exceptions(std::ifstream::failbit | std::ifstream::badbit); try { - f.open(fpath); - std::string s; - while (f.good()) + f.open(fpath, std::ios::in); + if (f.is_open()) { - std::getline(f, s, ','); + std::string skip; + std::getline(f, skip); + while (f.good()) + { + std::string sn, name, email; + std::getline(f, sn, ','); + std::getline(f, name, ','); + std::getline(f, email, ','); + if (f.eof()) break; + std::cout << sn << " " << name << " " << email << std::endl; + manfs.push_back(new Manufacturer(sn.c_str(), name.c_str(), email)); + } } f.close(); } catch (const std::ifstream::failure& e) { - std::cerr << "Cannot read file \'" << fpath << "\'." << std::endl << + std::cerr << "Error reading file \'" << fpath << "\'." << std::endl << e.what() << std::endl; return false; } return true; } -bool export_data(const char *fpath) +bool AppSystem::export_data(const char *fpath) { std::ofstream f; f.exceptions(std::ofstream::failbit | std::ofstream::badbit); try { f.open(fpath); - while (f.good()) - { + //while (f.good()) + //{ - } + //} f.close(); } catch (const std::ofstream::failure& e) { - std::cerr << "Cannot read file \'" << fpath << "\'." << std::endl << + std::cerr << "Error writing to file \'" << fpath << "\'." << std::endl << e.what() << std::endl; return false; } @@ -85,7 +96,7 @@ void AppSystem::chserialnum(const std::string& appname, const char *serialnum) { for (auto& app : apps) if (app->get_name() == appname) - app->convsn(serialnum); + app->set_serialnum(serialnum); } void AppSystem::chname(const std::string& appname, const std::string& name) @@ -116,6 +127,30 @@ void AppSystem::chprice(const std::string& appname, int price) app->set_price(price); } +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); +} + +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); +} + +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); +} + void AppSystem::removebad(Manufacturer *man) { apps.erase(std::remove_if(apps.begin(), apps.end(), [&](App *app) @@ -127,6 +162,50 @@ void AppSystem::removebad(Manufacturer *man) }), apps.end()); } +void AppSystem::removebad(const char *manfname) +{ + apps.erase(std::remove_if(apps.begin(), apps.end(), [&](App *app) + { + Manufacturer m = app->get_manf(); + if (strcmp(m.get_name(), manfname) == 0) + delete app; + return strcmp(m.get_name(), manfname) == 0; + }), apps.end()); +} + +const std::vector<Office *> AppSystem::get_freeapps() const +{ + std::vector<Office *> fapps; + for (auto& app : apps) + if (Office *o = dynamic_cast<Office *>(app)) + if (o->get_price() == 0) + fapps.push_back(o); + return fapps; +} + +const std::vector<Game *> AppSystem::get_goodgames() const +{ + std::vector<Game *> ggames; + for (auto& app : apps) + { + if (Game *o = dynamic_cast<Game *>(app)) + { + std::vector<Review *> revs = o->get_revs(); + int sum = 0, count = 0; + for (auto& rev : revs) + { + if (rev->get_stars() > 4) + { + sum += rev->get_stars(); + count++; + } + } + if (sum / count > 4) ggames.push_back(o); + } + } + return ggames; +} + const std::vector<App *>& AppSystem::get_apps() const { return apps; diff --git a/assignment-2.4-inheritance/src/appsystem.h b/assignment-2.4-inheritance/src/appsystem.h @@ -20,18 +20,24 @@ class AppSystem AppSystem& operator+= (App *app); AppSystem& operator+= (Manufacturer *manf); - bool read_data(const char *fpath); + bool read_data (const char *fpath); bool export_data(const char *fpath); - void newrev(const std::string& appname, Review *rev); + void newrev (const std::string& appname, Review *rev); void chserialnum(const std::string& appname, const char *serialnum); - void chname(const std::string& appname, const std::string& name); - void chos(const std::string& appname, const std::string& os); - void chmanf(const std::string& appname, Manufacturer *manf); - void chprice(const std::string& appname, int price); - void removebad(Manufacturer *man); + void chname (const std::string& appname, const std::string& name); + void chos (const std::string& appname, const std::string& os); + void chmanf (const std::string& appname, Manufacturer *manf); + void chprice (const std::string& appname, int price); + void chgenre (const std::string& appname, const std::string& genre); + void chonline (const std::string& appname, bool online); + void chexts (const std::string& appname, const std::vector<std::string> exts); + void removebad (Manufacturer *man); + void removebad (const char *manfname); + const std::vector<Office *> get_freeapps() const; + const std::vector<Game *> get_goodgames() const; const std::vector<App *>& get_apps() const; - const std::vector<Manufacturer *>& get_manfs() const; + const std::vector<Manufacturer *>& get_manfs() const; }; #endif /* APPSYSTEM_H */ diff --git a/assignment-2.4-inheritance/src/game.cpp b/assignment-2.4-inheritance/src/game.cpp @@ -17,3 +17,13 @@ bool Game::get_online() const { return online; } + +void Game::set_genre(const std::string& genre) +{ + this->genre = genre; +} + +void Game::set_online(bool online) +{ + this->online = online; +} diff --git a/assignment-2.4-inheritance/src/game.h b/assignment-2.4-inheritance/src/game.h @@ -15,8 +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); + 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 @@ -1,5 +1,5 @@ -#include "appsystem.h" #include <iostream> +#include "appsystem.h" std::ostream& operator<< (std::ostream& stream, const AppSystem& sys) { @@ -53,14 +53,24 @@ int main(int argc, char **argv) sys += cm; if (!sys.read_data("res/data.csv")) return -1; std::vector<std::string> ext = {".doc", ".xls", ".ppt"}; - sys += new Office("132456", "LibreOffice", "Linux 2.2", gnu, 15, ext); + sys += new Office("132456", "LibreOffice", "Linux 2.2", gnu, 0, ext); sys += new Game("731234", "minecurses", "Linux 4.5", cm, 0, "Puzzle", false); + + Review rev(6, "Name Surnaming", "Good"); + sys.newrev("minecurses", &rev); std::cout << sys << std::endl; sys.removebad(cm); - Review rev(4, "Name Naming", "Very good"); - sys.newrev("LibreOffice", &rev); std::cout << sys << std::endl; + std::vector<Office *> fapps = sys.get_freeapps(); + std::vector<Game *> ggames = sys.get_goodgames(); + for (auto& fapp : fapps) + std::cout << fapp->get_name() << std::endl; + for (auto& ggame : ggames) + std::cout << ggame->get_name() << std::endl; + + if (!sys.export_data("res/output.csv")) return -1; + return 0; } diff --git a/assignment-2.4-inheritance/src/manufacturer.cpp b/assignment-2.4-inheritance/src/manufacturer.cpp @@ -38,3 +38,20 @@ const std::string& Manufacturer::get_email() const { return email; } + +void Manufacturer::set_serialnum(const char *serialnum) +{ + if (this->serialnum != nullptr) delete[] serialnum; + this->serialnum = convstr(serialnum); +} + +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) +{ + this->email = email; +} diff --git a/assignment-2.4-inheritance/src/manufacturer.h b/assignment-2.4-inheritance/src/manufacturer.h @@ -23,6 +23,10 @@ class Manufacturer const char *get_serialnum() const; const char *get_name() const; const std::string& get_email() const; + + void set_serialnum(const char *serialnum); + void set_name(const char *name); + void set_email(const std::string& email); }; #endif /* MANUFACTURER_H */ diff --git a/assignment-2.4-inheritance/src/office.cpp b/assignment-2.4-inheritance/src/office.cpp @@ -8,7 +8,18 @@ Office::Office(const char *serialnum, const std::string& name, int price, const std::vector<std::string>& ext) :App(serialnum, name, os, manf, price), extensions(ext) {} +Office::~Office() +{ + if (!extensions.empty()) extensions.clear(); +} + const std::vector<std::string>& Office::get_exts() const { return extensions; } + +void Office::set_exts(const std::vector<std::string>& extensions) +{ + if (!this->extensions.empty()) this->extensions.clear(); + this->extensions = extensions; +} diff --git a/assignment-2.4-inheritance/src/office.h b/assignment-2.4-inheritance/src/office.h @@ -13,8 +13,11 @@ class Office: public App Office(const char *serialnum, const std::string& name, const std::string& os, Manufacturer *manf, int price, const std::vector<std::string>& ext); + ~Office(); - const std::vector<std::string>& get_exts() const override; + const std::vector<std::string>& get_exts() const; + + void set_exts(const std::vector<std::string>& extensions); }; #endif /* OFFICE_H */ diff --git a/assignment-2.4-inheritance/src/review.cpp b/assignment-2.4-inheritance/src/review.cpp @@ -20,3 +20,18 @@ const std::string& Review::get_comment() const { return comment; } + +void Review::set_stars(int stars) +{ + this->stars = stars; +} + +void Review::set_username(const std::string& username) +{ + this->username = username; +} + +void Review::set_comment(const std::string& comment) +{ + this->comment = comment; +} diff --git a/assignment-2.4-inheritance/src/review.h b/assignment-2.4-inheritance/src/review.h @@ -14,9 +14,13 @@ class Review Review(); Review(int stars, const std::string& username, const std::string& comment); - int get_stars() const; + int get_stars() const; const std::string& get_username() const; const std::string& get_comment() const; + + void set_stars(int stars); + void set_username(const std::string& username); + void set_comment(const std::string& comment); }; #endif /* REVIEW_H */ diff --git a/assignment-2.5-spreadsheets/res/courses.csv b/assignment-2.5-spreadsheets/res/courses.csv @@ -177,4 +177,4 @@ P1-9325,ΚΑΤΑΝΕΜΗΜΕΝΑ ΣΥΣΤΗΜΑΤΑ P1-9330,ΒΕΛΤΙΣΤΟΠΟΙΗΣΗ P1-9335,ΠΟΛΥΜΕΣΑ ΚΑΙ ΠΟΛΥΜΕΣΙΚΕΣ ΕΠΙΚΟΙΝΩΝΙΕΣ P1-9340,ΕΥΡΥΖΩΝΙΚΑ ΔΙΚΤΥΑ -P1-9350,ΤΕΧΝΟΛΟΓΙΑ ΚΑΙ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ ΚΙΝΗΤΩΝ ΣΥΣΚΕΥΩΝ- \ No newline at end of file +P1-9350,ΤΕΧΝΟΛΟΓΙΑ ΚΑΙ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ ΚΙΝΗΤΩΝ ΣΥΣΚΕΥΩΝ