/
building.h
119 lines (95 loc) · 2.89 KB
/
building.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* building.h
* Bryan Clair
*/
#ifndef _BUILDING_H_
#define _BUILDING_H_
#include <string>
#include <vector>
//
// The building has floors numbered 0, 1, 2, ... , MAXFLOOR
//
#define MAXFLOOR 10
//
// class ElevatorMachinery
//
// Implements the physical model of an elevator.
// The algorithm and coordination with passengers are expected
// to be implemented in a derived class Elevator.
//
class ElevatorMachinery {
public:
ElevatorMachinery();
int getid() const; // unique ID for this elevator
//
// Elevator display functions
//
void message(const char *s); // display a message for this elevator
void message(const char *s, const int i); // variant also displays an int
virtual int display_passengers() = 0; // returns number of passengers
// The Elevator class must implement display_passengers since
// ElevatorMachinery is not responsible for maintaining a list of passengers
//
// Elevator status functions
//
int onfloor() const; // elevator's current floor
bool door_is_open() const; // true if door is open
//
// Elevator action functions
//
void move_to_floor(int floor);
void move_up(); // up one floor
void move_down(); // down one floor
void open_door();
void close_door();
private:
static int next_unused_id;
int id;
int floor;
bool door_status; // true if door is currently open
void display(); // display the elevator
void warning(const char *s);
void gmessage(const char *s);
// display a warning message if machinery used improperly
};
//
// class Person
//
// Implements a person in the building.
// The person has work to do on various floors, and alternates
// between "working" and taking an elevator to a new floor.
//
// The Person class decides how long to "work" and decides which
// floors to visit. In addition, the Person class keeps track
// of time spent waiting for elevators, and displays the Person's
// progress through the building.
//
// The Person class does NOT implement the act of taking an elevator,
// but (repeatedly) calls take_elevator.
//
class Person {
public:
Person();
Person(std::string);
// ~Person();
// Person(const Person&);
// Person& operator=(const Person&);
//
// Person display functions
//
void display() const; // display this person
void message(const char *s) const; // display a message for this person
void message(const char *s, const int i) const;
// variant also displays an int
private:
int floor;
std::string name;
int entrytime;
std::vector<int> work_floors;
std::vector<int> work_times;
void gmessage(const char *s) const;
void warning(const char *s) const;
double run(void);
friend void *person_runner(void *);
};
#endif