Hi
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:
[code=cpp]
/*************** *************** *************** *******
** 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:\nChoice 1: (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.en ter(newCustomer );
fin.close();
if (customerList.i sEmpty()) {
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>>probabilit y;
for (int i=0; i <= 540; i++) {
if ( 1+rand()%100 <= probability )
customerList.en ter( 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.le ave();
bool isCounterEmpty = false;
int currentTime = atCounter.get_a rrivalTime();
int startService = atCounter.get_a rrivalTime();
printTime(curre ntTime);
cout << " " << atCounter.get_n ame() << " has entered the bank.\n";
printTime(curre ntTime);
cout << " " << atCounter.get_n ame() << " 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.p eek()).get_arri valTime() <= currentTime) {
printTime(curre ntTime);
cout << " "<< (customerList.p eek()).get_name ()
<< " has entered the bank.\n";
line.enter( customerList.le ave() );
}
//Check if someone leaves the counter.
if ( !isCounterEmpty && (startService + atCounter.get_s erviceTime() <= currentTime) ) {
isCounterEmpty = true;
printTime(curre ntTime);
cout << " "
<< atCounter.get_n ame()
<< " 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(curre ntTime);
cout << " " << atCounter.get_n ame()
<< " has stepped up to the counter.\n";
}
currentTime++; //Inefficient. Better to move to next event time.
}
//Compute queue statistics.
return 0;
}[/code]
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:
[code=cpp]
/*************** *************** *************** *******
** 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:\nChoice 1: (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.en ter(newCustomer );
fin.close();
if (customerList.i sEmpty()) {
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>>probabilit y;
for (int i=0; i <= 540; i++) {
if ( 1+rand()%100 <= probability )
customerList.en ter( 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.le ave();
bool isCounterEmpty = false;
int currentTime = atCounter.get_a rrivalTime();
int startService = atCounter.get_a rrivalTime();
printTime(curre ntTime);
cout << " " << atCounter.get_n ame() << " has entered the bank.\n";
printTime(curre ntTime);
cout << " " << atCounter.get_n ame() << " 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.p eek()).get_arri valTime() <= currentTime) {
printTime(curre ntTime);
cout << " "<< (customerList.p eek()).get_name ()
<< " has entered the bank.\n";
line.enter( customerList.le ave() );
}
//Check if someone leaves the counter.
if ( !isCounterEmpty && (startService + atCounter.get_s erviceTime() <= currentTime) ) {
isCounterEmpty = true;
printTime(curre ntTime);
cout << " "
<< atCounter.get_n ame()
<< " 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(curre ntTime);
cout << " " << atCounter.get_n ame()
<< " has stepped up to the counter.\n";
}
currentTime++; //Inefficient. Better to move to next event time.
}
//Compute queue statistics.
return 0;
}[/code]
Comment