There is only one problem this week. It is to be implemented.
A secretary helps a stream of people who enter his office. When a customer comes in, she wants to ask a question that will take the secretary q seconds to answer. She waits in line until it is her turn. Every d seconds, someone else comes in through the door to ask something and waits in line until she is at the front.
However, some customers are clever, and instead of going to the secretary, they call him on the telephone. Phone customers occur every p seconds. He is so flustered by phone calls that he interrupts his answer to the current client (whether the current client is physically in his office or is another phone-in customer) and makes her wait at the front of the line. When he eventually gets back to a waiting customer, he only has to devote the amount of time remaining for that customer in order to properly answer her question.
Write a program that simulates this office. Instead of having each question take exactly q seconds to answer, every door arrival appear exactly d seconds after the previous door arrival, and each phone arrival appear exactly p seconds after the previous phone arrival, use a random real number between 0 and q, 0 and d and 0 and p, respectively. (Recall the C++ function rand().)
Print a message every time someone comes in the door or makes a phone call or has finally gotten her question answered. Each message should indicate at what time the event happened, to whom it happened (number each customer consecutively from 1 to however high they reach), and how long the line at the office is after that event. (The person currently being served counts as a member of the line, as do waiting phone callers.)
Your program must use a linked queue to implement the line of waiting customers. You may not use STL containers.
For the hard copy you turn in, run your program for 10 simulated seconds, with the constants q, d and p set to 1, 2 and 2.
CHV pp 324-334 presents examples of simulation. Understanding the examples will help ypu in solving this problem.