uni

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

commit 5db9bc0d12ffae108f3f29af800bb9606410f84c
parent a361ec2ba080e3fc19492a0790a07000fff6d784
Author: Christos Margiolis <christos@margiolis.net>
Date:   Thu,  4 Jun 2020 03:58:46 +0300

added some smart pointers

Diffstat:
Massignment-2.2-classes/classes.cpp | 26++++++++++++--------------
Massignment-2.3-operoverloading/bin/operoverloading | 0
Massignment-2.3-operoverloading/obj/main.o | 0
Massignment-2.3-operoverloading/src/main.cpp | 37++++++++++++++++---------------------
Aassignment-2.4-inheritance/bin/inheritance | 0
Aassignment-2.4-inheritance/obj/app.o | 0
Aassignment-2.4-inheritance/obj/appsystem.o | 0
Aassignment-2.4-inheritance/obj/game.o | 0
Aassignment-2.4-inheritance/obj/main.o | 0
Aassignment-2.4-inheritance/obj/manufacturer.o | 0
Aassignment-2.4-inheritance/obj/office.o | 0
Aassignment-2.4-inheritance/obj/review.o | 0
Massignment-2.4-inheritance/src/main.cpp | 31++++++++++++++++---------------
Massignment-2.5-spreadsheets/bin/spreadsheets | 0
Massignment-2.5-spreadsheets/obj/main.o | 0
Massignment-2.5-spreadsheets/src/main.cpp | 15++++++++-------
16 files changed, 52 insertions(+), 57 deletions(-)

