Allegato "bancoCheckin.cpp"
Scarica 1 class Posti
2 {
3 int posto[MAX];
4 public:
5 int trovaEBloccaPosto(int codiceutente)
6 {
7 for(int i =0; i < MAX; i++)
8 if (posto[i] == 0)
9 {
10 posto[i] = codiceutente;
11 return i;
12 }
13 return -1;
14 }
15 };
16
17 Posti* posti;
18
19 class BancoCheckin : public JTCThread
20
21 {
22 int codiceBanco;
23 public:
24 BancoCheckin (int cod)
25 { codiceBanco = cod; }
26 virtual void run()
27 {
28 while(true)
29 {
30 sleep(100);
31 int codiceutente = rand() % 10000;
32 int posto
33 = posti->trovaEBloccaPosto(codiceutente);
34 cout << "Banco checkin:" << codicebanco <<endl;
35 if (posto > 0)
36 {
37 cout << "Prenotato posto:" << posto;
38 }
39 else
40 cout << "Utente: " << codiceutente <<
41 "non c'è posto per te.";
42 }
43 }
44 };
45
46 int main()
47 {
48 posti = new Posti();
49 BancoCheckin *a = new BancoCheckin(1);
50 BancoCheckin *b = new BancoCheckin(2);
51 BancoCheckin *c = new BancoCheckin(3);
52 a->start();
53 b->start();
54 c->start();
55 return 0;
56 }
Allegati
Non è consentito inserire allegati su questa pagina.