-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSleeping barber auto 2.cpp
57 lines (56 loc) · 1.42 KB
/
Sleeping barber auto 2.cpp
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
#include<stdio.h>
#include <unistd.h>
int cust;
bool chair,wait,barber;
main(){
for(int i=0;i<=8;i++){
if(cust==0 && barber==false && chair==false && wait==false){
printf("\nCUSTOMERS[%d]BARBER[Sleeping]\tCHAIR[idle]\tWAITING[Empty]",cust);
cust=1;
barber=false;
chair=false;
wait=false;
sleep(2);
}
else if(cust == 1 && barber==false && chair==false && wait==false){
printf("\nCUSTOMERS[%d]BARBER[Sleeping]\tCHAIR[idle]\tWAITING[Empty]",cust);
cust=1;
barber=true;
chair=false;
wait=false;
sleep(2);
}
else if(cust == 1 && barber==true && chair==false && wait==false){
printf("\nCUSTOMERS[%d]BARBER[Awake]\tCHAIR[idle]\tWAITING[Empty]",cust);
cust=1;
barber=true;
chair=true;
wait=false;
sleep(2);
}
else if(cust == 1 && barber==true && chair==true && wait==false){
printf("\nCUSTOMERS[%d]BARBER[Awake]\tCHAIR[Reserved]\tWAITING[Empty]",cust);
cust=2;
barber=true;
chair=true;
wait=true;
sleep(2);
}
else if(cust == 2 && barber==true && chair==true && wait==true){
printf("\nCUSTOMERS[%d]BARBER[Cutting]\tCHAIR[Reserved]\tWAITING[Full]",cust);
cust=3;
barber=true;
chair=true;
wait=true;
sleep(2);
}
else if(cust == 3 && barber==true && chair==true && wait==true){
printf("\nCUSTOMERS[%d]BARBER[Cutting]\tCHAIR[Reserved]\tWAITING[Full!]",cust);
cust=2;
barber=true;
chair=true;
wait=true;
sleep(2);
}
}
}