Hi,
How are you?
I am student in college of technology and I have assigment in C++ programing and I can not solve it. please help me to program it in any language.
The problem is:
Three barbers work independently in a barber shop:
1. The barbershop has 3 barber chairs, each of which is assigned to one barber.
2. Each barber follows the same work plan:
3.The barber sleeps (or daydreams) when no customer customer is waiting (and is not in the barber's own chair).
4.When the barber is asleep, the barber waits to be awaken by a new customer. (A sign in the shop indicates which barber has been asleep longest, so the customer will know which barber to wake up if multiple barbers are asleep.)
5.Once awake, the barber cuts the hair of a customer in the barber's chair.
6.When the haircut is done, the customer pays the barber and then is free to leave.
7.After receiving payment, the barber calls the next waiting customer (if any). If such a customer exists, that customer sits in the barber's chair and the barber starts the next haircut. If no customer is waiting, the barber goes back to sleep.
8.Each customer follows the following sequence of events.
9.When the customer first enters the barbershop, the customer leaves immediately if more than 20 people are waiting (10 standing and 10 sitting). On the other hand, if the barbershop is not too full, the customer enters and waits.
10.If at least one barber is sleeping, the customer looks at a sign, wakes up the barber who has been sleeping the longest, and sits in that barber's chair (after the barber has stood up).
11.If all barbers are busy, the customer sits in a waiting-room chair, if one is available. Otherwise, the customer remains standing until a waiting-room chair becomes available.
12.Customers keep track of their order, so the person sitting the longest is always the next customer to get a haircut.
13.Similarly, standing customers remember their order, so the person standing the longest takes the next available waiting-room seat.
For this exercise, you are to write a C program to simulate activity for this barbershop:
a.Simulate each barber and each customer as a separate process.
b.Altogether, 30 customers should try to enter.
c.Use a random number generator, so a new customer arrives every 1, 2, 3, or 4 seconds. (This might be accomplished by an appropriate statement sleep(1+(rand()%4)); .
d.Similarly, use a random number generator, so each haircut lasts between 3 and 6 seconds.
e.Each barber should report when he/she starts each haircut and when he/she finishes each haircut.
f.Each customer should report when he/she enters the barbershop. The customer also should report if he/she decides to leave immediately.
g.Similarly, if the customer must stand or sit in the waiting room, the customer should report when each activity begins.
h.Finally, the customer should report when the haircut begins and when the customer finally exits the shop.
Thank you.