Finish Øving 8

master
Øyvind Skaaden 2019-03-04 15:10:11 +01:00
parent 873fc9ee93
commit 3b62f4df86
7 changed files with 236 additions and 36 deletions

View File

@ -3,8 +3,12 @@
Meeting::Meeting()
Meeting::Meeting(int d, int sT, int eT, Campus loc, string sub, Person * lead) :
day{ d }, startTime{ sT }, endTime{ eT }, location{ loc }, subject{ sub }, leader{ lead }
{
addParticipant(lead);
meetings.emplace(this);
}
int Meeting::getDay() const
@ -37,36 +41,84 @@ const Person* Meeting::getLeader() const
return leader;
}
Meeting::~Meeting()
void Meeting::addParticipant(Person * person)
{
participants.emplace(person);
}
Campus begin(Campus c)
set<const Person*> Meeting::getParticipants() const
{
return Campus::First;
return participants;
}
Campus end(Campus c)
vector<string> Meeting::getParticipantList() const
{
return Campus::Last;
vector<string> names;
for (auto p : participants)
{
names.push_back(p->getName());
}
return names;
}
Campus operator++(Campus& x) {
return x = (Campus)(std::underlying_type<Campus>::type(x) + 1);
}
vector<const Person*> Meeting::findPotentialCoDriving() const
{
vector<const Person*> drivers;
Campus operator*(Campus c) {
return c;
for (const auto m : meetings)
{
if (m->getLocation() == this->location) {
if (m->getDay() == this->day &&
abs(m->getStartTime() - this->startTime) <= 100 &&
abs(m->getEndTime() - this->endTime) <= 100)
{
for (const auto p : m->getParticipants()) {
if (p->hasAvalibleSeats())
drivers.push_back(p);
}
}
}
}
return drivers;
}
ostream & operator<<(ostream & os, const Campus & c)
{
//string campus;
for (auto city : c) {
os << city << endl;
switch (c)
{
case Campus::Trondheim: os << "Trondheim";
break;
case Campus::Ålesund: os << "Ålesund";
break;
case Campus::Gjøvik: os << "Gjøvik";
break;
}
return os;
}
ostream& operator<<(ostream & os, const Meeting & m)
{
os << "Subject: " << m.getSubject() << endl;
os << "Location: " << m.getLocation() << endl;
os << "Starttime: " << m.getStartTime() << endl;
os << "Endtime: " << m.getEndTime() << endl;
os << "Leader: " << m.getLeader()->getName() << endl;
os << "Participants: " << endl;
for (auto p : m.getParticipantList())
{
os << p << endl;
}
return os;
}
set<const Meeting*> Meeting::meetings;
Meeting::~Meeting()
{
meetings.erase(this);
}

View File

@ -5,19 +5,11 @@
enum class Campus
{
trondheim,
ålesund,
gjøvik,
First = trondheim,
Last = gjøvik
Trondheim,
Ålesund,
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);
@ -26,22 +18,45 @@ class Meeting
int day;
int startTime;
int endTime;
Campus location;
string subject;
const Person* leader;
set<const Person*> participants;
public:
Meeting();
Campus location;
string subject;
const Person* leader;
set<const Person*> participants;
static set<const Meeting*> meetings;
public:
Meeting(int d, int sT, int eT, Campus loc, string sub, Person* lead);
int getDay() const;
int getStartTime() const;
int getEndTime() const;
Campus getLocation() const;
string getSubject() const;
const Person* getLeader() const;
virtual ~Meeting();
void addParticipant(Person* person);
set<const Person*> getParticipants() const;
vector<string> getParticipantList() const;
vector<const Person*> findPotentialCoDriving() const;
~Meeting();
};
ostream& operator<<(ostream& os, const Meeting& m);

View File

@ -0,0 +1,39 @@
#include "MeetingWindow.h"
using namespace Graph_lib;
Vector_ref<Person> MeetingWindow::getPeople()
{
return people;
}
MeetingWindow::MeetingWindow(Point xy, int w, int h, const string & title) :
Window{ xy, w, h, title },
quitBtn{ Point{x_max() - pad - btnW, pad }, btnW, btnH, "Quit", cb_quit },
newPersBtn{ newPersPos, btnW, btnH, "New Person", cb_newPers },
name{nameInPos, fieldW, fieldH, "Name"},
email{mailInPos, fieldW, fieldH, "E-Mail"}
{
attach(quitBtn);
attach(newPersBtn);
attach(name);
attach(email);
ti = title;
}
void MeetingWindow::cb_quit(Address, Address pw) { reference_to<MeetingWindow>(pw).quit(); }
void MeetingWindow::cb_newPers(Address, Address pw){ reference_to<MeetingWindow>(pw).newPers(); }
void MeetingWindow::newPers()
{
cout << name.get_string() << " --- " << email.get_string() << endl;
people.push_back(new Person{ name.get_string(), email.get_string() });
redraw();
}
MeetingWindow::~MeetingWindow()
{
}

View File

@ -0,0 +1,53 @@
#pragma once
#include "GUI.h"
#include "Graph.h"
#include "Meeting.h"
#include "std_lib_facilities.h"
using namespace Graph_lib;
class MeetingWindow : public Graph_lib::Window
{
static constexpr int pad = 50;
static constexpr int fieldPad = 100;
static constexpr int fieldH = 50;
static constexpr int fieldW = 200;
static constexpr int btnH = 50;
static constexpr int btnW = 100;
static constexpr Point nameInPos{ pad, pad };
static constexpr Point mailInPos{ pad, nameInPos.y + fieldH + pad };
static constexpr Point newPersPos{ pad, mailInPos.y + fieldH + pad };
Button quitBtn;
Button newPersBtn;
In_box name;
In_box email;
string ti;
Vector_ref<Person> people;
public:
Vector_ref<Person> getPeople();
MeetingWindow(Point xy, int w, int h, const string& title);
// Callback
static void cb_quit(Address, Address pw); // cb for quitbtn
static void cb_newPers(Address, Address pw); // cb for newPersBtn
// Callback-functions
void quit() { cout << ti + ": quit called\n"; hide(); } // action to be done when quit_button is pressed
void newPers();
~MeetingWindow();
};

View File

@ -22,11 +22,13 @@
<ClCompile Include="Car.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Meeting.cpp" />
<ClCompile Include="MeetingWindow.cpp" />
<ClCompile Include="Person.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Car.h" />
<ClInclude Include="Meeting.h" />
<ClInclude Include="MeetingWindow.h" />
<ClInclude Include="Person.h" />
</ItemGroup>
<PropertyGroup Label="Globals">

View File

@ -27,6 +27,9 @@
<ClCompile Include="Meeting.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="MeetingWindow.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Car.h">
@ -38,5 +41,8 @@
<ClInclude Include="Meeting.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="MeetingWindow.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@ -1,24 +1,57 @@
// Example program in TDT4102_Graphics template, from PPP page 415
#include "GUI.h"
#include "Graph.h"
#include "Simple_window.h"
#include "MeetingWindow.h"
#include "Meeting.h"
// The following pragma turns off the console
//#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
using namespace Graph_lib;
int main() {
/*
Car c1{ 5 };
Car c2{ 0 };
Car c3{ 4 };
Person p1{ "Oyvind", "mail", &c1 };
Person p2{ "Ulrik", "mail2" };
Person p3{ "Live", "mail3", &c2 };
Person p4{ "Per", "mail4", &c3 };
cout << p1 << endl;
cout << p2 << endl;
cout << p3 << endl;
Meeting m1{ 13, 1300, 1500, Campus::Trondheim, "Test", &p1 };
m1.addParticipant(&p2);
m1.addParticipant(&p3);
Meeting m2{ 13, 1200, 1500, Campus::Trondheim, "Test", &p4 };
cout << m1;
m1.findPotentialCoDriving();
*/
MeetingWindow win{Point{100, 100}, 600, 400, "Meetings" };
gui_main();
for (const auto p : win.getPeople())
{
cout << p->getName() << endl;
}
keep_window_open();
return 0;
}