473,394 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Help me in a barbarshop broblem

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.
Nov 24 '06 #1
1 1477
Banfa
9,065 Expert Mod 8TB
How far have you got so far?
Nov 24 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: LRW | last post by:
This is mySQL 101. I know it's supposed to be super simple, but I'm an idiot. I can't get my join to work (1st time I've tried doing joins.) I've read http://www.mysql.com/doc/en/JOIN.html, but...
21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
0
by: LRW | last post by:
This has to do with mySQL 101. I know it's supposed to be super simple, but I'm an idiot. I can't get my join to work (1st time I've tried doing joins.) I've read...
2
by: Sudheer Kareem | last post by:
Dear All Please tell me how to assosiate help files with my Vb.net Project. Regards Sudheer
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
2
by: bmbvm5 | last post by:
Hello; I am beginner in java and I should submit one java program in early day. I try to write this program more then ten time but every time I find one broblem. Please help me because if you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.