#include
#include
#include
#include
#include "Simulation.h"
using namespace std;
//*************** customerType ************
customerType::customerType(int cN, int arrvTime, int wTime,
int tTime)
{
customerNumber = cN;
arrivalTime = arrvTime;
waitingTime = wTime;
transactionTime = tTime;
}
int customerType::getWaitingTime() const
{
return waitingTime;
}
void customerType::incrementWaitingTime()
{
waitingTime++;
}
void customerType::setWaitingTime(int time)
{
waitingTime = time;
}
void customerType::setCustomerInfo(int customerN, int inTime,
int wTime, int tTime)
{
customerNumber = customerN;
arrivalTime = inTime;
waitingTime = wTime;
transactionTime = tTime;
}
int customerType::getArrivalTime()
{
return arrivalTime;
}
int customerType::getTransactionTime()
{
return transactionTime;
}
int customerType::getCustomerNumber()
{
return customerNumber;
}
//**************** serverType **********
serverType::serverType()
{
status = "free";
transactionTime = 0;
}
bool serverType::isFree() const
{
return (status == "free");
}
void serverType::setBusy()
{
status = "busy";
}
void serverType::setFree()
{
status = "free";
}
void serverType::setTransactionTime(int t)
{
transactionTime = t;
}
void serverType::setTransactionTime()
{
int time;
time = currentCustomer.getTransactionTime();
transactionTime = time;
}
void serverType::decreaseTransactionTime()
{
transactionTime--;
}
int serverType::getRemainingTransactionTime()
{
return transactionTime;
}
void serverType::setCurrentCustomer(customerType cCustomer)
{
currentCustomer = cCustomer;
}
int serverType::getCurrentCustomerNumber()
{
return currentCustomer.getCustomerNumber();
}
int serverType::getCurrentCustomerArrivalTime()
{
return currentCustomer.getArrivalTime();
}
int serverType::getCurrentCustomerWaitingTime()
{
return currentCustomer.getWaitingTime();
}
int serverType::getCurrentCustomerTransactionTime()
{
return currentCustomer.getTransactionTime();
}
//************** serverListType ***********
serverListType::serverListType(int num)
{
numOfServers = num;
servers = new serverType[num];
for (int i = 0; i < num; i++)
servers[i].setFree();
}
serverListType::~serverListType()
{
delete [] servers;
}
int serverListType::getFreeServerID()
{
int serverID = -1;
int i;
for (i = 0; i < numOfServers; i++)
if (servers[i].isFree())
{
serverID = i;
break;
}
return serverID;
}
int serverListType::getNumberOfBusyServers()
{
int busyServers = 0;
int i;
for (i = 0; i < numOfServers; i++)
if (!servers[i].isFree())
busyServers++;
return busyServers;
}
void serverListType::setServerBusy(int serverID,
customerType cCustomer,
int tTime)
{
servers[serverID].setBusy();
servers[serverID].setTransactionTime(tTime);
servers[serverID].setCurrentCustomer(cCustomer);
}
void serverListType::setServerBusy(int serverID,
customerType cCustomer)
{
int time;
time = cCustomer.getTransactionTime();
servers[serverID].setBusy();
servers[serverID].setTransactionTime(time);
servers[serverID].setCurrentCustomer(cCustomer);
}
void serverListType::updateServers()
{
int i;
for (i = 0; i < numOfServers; i++)
if (!servers[i].isFree())
{
servers[i].decreaseTransactionTime();
if (servers[i].getRemainingTransactionTime() == 0)
{
cout << "From server no " << (i + 1) << " Customer number "
<< servers[i].getCurrentCustomerNumber()
<< " departed at " << endl
<< " clock unit "
<< servers[i].getCurrentCustomerArrivalTime()
+ servers[i].getCurrentCustomerWaitingTime()
+ servers[i].getCurrentCustomerTransactionTime()
<< endl;
servers[i].setFree();
}
}
}
void serverListType::updateServers(ofstream& outFile)
{
int i;
for (i = 0; i < numOfServers; i++)
if (!servers[i].isFree())
{
servers[i].decreaseTransactionTime();
if (servers[i].getRemainingTransactionTime() == 0)
{
outFile << "From server no " << (i + 1) << " Customer number "
<< servers[i].getCurrentCustomerNumber()
<< " departed at " << endl
<< " clock unit "
<< servers[i].getCurrentCustomerArrivalTime()
+ servers[i].getCurrentCustomerWaitingTime()
+ servers[i].getCurrentCustomerTransactionTime()
<< endl;
servers[i].setFree();
}
}
}
No comments:
Post a Comment