Hello everyone. My name is Mike. I am a new member :). I hope to be using this forum quite a bit to extend my knowledge base on c++ and java.(just wanted to introduce myself being my 1st post and all lol)
Well my class was tasked with making a queue program for a bank last week. This program was to simulate a line, with a certain amount of tellers. Calculating avg wait time etc etc. This week our professor wants us to print something like the following.....
Customer No Arrival time Waiting time in queue
Total waiting time: ____
Number of customers served: ______
Average waiting time: ______
After service, number of customers left in queue (left unserved): ________
*(The format is better shown in the code)^^^
Along with that addition we were tasked with making it so that no more customers were to be added after N minutes. The program runs for 20 minutes. Once 20minutes is over the rest of customers in queue continue to run.
I edited the code a bit to try to make these adjustments. I am not quite sure what route to take to achieve this... I asked my professor and he replied "Figure it out" lol. Any help would be great. Here is the code I am working with...
#include <iostream>
#include <queue>
#include <time.h>
using namespace std;
class Customer
{
private:
int arrivalTime;
int serviceTime;
public:
Customer()
{
arrivalTime = 0;
serviceTime = 0;
}
Customer(int arrival)
{
arrivalTime = arrival;
serviceTime = rand()%9 + 2;
}
bool done()
{
return (serviceTime-- <= 0);
}
int getArrivalTime()
{
return arrivalTime;
}
};
class Teller
{
private:
Customer customerBeingServed;
bool free;
public:
Teller()
{
free = true;
customerBeingServed = NULL;
}
void addCustomer(Customer cust)
{
customerBeingServed = cust;
free = false;
}
bool isFree()
{
if (free) return true;
if (customerBeingServed.done())
free = true;
return free;
}
};
int main()
{
/* initialize random seed: to generate a different sequence each time*/
srand ( (unsigned int) time(NULL) );
const int M = 3; // Number of tellers
const int N = 20; // Simulation time in minutes
queue<Customer> customerQueue;
Teller tellers[M];
int totalWait = 0, numCustServed = 0;
cout<<"Customer No. Arrival time Waiting time in queue"<<endl;
cout<<"------------ ------------ ---------------------"<<endl;
for (int currentTime = 0; currentTime < N; currentTime++)
{
if (1+rand()%10 <= 9)
{
Customer customer(currentTime);
customerQueue.push(customer);
cout<<" "<<numCustServed+1<<" "<<currentTime<<" "<</* not sure what goes here*/<<endl;
}
for (int t = 0; t < M; t++)
{
if (tellers[t].isFree() && (!customerQueue.empty()))
{
Customer customer = customerQueue.front();
tellers[t].addCustomer(customer);
totalWait = totalWait + (currentTime - customer.getArrivalTime());
customerQueue.pop();
numCustServed++;
}
} // end of for tellers
} // end of for current time
cout << "Total waiting time : " << totalWait << endl;
cout << "Number of Customers served : "<< numCustServed<<endl;
cout << "Average waiting time : " << totalWait/numCustServed<<endl;
cout << "After service the number of customers left in queue : " <<endl;
return 0;
}
Thanks in advance for the help I will receive. Thanks for reading :)