First of all I should say, I dont want to bother any one with my question or long program
please if you have time, help me.( I dont mean that I want any one to do my program, just please if you are an expert and professional in C++, please help me and guid me how to fix the program)
I did my best to comment my program.
I am learning C++ and now I'm working on a program that:
reads in a file "customers.txt" containing the information for bank customers. The file is formatted with each customer's name, arrival time (in minutes after 9:00), and service time (in minutes) on a separate line. The program moves each customer into the bank line at the arrival time. If the teller counter is available, the customer is moved out of the line to the teller. When the customer has spent the specified amount of time at the counter, they leave the bank and the next customer steps up. The program continues until all customers are serviced.
I'm trying to make Multiple Tellers, at this time my program assumes the bank has only one teller/counter. I want to modify the program so that it can handle multiple tellers, so that the customers in line will move to any available teller. For example, "Chewbacca steps up to counter #2" or "Vader has left counter #4."
but I have no idea how I can do that:
right now my program works, but I dont know how to add multiple tellers.
my program is:
Expand|Select|Wrap|Line Numbers
- /****************************************************
- ** The main routine simulates a line-up at the bank.
- *****************************************************/
- int main() {
- //Read in the customer file.
- //Assume file is in format: Name ArrivalTime ServiceTime
- //Assume list is sorted based on distinct arrival times.
- string file_name; // the files name that user input
- ifstream fin;
- cout<<"please Enter your choice:\nChoice1: (You can type in the name of your file.)\nchoice2: (You can ask the program to generate a list of random customers.)\n\n";
- int choice;
- cout<<"what is your choice? (1 or 2):";
- cin>>choice;
- while(choice!=1 && choice!=2){
- cout<<"You should type 1 or 2, try again:\nEnter you choice again:";
- cin>>choice;
- }
- Queue<Customer> customerList;
- Customer newCustomer;
- if(choice==1){ //choice 1 , user type his/her file_name to open
- cout<<"PLease type your file name:";
- cin >> file_name;
- cout<<"\n";
- fin.open( file_name.c_str( ) );
- while (fin >> newCustomer)
- customerList.enter(newCustomer);
- fin.close();
- if (customerList.isEmpty()) {
- cout << "Could not read file customers.txt.\n";
- return 0;
- }
- }
- if (choice==2){
- cout<<"Please specify the probability that a customer arrives each minute:";
- int probability;
- cin>>probability;
- for (int i=0; i <= 540; i++) {
- if ( 1+rand()%100 <= probability )
- customerList.enter( Customer("A customer", i, 5+rand()%11) );
- }
- }
- int num_teller; //number of tellers
- cout<<"please Enter the Number of tellers:";
- cin>>num_teller;
- cout<<"\n";
- //The first customer immediately steps up to the counter, no waiting.
- //We start the clock running at first customer's arrival time.
- Customer atCounter = customerList.leave();
- bool isCounterEmpty = false;
- int currentTime = atCounter.get_arrivalTime();
- int startService = atCounter.get_arrivalTime();
- printTime(currentTime);
- cout << " " << atCounter.get_name() << " has entered the bank.\n";
- printTime(currentTime);
- cout << " " << atCounter.get_name() << " stepped up to the counter.\n";
- //Set up our empty line.
- Queue<Customer> line;
- //Repeat while there are customers in bank or yet to arrive.
- while (!customerList.isEmpty() || !line.isEmpty() || !isCounterEmpty) {
- //Check if someone enters line.
- if (!customerList.isEmpty() && (customerList.peek()).get_arrivalTime() <= currentTime) {
- printTime(currentTime);
- cout << " "<< (customerList.peek()).get_name()
- << " has entered the bank.\n";
- line.enter( customerList.leave() );
- }
- //Check if someone leaves the counter.
- if ( !isCounterEmpty && (startService + atCounter.get_serviceTime() <= currentTime) ) {
- isCounterEmpty = true;
- printTime(currentTime);
- cout << " "
- << atCounter.get_name()
- << " has left the counter.\n";
- }
- //Check if counter is empty and someone is waiting in line.
- if ( isCounterEmpty && !line.isEmpty() ) {
- atCounter = line.leave();
- startService = currentTime;
- isCounterEmpty = false;
- printTime(currentTime);
- cout << " " << atCounter.get_name()
- << " has stepped up to the counter.\n";
- }
- currentTime++; //Inefficient. Better to move to next event time.
- }
- //Compute queue statistics.
- return 0;
- }