diff --git a/assignment-2.2-classes/classes.cpp b/assignment-2.2-classes/classes.cpp @@ -1,7 +1,8 @@ +#include <algorithm> #include <cstring> #include <iostream> #include <iomanip> -#include <algorithm> +#include <memory> #include <string> class Student @@ -224,28 +225,26 @@ static void addgrd(Student& s3); int main(int argc, char **argv) { - Student *s1 = new Student("12345678", std::string("Name Surname")); + std::unique_ptr<Student> s1 = + std::make_unique<Student>("12345678", std::string("Name Surname")); system("clear || cls"); constructor1(*s1); cont(); ostream_overload(*s1); cont(); - delete s1; - Student *s2 = new Student("92345678", std::string("Name Surnamington"), 2); + std::unique_ptr<Student> s2 = + std::make_unique<Student>("92345678", std::string("Name Surnamington"), 2); constructor2(*s2); cont(); - Student *copystud = new Student(*s2); + std::unique_ptr<Student> copystud = std::make_unique<Student>(*s2); copy_constructor(*copystud); cont(); - delete copystud; - delete s2; - float *grd = new float[4]{9.4f, 8.4f, 5.5f, 6.3f}; - Student *s3 = new Student("72345678", std::string("Name Surnaming"), 2, 4, grd); - delete[] grd; + std::unique_ptr<float[]> grd(new float[4]{9.4f, 8.4f, 5.5f, 6.3f}); + std::unique_ptr<Student> s3 = + std::make_unique<Student>("72345678", std::string("Name Surnaming"), 2, 4, grd.get()); constructor3(*s3); cont(); detprint(*s3); cont(); setters(*s3); addgrd(*s3); cont(); - delete s3; return 0; } @@ -345,9 +344,8 @@ setters(Student& s3) s3.set_name("AAAA"); s3.set_semester(100); s3.set_pcourses(2); - float *gg = new float[2]{0.1f, 2.2f}; - s3.set_grades(gg); - delete[] gg; + std::unique_ptr<float> gg(new float[2]{0.1f, 2.2f}); + s3.set_grades(gg.get()); std::cout << "Setters example using s3" << std::endl; std::cout << "----------------------------" << std::endl; diff --git a/assignment-2.3-operoverloading/bin/operoverloading b/assignment-2.3-operoverloading/bin/operoverloading Binary files differ. diff --git a/assignment-2.3-operoverloading/obj/main.o b/assignment-2.3-operoverloading/obj/main.o Binary files differ. diff --git a/assignment-2.3-operoverloading/src/main.cpp b/assignment-2.3-operoverloading/src/main.cpp @@ -1,3 +1,4 @@ +#include <memory> #include "student.h" static std::ostream& operator<< (std::ostream& stream, const Student& s); @@ -20,42 +21,37 @@ static void setters(Course& c); int main(int argc, char **argv) { - Student *s1 = new Student("12345678", std::string("Name Surname")); + std::unique_ptr<Student> s1 = + std::make_unique<Student>("12345678", std::string("Name Surname")); system("clear || cls"); constructor1(*s1); cont(); ostream_overload(*s1); cont(); - Student *s2 = new Student("92345678", std::string("Name Surnamington"), 2); + std::unique_ptr<Student> s2 = + std::make_unique<Student>("92345678", std::string("Name Surnamington"), 2); constructor2(*s2); cont(); - Student *copystud = new Student(*s2); + std::unique_ptr<Student> copystud = std::make_unique<Student>(*s2); copy_constructor(*copystud); cont(); conditional_overload(*s1, *s2, *copystud); cont(); equals_overload(*s1, *s2); cont(); - delete s1; - delete copystud; - delete s2; - float *grd = new float[4]{9.4f, 8.4f, 5.5f, 6.3f}; - Student *s3 = new Student("72345678", std::string("Name Surnaming"), 2, 4, grd); - delete[] grd; + std::unique_ptr<float[]> grd(new float[4]{9.4f, 8.4f, 5.5f, 6.3f}); + std::unique_ptr<Student> s3 = std::make_unique<Student>("72345678", + std::string("Name Surnaming"), 2, 4, grd.get()); constructor3(*s3); cont(); detprint(*s3); cont(); setters(*s3); addgrd(*s3); cont(); submcourses(*s3); cont(); - Student *s4 = new Student(*s3); - - Course *oop = new Course(std::string("356431"), std::string("OOP"), 2); - plusequals_overload(*s3, oop); cont(); + std::unique_ptr<Student> s4 = std::make_unique<Student>(*s3); + std::unique_ptr<Course> oop = + std::make_unique<Course>(std::string("356431"), std::string("OOP"), 2); + plusequals_overload(*s3, oop.get()); cont(); getters(*oop); cont(); setters(*oop); - delete s4; - delete s3; - delete oop; - return 0; } @@ -180,9 +176,8 @@ setters(Student& s3) s3.set_name("AAAA"); s3.set_semester(100); s3.set_pcourses(2); - float *gg = new float[2]{0.1f, 2.2f}; - s3.set_grades(gg); - delete[] gg; + std::unique_ptr<float[]> gg(new float[2]{0.1f, 2.2f}); + s3.set_grades(gg.get()); std::cout << "Setters example using s3" << std::endl; std::cout << "----------------------------" << std::endl; @@ -234,7 +229,7 @@ submcourses(Student& s3) { Course *a = new Course(std::string("11231"), std::string("Discrete Math"), 1); Course *b = new Course(std::string("56562"), std::string("Physics"), 1); - Course **c = new Course *[2]{a, b}; + Course *c[] = {a, b}; s3.set_num_submitted_courses(2); s3.set_submitted_courses(c); 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/main.cpp b/assignment-2.4-inheritance/src/main.cpp @@ -1,3 +1,4 @@ +#include <memory> #include "appsystem.h" std::ostream& operator<< (std::ostream& stream, const AppSystem& sys); @@ -10,34 +11,34 @@ static void getapps(const AppSystem& sys); int main(int argc, char **argv) { - AppSystem sys; + std::unique_ptr<AppSystem> sys = std::make_unique<AppSystem>(); system("clear || cls"); - if (!sys.import_data<Manufacturer>("res/manfdata.csv")) return -1; - if (!sys.import_data<App>("res/appdata.csv")) return -1; - if (!sys.import_data<Review>("res/revs.csv")) return -1; + if (!sys->import_data<Manufacturer>("res/manfdata.csv")) return -1; + if (!sys->import_data<App>("res/appdata.csv")) return -1; + if (!sys->import_data<Review>("res/revs.csv")) return -1; cont("Imported data"); - std::cout << sys << std::endl; + std::cout << *sys << std::endl; - pluseqs(sys); + pluseqs(*sys); cont("Additional data"); - std::cout << sys << std::endl; + std::cout << *sys << std::endl; - edit(sys); + edit(*sys); cont("Editing data"); - std::cout << sys << std::endl; + std::cout << *sys << std::endl; - remove(sys); + remove(*sys); cont("Removing data"); - std::cout << sys << std::endl; + std::cout << *sys << std::endl; cont(""); - getapps(sys); + getapps(*sys); cont(""); - if (!sys.export_data<Manufacturer>("res/manfdata_out.csv")) return -1; - if (!sys.export_data<App>("res/appdata_out.csv")) return -1; - if (!sys.export_data<Review>("res/revs_out.csv")) return -1; + if (!sys->export_data<Manufacturer>("res/manfdata_out.csv")) return -1; + if (!sys->export_data<App>("res/appdata_out.csv")) return -1; + if (!sys->export_data<Review>("res/revs_out.csv")) return -1; std::printf("\nThank you :)\n"); return 0; diff --git a/assignment-2.5-spreadsheets/bin/spreadsheets b/assignment-2.5-spreadsheets/bin/spreadsheets 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/src/main.cpp b/assignment-2.5-spreadsheets/src/main.cpp @@ -1,15 +1,16 @@ +#include <memory> #include "datahandler.h" int main(int argc, char **argv) { - DataHandler dh; - if (!dh.import_data<Course>("res/courses.csv")) return -1; - if (!dh.import_data<Student>("res/students.csv")) return -1; - if (!dh.import_data<equivalencies>("res/equivalencies.csv")) return -1; - if (!dh.store_data()) return -1; - if (!dh.make_report()) return -1; - dh.summary(); + std::unique_ptr<DataHandler> dh = std::make_unique<DataHandler>(); + if (!dh->import_data<Course>("res/courses.csv")) return -1; + if (!dh->import_data<Student>("res/students.csv")) return -1; + if (!dh->import_data<equivalencies>("res/equivalencies.csv")) return -1; + if (!dh->store_data()) return -1; + if (!dh->make_report()) return -1; + dh->summary(); return 0; }