《数据结构(C++)》学习辅导系列:队列应用(2)
void printresult()
{
int tsn = 0;
long tst = 0;
cout << endl;
cout << "-------------模拟结果------------------";
cout << endl << "tellerid\tservicenum\tservicetime\taveragetime" << endl;
for (int i = 1; i <= tellernum; i++)
{
cout << "teller " << i;
cout << ’\t’ << tellers[i].totalcustomercount << " "; tsn += ellers[i].totalcustomercount;
cout << ’\t’ << tellers[i].totalservicetime << " "; tst += long)tellers[i].totalservicetime;
cout << ’\t’;
if (tellers[i].totalcustomercount)
cout << (float)tellers[i].totalservicetime/(float)tellers[i].totalcustomercount;
else cout << 0;
cout << " " << endl;
}
cout << "total \t" << tsn << " \t" << tst << " \t";
if (tsn) cout << (float)tst/(float)tsn; else cout << 0;
cout << " " << endl;
cout << "customer number:\t" << customernum << "\tno service:\t" << customernum - tsn << endl;
cout << "customer waittime:\t" << customertime << "\tavgwaittime:\t";
if (tsn) cout << (float)customertime/(float)tsn; else cout << 0;
cout << endl;
}
private:
int tellernum;
int simutime;
int curtime, nexttime;
int customernum;
long customertime;
int arrivallow, arrivalhigh, arrivalrange;
int servicelow, servicehigh, servicerange;
teller tellers[21];
queue customer;
void nextarrived()
{
nexttime += arrivallow + rand() % arrivalrange;
}
int nextservice()
{
return servicelow + rand() % servicerange;
}
void customerarrived()
{
customernum++;
customer.enqueue(nexttime);
}
0条评论