Problem description
? Assume that Banks have K window to provide services, from bank in the morning to open the door closed (open the door at 9 am, 5:00 PM) has the customer into the bank, because each window can only receive a customer at a time, for customers who just entered the bank (suggestion: customers getting into the time using random function), the first to take the machine take service number, take the opportunity to automatically print out a single service, shown on the single service, and the service, the number of people are waiting for the front, when the bank clerk after service to a customer, simply call the corresponding key, can automatically call a customer,
The basic requirements
(1) a program simulating bank this kind of business activity,
(2) calculation of day N customers in the Banks' average waiting time, waiting for the longest time, the final completion time, the number of customer service, and statistics each window
(3) the proposal has the following Settings:
A) the customer arrival time of random, set to N the number of people a day,
B) the bank clerk random processing time,
Code implementation
#include
# include & lt; Stdlib. H>
# include & lt; Time. H>
#include
Using namespace STD. Int K, N;//define the bank service window number and the number of customers a day//welcome screen function void welcom () {cout<& lt;" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * welcome to Alexander bank * * * * * * * * * * * * * * * * * * * * * * * * * * * * "& lt; Struct chainNode {
//data members T element;
ChainNode * next;
//method chainNode () {}
ChainNode (const T& Element) {this - & gt; Element=element; }
ChainNode (const T& Element, chainNode * next) {this - & gt; Element=element; This - & gt; Next=next; }};//define the queue template The class queue {public: queue ();//initialize the queue to queue () {};//destructors bool empty () {//whether the queue is empty return queueSize==0; } int size () {//returns the number of elements in the return queueSize; } T& The front () {//returns the first element return queueFront - & gt; Element; } T& The back () {//returns the tail element return queueBack - & gt; Element; } chainNode * the begin () {return queueFront; } void pop ();//remove the first element void push (const T& TheElement); Private: int queueSize;//chainNode< queue length; T> * queueFront;//a pointer to the first element on the queue chainNode * queueBack;//pointer to the last element queue}; Template Queue : : queue () {queueFront=queueBack=NULL; QueueSize=0; } template Void queue : : pop () {if (queueFront==NULL) {cout<& lt;" You queue is empty!" ; return; } chainNode * nextNode=queueFront - & gt; Next; The delete queueFront; QueueFront=nextNode; QueueSize -; } template Void queue : : push (const T& ChainNode< theElement) {//apply for a new element node; T> * newNode=new chainNode (theElement, NULL);//insert the new node into the next morning the if (queueSize==0) queueFront=newNode; Empty the else//team queueBack - & gt; Next=newNode;//team not empty queueBack=newNode; QueueSize++; }//define time struct thetime {int h;//int m;//points};//define each customer reach the bank time, waiting time, began to deal with business time, business processing time, end of business time (time) to leave struct customers {struct thetime arrive_time;//reach the bank time struct thetime wait_time;//waiting time struct thetime start_time;//handle the business time int business_time;//business processing time (assuming the business processing time for an integer, and the processing time range of 10 to 40 min) struct thetime end_time;//end to handle business time int in_bank_number;//enter the bank number} customers;//display window service void show_queue (queue Cus_queue []) {Sleep (1000); For (int I=0; I & lt; K; I++) {cout<& lt;" Window "& lt; * m=cus_queue [I] the begin (); While (m!=NULL) {cout<& lt;" Customer "& lt; 0; I -) {max_time_cus=customer [I]; Max_time_index=I;//find the arrival time at the latest for (int j=0; J Cus_queue [], customers & amp; The customer, int each_queue_cus_number []) {//the user in each queue needs to wait for the time in an array of int each_queue_wait_time [K]. for(int i=0; I {cus_queue [], customers customer) for (int I=0; I