More oving 8
parent
15b62e74e2
commit
873fc9ee93
|
@ -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;
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
class Car
|
||||
{
|
||||
unsigned int freeSeats;
|
||||
public:
|
||||
Car(unsigned int freeSeats);
|
||||
|
||||
bool hasFreeSeats() const;
|
||||
void reserveFreeSeat();
|
||||
|
||||
virtual ~Car() {};
|
||||
};
|
||||
|
|
@ -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<Campus>::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;
|
||||
}
|
|
@ -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<const Person*> participants;
|
||||
public:
|
||||
Meeting();
|
||||
|
||||
int getDay() const;
|
||||
int getStartTime() const;
|
||||
int getEndTime() const;
|
||||
Campus getLocation() const;
|
||||
string getSubject() const;
|
||||
const Person* getLeader() const;
|
||||
|
||||
virtual ~Meeting();
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -19,7 +19,15 @@
|
|||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Car.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="Meeting.cpp" />
|
||||
<ClCompile Include="Person.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Car.h" />
|
||||
<ClInclude Include="Meeting.h" />
|
||||
<ClInclude Include="Person.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
|
@ -99,7 +107,7 @@
|
|||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>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)</AdditionalDependencies>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
|
@ -113,7 +121,7 @@
|
|||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>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)</AdditionalDependencies>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
|
@ -131,7 +139,7 @@
|
|||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>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)</AdditionalDependencies>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
@ -149,7 +157,7 @@
|
|||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>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)</AdditionalDependencies>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
|
|
@ -18,5 +18,25 @@
|
|||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Car.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Person.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Meeting.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Car.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Person.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Meeting.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -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;
|
||||
}
|
|
@ -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() {};
|
||||
};
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue