《数据结构(C++)》学习辅导系列:队列应用(2)

《数据结构(C++)》学习辅导系列:队列应用(2),第1张

《数据结构(C++)》学习辅导系列:队列应用(2),第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);
   }

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » 《数据结构(C++)》学习辅导系列:队列应用(2)

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情