Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
teller.h
Go to the documentation of this file.
1
30#ifndef TELLER_H_INCLUDED
31#define TELLER_H_INCLUDED
32
33inline int lcg_rand (int n);
34
36{
37public:
38
41
42 Customer (int at = 0)
43 : arrivalTime (at),
44 processTime (2 + lcg_rand (6)) {}
45
46 bool done () { // are we done with our transaction?
47 return --processTime < 0;
48 }
49
50 bool operator< (const Customer& c) const { // order by arrival time
51 return arrivalTime < c.arrivalTime;
52 }
53};
54
55
56class Teller
57{
58public:
59 Teller (): free (true) { }
60
61 bool isFree () { // are we free to service new customer?
62 if (free)
63 return true;
64 if (customer.done())
65 free = true;
66 return free;
67 }
68
69 void addCustomer (const Customer &c) { // start serving new customer
70 customer = c;
71 free = false;
72 }
73
74private:
75
76 bool free;
77 Customer customer;
78};
79
80#endif // TELLER_H_INCLUDED
#define c
Definition 17.names.cpp:111
#define n
Definition 17.names.cpp:130
Customer(int at=0)
Definition teller.h:42
bool operator<(const Customer &c) const
Definition teller.h:50
int processTime
Definition teller.h:40
bool done()
Definition teller.h:46
int arrivalTime
Definition teller.h:39
void addCustomer(const Customer &c)
Definition teller.h:69
Teller()
Definition teller.h:59
bool isFree()
Definition teller.h:61
#define true
Definition stdbool.h:25
int lcg_rand(int n)
Definition teller.cpp:39