uni

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

commit a361ec2ba080e3fc19492a0790a07000fff6d784
parent 8583e8bc02ff7d10e5f977604e07ae7ee002faf0
Author: Christos Margiolis <christos@margiolis.net>
Date:   Thu,  4 Jun 2020 02:06:46 +0300

details fix

Diffstat:
Massignment-2.2-classes/classes.cpp | 40+++++++++++++++++++++++++++++++++++-----
Dassignment-2.4-inheritance/bin/inheritance | 0
Dassignment-2.4-inheritance/obj/app.o | 0
Dassignment-2.4-inheritance/obj/appsystem.o | 0
Dassignment-2.4-inheritance/obj/game.o | 0
Dassignment-2.4-inheritance/obj/main.o | 0
Dassignment-2.4-inheritance/obj/manufacturer.o | 0
Dassignment-2.4-inheritance/obj/office.o | 0
Dassignment-2.4-inheritance/obj/review.o | 0
Massignment-2.4-inheritance/src/app.cpp | 6+++---
Massignment-2.4-inheritance/src/app.h | 8++++----
Massignment-2.4-inheritance/src/appsystem.cpp | 12+++++++-----
Massignment-2.4-inheritance/src/appsystem.h | 25++++++++++++++++---------
Massignment-2.4-inheritance/src/game.h | 8++++----
Massignment-2.4-inheritance/src/main.cpp | 3+--
Massignment-2.4-inheritance/src/manufacturer.h | 2+-
Massignment-2.4-inheritance/src/office.h | 4++--
Massignment-2.4-inheritance/src/review.cpp | 4++--
Massignment-2.4-inheritance/src/review.h | 8++++----
19 files changed, 79 insertions(+), 41 deletions(-)

