diff --git a/Oving 8/Oving 8/Car.cpp b/Oving 8/Oving 8/Car.cpp index e69de29..b51dbc7 100644 --- a/Oving 8/Oving 8/Car.cpp +++ b/Oving 8/Oving 8/Car.cpp @@ -0,0 +1,21 @@ +#include "Car.h" + + + +Car::Car(unsigned int freeSeats) : + freeSeats{freeSeats} +{ +} + +bool Car::hasFreeSeats() const +{ + if (freeSeats > 0) + return true; + return false; +} + +void Car::reserveFreeSeat() +{ + --freeSeats; +} + diff --git a/Oving 8/Oving 8/Car.h b/Oving 8/Oving 8/Car.h index e69de29..b291d68 100644 --- a/Oving 8/Oving 8/Car.h +++ b/Oving 8/Oving 8/Car.h @@ -0,0 +1,13 @@ +#pragma once +class Car +{ + unsigned int freeSeats; +public: + Car(unsigned int freeSeats); + + bool hasFreeSeats() const; + void reserveFreeSeat(); + + virtual ~Car() {}; +}; + diff --git a/Oving 8/Oving 8/Meeting.cpp b/Oving 8/Oving 8/Meeting.cpp new file mode 100644 index 0000000..f83e608 --- /dev/null +++ b/Oving 8/Oving 8/Meeting.cpp @@ -0,0 +1,72 @@ +#include "Meeting.h" + + + + +Meeting::Meeting() +{ +} + +int Meeting::getDay() const +{ + return day; +} + +int Meeting::getStartTime() const +{ + return startTime; +} + +int Meeting::getEndTime() const +{ + return endTime; +} + +Campus Meeting::getLocation() const +{ + return location; +} + +string Meeting::getSubject() const +{ + return subject; +} + +const Person* Meeting::getLeader() const +{ + return leader; +} + + +Meeting::~Meeting() +{ +} + +Campus begin(Campus c) +{ + return Campus::First; +} + +Campus end(Campus c) +{ + return Campus::Last; +} + +Campus operator++(Campus& x) { + return x = (Campus)(std::underlying_type::type(x) + 1); +} + +Campus operator*(Campus c) { + return c; +} + + +ostream & operator<<(ostream & os, const Campus & c) +{ + + //string campus; + for (auto city : c) { + os << city << endl; + } + return os; +} diff --git a/Oving 8/Oving 8/Meeting.h b/Oving 8/Oving 8/Meeting.h new file mode 100644 index 0000000..ef1bdf5 --- /dev/null +++ b/Oving 8/Oving 8/Meeting.h @@ -0,0 +1,47 @@ +#pragma once + +#include "std_lib_facilities.h" +#include "Person.h" + +enum class Campus +{ + trondheim, + ålesund, + gjøvik, + + First = trondheim, + Last = gjøvik +}; + +Campus begin(Campus c); +Campus end(Campus c); +Campus operator++(Campus& x); +Campus operator*(Campus c); + +ostream& operator<<(ostream& os, const Campus& c); + + +class Meeting +{ + int day; + int startTime; + int endTime; + Campus location; + string subject; + const Person* leader; + set participants; +public: + Meeting(); + + int getDay() const; + int getStartTime() const; + int getEndTime() const; + Campus getLocation() const; + string getSubject() const; + const Person* getLeader() const; + + virtual ~Meeting(); +}; + + + diff --git a/Oving 8/Oving 8/Oving 8.vcxproj b/Oving 8/Oving 8/Oving 8.vcxproj index c7b7aaf..485a6f3 100644 --- a/Oving 8/Oving 8/Oving 8.vcxproj +++ b/Oving 8/Oving 8/Oving 8.vcxproj @@ -19,7 +19,15 @@ + + + + + + + + 15.0 @@ -99,7 +107,7 @@ Graph_libd.lib;fltkd.lib;wsock32.lib;comctl32.lib;fltkjpegd.lib;fltkimagesd.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - /ignore:4099 %(AdditionalOptions) + /ignore:4099 %(AdditionalOptions) @@ -113,7 +121,7 @@ Graph_libd.lib;fltkd.lib;wsock32.lib;comctl32.lib;fltkjpegd.lib;fltkimagesd.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - /ignore:4099 %(AdditionalOptions) + /ignore:4099 %(AdditionalOptions) @@ -131,7 +139,7 @@ true true Graph_lib.lib;fltk.lib;wsock32.lib;comctl32.lib;fltkjpeg.lib;fltkimages.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - /ignore:4099 %(AdditionalOptions) + /ignore:4099 %(AdditionalOptions) @@ -149,7 +157,7 @@ true true Graph_lib.lib;fltk.lib;wsock32.lib;comctl32.lib;fltkjpeg.lib;fltkimages.lib;;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - /ignore:4099 %(AdditionalOptions) + /ignore:4099 %(AdditionalOptions) diff --git a/Oving 8/Oving 8/Oving 8.vcxproj.filters b/Oving 8/Oving 8/Oving 8.vcxproj.filters index a91ad0e..c8fa99d 100644 --- a/Oving 8/Oving 8/Oving 8.vcxproj.filters +++ b/Oving 8/Oving 8/Oving 8.vcxproj.filters @@ -18,5 +18,25 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + \ No newline at end of file diff --git a/Oving 8/Oving 8/Person.cpp b/Oving 8/Oving 8/Person.cpp index e69de29..86463e8 100644 --- a/Oving 8/Oving 8/Person.cpp +++ b/Oving 8/Oving 8/Person.cpp @@ -0,0 +1,39 @@ +#include "Person.h" + + + +Person::Person(string name, string email, Car* car) : + name{ name }, email{ email }, car{ car } +{ + +} + +string Person::getName() const +{ + return name; +} + +string Person::getEmail() const +{ + return email; +} + +bool Person::hasAvalibleSeats() const +{ + if (car != nullptr) + return car->hasFreeSeats(); + return false; +} + +void Person::setEmail(string newEmail) +{ + email = newEmail; +} + +ostream & operator<<(ostream & os, const Person & p) +{ + string seats = "No"; + if (p.hasAvalibleSeats()) + seats = "Yes"; + return os << "Name: " << p.name << "\nE-Mail: " << p.email << "\nHas free seats: " << seats << endl; +} diff --git a/Oving 8/Oving 8/Person.h b/Oving 8/Oving 8/Person.h index e69de29..ad03b32 100644 --- a/Oving 8/Oving 8/Person.h +++ b/Oving 8/Oving 8/Person.h @@ -0,0 +1,30 @@ +#pragma once +#include "std_lib_facilities.h" +#include "Car.h" + +class Person +{ + string name, email; + Car* car; +public: + Person(string name, string email, Car* car = nullptr); + + string getName() const; + string getEmail() const; + + bool hasAvalibleSeats() const; + + void setEmail(string newEmail); + + friend ostream& operator<<(ostream& os, const Person& p); + + /* + operatoren burde ha const fordi den ikke skal kunne endre på personen når den skal skrives ut. + + Dersom vi ønsker å endre på dataen kan vi ikke bruke const + Const er kjekt å bruke slik at vi er sikre på at dataen ikke kan endres etter at vi sender den til en funksjon + */ + + virtual ~Person() {}; +}; + diff --git a/Oving 8/Oving 8/main.cpp b/Oving 8/Oving 8/main.cpp index c39cede..444e38f 100644 --- a/Oving 8/Oving 8/main.cpp +++ b/Oving 8/Oving 8/main.cpp @@ -1,19 +1,24 @@ // Example program in TDT4102_Graphics template, from PPP page 415 #include "Graph.h" #include "Simple_window.h" + +#include "Meeting.h" + int main() { - using namespace Graph_lib; - cout << "The New \"Hello, Graphical World!\" message\n"; - Point tl{ 100, 100 }; - Simple_window win{ tl, 600, 400, "Canvas" }; - Polygon poly; - poly.add(Point{ 300, 200 }); - poly.add(Point{ 350, 100 }); - poly.add(Point{ 400, 200 }); - poly.set_color(Color::red); + Car c1{ 5 }; + Car c2{ 0 }; - win.attach(poly); - win.wait_for_button(); + + Person p1{ "Oyvind", "mail", &c1 }; + Person p2{ "Ulrik", "mail2" }; + Person p3{ "Live", "mail3", &c2 }; + + cout << p1 << endl; + cout << p2 << endl; + cout << p3 << endl; + + keep_window_open(); + return 0; }