uni

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

commit b5c1d3969844dda3bce2a05d4525d8d78db8af5b
parent 626b8de394a92875f8299a85260a2d23108e7ded
Author: Christos Margiolis <christos@margiolis.net>
Date:   Thu, 30 Apr 2020 00:51:47 +0300

pending file read

Diffstat:
Massignment-2.4-inheritance/bin/inheritance | 0
Massignment-2.4-inheritance/obj/appsystem.o | 0
Massignment-2.4-inheritance/obj/main.o | 0
Massignment-2.4-inheritance/src/app.h | 3+--
Massignment-2.4-inheritance/src/appsystem.cpp | 43+++++++++++++++++++++++++++++++++----------
Massignment-2.4-inheritance/src/appsystem.h | 1+
Massignment-2.4-inheritance/src/main.cpp | 2+-
7 files changed, 36 insertions(+), 13 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/appsystem.o b/assignment-2.4-inheritance/obj/appsystem.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/src/app.h b/assignment-2.4-inheritance/src/app.h @@ -39,10 +39,9 @@ class App void set_manf(Manufacturer *manf); void set_price(int price); - // add some default functionality virtual const std::string& get_genre() const {} virtual bool get_online() const {} - virtual const std::vector<std::string>& get_exts() 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 @@ -1,6 +1,4 @@ #include "appsystem.h" -#include <iostream> -#include <sstream> AppSystem::AppSystem() {} @@ -33,22 +31,47 @@ AppSystem& AppSystem::operator+= (Manufacturer *man) bool AppSystem::read_data(const char *fpath) { - std::ifstream f(fpath); - std::string s; - while (f.good()) + std::ifstream f; + f.exceptions(std::ifstream::failbit | std::ifstream::badbit); + try { - std::getline(f, s, ','); - std::cout << s << std::endl; + f.open(fpath); + std::string s; + while (f.good()) + { + std::getline(f, s, ','); + } + f.close(); + } + catch (const std::ifstream::failure& e) + { + std::cerr << "Cannot read file \'" << fpath << "\'." << std::endl << + e.what() << std::endl; + return false; } + return true; } bool export_data(const char *fpath) { - std::ofstream f(fpath); - while (f.good()) + std::ofstream f; + f.exceptions(std::ofstream::failbit | std::ofstream::badbit); + try + { + f.open(fpath); + while (f.good()) + { + + } + f.close(); + } + catch (const std::ofstream::failure& e) { - + std::cerr << "Cannot read file \'" << fpath << "\'." << std::endl << + e.what() << std::endl; + return false; } + return true; } void AppSystem::newrev(const std::string& appname, Review *rev) diff --git a/assignment-2.4-inheritance/src/appsystem.h b/assignment-2.4-inheritance/src/appsystem.h @@ -3,6 +3,7 @@ #include <algorithm> #include <fstream> +#include <iostream> #include "game.h" #include "office.h" diff --git a/assignment-2.4-inheritance/src/main.cpp b/assignment-2.4-inheritance/src/main.cpp @@ -51,7 +51,7 @@ int main(int argc, char **argv) Manufacturer *cm = new Manufacturer("5678", "Chris", "chris@cm.com"); sys += gnu; sys += cm; - sys.read_data("res/data.csv"); + 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 Game("731234", "minecurses", "Linux 4.5", cm, 0, "Puzzle", false);