diff --git a/assignment-2.2-classes/classes.cpp b/assignment-2.2-classes/classes.cpp @@ -25,10 +25,10 @@ class Student ~Student(); const std::string& get_name() const; - constexpr const char *get_id() const {return this->id;} - constexpr unsigned int get_semester() const {return this->semester;} - constexpr unsigned int get_pcourses() const {return this->pcourses;} - constexpr float *get_grades() const {return this->grades;} + constexpr const char *get_id() const; + constexpr const unsigned int get_semester() const; + constexpr const unsigned int get_pcourses() const; + constexpr float *get_grades() const; void set_id (const char *id); void set_name (const std::string& name); @@ -42,7 +42,7 @@ class Student private: template<typename T> T *conv(const T *arr, std::size_t len) const; template<typename T> T *resize(const T *arr, std::size_t len); - constexpr std::size_t len(const char *s) const {return std::strlen(s) + 1;} + constexpr std::size_t len(const char *s) const; float avg() const; }; @@ -88,6 +88,30 @@ Student::get_name() const return this->name; } +constexpr const char * +Student::get_id() const +{ + return this->id; +} + +constexpr const unsigned int +Student::get_semester() const +{ + return this->semester; +} + +constexpr const unsigned int +Student::get_pcourses() const +{ + return this->pcourses; +} + +constexpr float * +Student::get_grades() const +{ + return this->grades; +} + void Student::set_id(const char *id) { @@ -142,6 +166,12 @@ Student::detailed_print() const } } +constexpr std::size_t +Student::len(const char *s) const +{ + return std::strlen(s) + 1; +} + float Student::avg() const { 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.cpp b/assignment-2.4-inheritance/src/app.cpp @@ -17,9 +17,9 @@ App::App(const char *serialnum, const std::string& name, throw std::runtime_error("Price can't have negative value."); } -App::App(const App& a) - :serialnum(a.serialnum), name(a.name), os(a.os), manf(a.manf), - price(a.price) {} +App::App(const App& app) + :serialnum(app.serialnum), name(app.name), os(app.os), manf(app.manf), + price(app.price) {} App::~App() { diff --git a/assignment-2.4-inheritance/src/app.h b/assignment-2.4-inheritance/src/app.h @@ -24,7 +24,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); App(const App& app); virtual ~App(); @@ -34,16 +34,16 @@ class App const std::string& get_name() const {return name;} const std::string& get_os() const {return os;} - const Manufacturer get_manf() const {return Manufacturer(*manf);} + constexpr const Manufacturer& get_manf() const {return *manf;} constexpr const char *get_serialnum() const {return serialnum;} constexpr const std::vector<Review *>& get_revs() const {return reviews;} - constexpr int get_price() const {return price;} + constexpr const int get_price() const {return price;} void set_serialnum(const char *serialnum); void set_name(const std::string& name) {this->name = name;} void set_os(const std::string& os) {this->os = os;} void set_manf(Manufacturer *manf) {this->manf = manf;} - void set_price(int price) {this->price = price;} + void set_price(const int price) {this->price = price;} virtual void print(std::ostream& stream) const = 0; diff --git a/assignment-2.4-inheritance/src/appsystem.cpp b/assignment-2.4-inheritance/src/appsystem.cpp @@ -9,14 +9,16 @@ AppSystem::~AppSystem() AppSystem& AppSystem::operator+= (App *app) { - apps.push_back(app); + if (!exists<App>(apps, app)) apps.push_back(app); + else throw std::logic_error("App exists already."); return *this; } AppSystem& -AppSystem::operator+= (Manufacturer *man) +AppSystem::operator+= (Manufacturer *manf) { - manfs.push_back(man); + if (!exists<Manufacturer>(manfs, manf)) manfs.push_back(manf); + else throw std::logic_error("Manufacturer exists already."); return *this; } @@ -32,7 +34,7 @@ AppSystem::parse_office_exts(std::ifstream& f) } void -AppSystem::write_office_exts(Office *of, std::ofstream& f) +AppSystem::write_office_exts(const Office *of, std::ofstream& f) { std::vector<std::string> exts = of->get_exts(); for (const auto& ext : exts) @@ -40,7 +42,7 @@ AppSystem::write_office_exts(Office *of, std::ofstream& f) } void -AppSystem::removebad(Manufacturer *man) +AppSystem::removebad(const Manufacturer *man) { apps.erase(std::remove_if(apps.begin(), apps.end(), [&](App *app) { diff --git a/assignment-2.4-inheritance/src/appsystem.h b/assignment-2.4-inheritance/src/appsystem.h @@ -26,14 +26,14 @@ class AppSystem template<typename T> bool export_data(const char *fpath); template<typename T> void call( const std::string& appname, - T element, - void(App::*func)(T)); + const T element, + void (App::*func)(T)); template<typename T, class U> void cast_call( const std::string& appname, - T element, - void(U::*func)(T)); - void removebad (Manufacturer *man); - void removebad (const char *manfname); + const T element, + void (U::*func)(T)); + void removebad(const Manufacturer *man); + void removebad(const char *manfname); constexpr const std::vector<App *>& get_apps() const {return apps;} constexpr const std::vector<Manufacturer *>& get_manfs() const {return manfs;} @@ -41,11 +41,12 @@ class AppSystem const std::vector<Game *> get_goodgames() const; private: + template<typename T> bool exists(const std::vector<T *>& vec, const T *element); template<typename T> bool parse(std::ifstream& f); const std::vector<std::string> parse_office_exts(std::ifstream& f); const std::vector<Review *> parse_reviews(const std::string& appname, const char *rpath); - void write_office_exts(Office *of, std::ofstream& f); + void write_office_exts(const Office *of, std::ofstream& f); bool valid_path(const std::string& strpath); const std::string err_csv(const std::string& strpath); const std::string err_read(const std::string& strpath); @@ -256,8 +257,14 @@ AppSystem::export_data(const char *fpath) return true; } +template<typename T> bool +AppSystem::exists(const std::vector<T *>& vec, const T *element) +{ + return std::find(vec.begin(), vec.end(), element) != vec.end(); +} + template<typename T> void -AppSystem::call(const std::string& appname, T element, void(App::*func)(T)) +AppSystem::call(const std::string& appname, const T element, void (App::*func)(T)) { for (auto&& app : apps) if (app->get_name() == appname) @@ -265,7 +272,7 @@ AppSystem::call(const std::string& appname, T element, void(App::*func)(T)) } template<typename T, class U> void -AppSystem::cast_call(const std::string& appname, T element, void(U::*func)(T)) +AppSystem::cast_call(const std::string& appname, const T element, void (U::*func)(T)) { for (auto&& app : apps) if (U *o = dynamic_cast<U *>(app)) diff --git a/assignment-2.4-inheritance/src/game.h b/assignment-2.4-inheritance/src/game.h @@ -12,14 +12,14 @@ class Game final: public App public: Game(); Game(const char *serialnum, const std::string& name, - const std::string& os, Manufacturer *manf, int price, - const std::string& genre, bool online); + const std::string& os, Manufacturer *manf, int price, + const std::string& genre, bool online); Game(const Game& g); const std::string get_genre() const {return genre;} - constexpr bool get_online() const {return online;} + constexpr const bool get_online() const {return online;} void set_genre(const std::string& genre) {this->genre = genre;} - void set_online(bool online) {this->online = online;} + void set_online(const bool online) {this->online = online;} void print(std::ostream& stream) const override; }; diff --git a/assignment-2.4-inheritance/src/main.cpp b/assignment-2.4-inheritance/src/main.cpp @@ -78,8 +78,7 @@ pluseqs(AppSystem& sys) Manufacturer *chris = new Manufacturer("0005", "Chris", "chris@chris.com"); sys += comp; sys += chris; - std::vector<std::string> ext = {".pdf", ".md"}; - sys += new Office("0004", "zathura", "NiceOS 1.1", comp, 0, ext); + sys += new Office("0004", "zathura", "NiceOS 1.1", comp, 0, {".pdf", ".md"}); sys += new Game("0005", "minecurses", "NiceOS 0.5", chris, 0, "Puzzle", false); } diff --git a/assignment-2.4-inheritance/src/manufacturer.h b/assignment-2.4-inheritance/src/manufacturer.h @@ -15,7 +15,7 @@ class Manufacturer public: Manufacturer(); Manufacturer(const char *serialnum, const char *name, - const std::string& email); + const std::string& email); Manufacturer(const Manufacturer& m); ~Manufacturer(); diff --git a/assignment-2.4-inheritance/src/office.h b/assignment-2.4-inheritance/src/office.h @@ -11,8 +11,8 @@ class Office final: public App public: Office(); Office(const char *serialnum, const std::string& name, - const std::string& os, Manufacturer *manf, - int price, const std::vector<std::string>& ext); + const std::string& os, Manufacturer *manf, + int price, const std::vector<std::string>& ext); Office(const Office& o); ~Office(); diff --git a/assignment-2.4-inheritance/src/review.cpp b/assignment-2.4-inheritance/src/review.cpp @@ -10,5 +10,5 @@ Review::Review(int stars, const std::string& username, const std::string& commen throw std::runtime_error("Wrong star value. Must be in [0, 5]"); } -Review::Review(const Review& r) - :stars(r.stars), username(r.username), comment(r.comment) {} +Review::Review(const Review& rev) + :stars(rev.stars), username(rev.username), comment(rev.comment) {} diff --git a/assignment-2.4-inheritance/src/review.h b/assignment-2.4-inheritance/src/review.h @@ -14,14 +14,14 @@ class Review public: Review(); Review(int stars, const std::string& username, - const std::string& comment); - Review(const Review& r); + const std::string& comment); + Review(const Review& rev); const std::string& get_username() const {return username;} const std::string& get_comment() const {return comment;} - constexpr int get_stars() const {return stars;} + constexpr const int get_stars() const {return stars;} - void set_stars(int stars) {this->stars = stars;} + void set_stars(const int stars) {this->stars = stars;} void set_username(const std::string& username) {this->username = username;} void set_comment(const std::string& comment)