uni

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

commit e6cfb4e1252308c19aaee5261a0c1365622def98
parent 4e68566c991af6d3891351aa68fb8f387ce1f7f8
Author: Christos Margiolis <christos@margiolis.net>
Date:   Fri, 12 Jun 2020 16:20:56 +0300

more error checks

Diffstat:
Massignment-2.4-inheritance/bin/inheritance | 0
Massignment-2.4-inheritance/obj/app.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/obj/review.o | 0
Massignment-2.4-inheritance/src/app.cpp | 2++
Massignment-2.4-inheritance/src/appsystem.hpp | 11++++++++++-
Massignment-2.4-inheritance/src/game.cpp | 2+-
Massignment-2.4-inheritance/src/main.cpp | 5+++++
Massignment-2.4-inheritance/src/office.cpp | 3++-
Massignment-2.4-inheritance/src/review.cpp | 4++++
Massignment-2.5-spreadsheets/obj/datahandler.o | 0
Massignment-2.5-spreadsheets/obj/errlog.o | 0
Massignment-2.5-spreadsheets/obj/main.o | 0
Massignment-2.5-spreadsheets/obj/xstring.o | 0
16 files changed, 24 insertions(+), 3 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/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/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 @@ -13,6 +13,8 @@ App::App(const char *serialnum, const std::string& name, errlog.write("App: " + std::string(serialnum) + ": Missing app name"); if (os.empty()) errlog.write("App: " + std::string(serialnum) + ": Missing OS version"); + if (manf == nullptr) + errlog.write("App: " + std::string(serialnum) + ": Missing Manufacturer"); if (price < 0) errlog.write("App: " + std::string(serialnum) + ": Negative price"); } diff --git a/assignment-2.4-inheritance/src/appsystem.hpp b/assignment-2.4-inheritance/src/appsystem.hpp @@ -177,7 +177,11 @@ AppSystem::import_data(const char *fpath) } catch (const std::ifstream::failure& e) { - errlog.write(err_read(fpath) + " (" + e.what() + ")"); + /* + * We terminate because there's no point in continuing if + * the file is corrupted + */ + throw std::runtime_error(err_read(fpath) + " (" + e.what() + ")"); } } @@ -248,6 +252,11 @@ AppSystem::export_data(const char *fpath) } catch (const std::ofstream::failure& e) { + /* + * In this case we don't terminate because the output + * file is not to be used by the program later, so + * we shouldn't lose all progress. + */ errlog.write(err_write(fpath) + " (" + e.what() + ")"); } } 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, const bool online) :App(serialnum, name, os, manf, price), genre(genre), online(online) { - if (genre.empty() || genre == "") + if (genre.empty()) errlog.write("Game: " + std::string(serialnum) + ": Empty genre"); } diff --git a/assignment-2.4-inheritance/src/main.cpp b/assignment-2.4-inheritance/src/main.cpp @@ -12,6 +12,11 @@ static void getapps(const AppSystem& sys); * main uses smart pointers just so I don't have to delete * them manually. There's obviously no good reason to do it * as there's only one object, but it looks cool. + * + * I also used some features that might make the program harder + * to understand, but I wanted to take a chance and try out some of + * these features, for fun mainly, even though they might seem + * (and be) useless. */ int main(int argc, char **argv) diff --git a/assignment-2.4-inheritance/src/office.cpp b/assignment-2.4-inheritance/src/office.cpp @@ -8,7 +8,8 @@ Office::Office(const char *serialnum, const std::string& name, :App(serialnum, name, os, manf, price), extensions(ext) {} Office::Office(const Office& of) - :App(of.serialnum, of.name, of.os, of.manf, of.price) {} + :App(of.serialnum, of.name, of.os, of.manf, of.price), + extensions(of.extensions) {} Office::~Office() { diff --git a/assignment-2.4-inheritance/src/review.cpp b/assignment-2.4-inheritance/src/review.cpp @@ -7,6 +7,10 @@ Review::Review(const int stars, const std::string& username, const std::string& comment) :stars(stars), username(username), comment(comment) { + if (username.empty()) + errlog.write("Missing username"); + if (comment.empty()) + errlog.write("Missing comment"); if (stars < 0 || stars > 5) errlog.write("Review from: " + username + ": Star value out of bounds"); } diff --git a/assignment-2.5-spreadsheets/obj/datahandler.o b/assignment-2.5-spreadsheets/obj/datahandler.o Binary files differ. diff --git a/assignment-2.5-spreadsheets/obj/errlog.o b/assignment-2.5-spreadsheets/obj/errlog.o 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/obj/xstring.o b/assignment-2.5-spreadsheets/obj/xstring.o Binary files differ.