?? page122.cpp
字號:
#include <iostream.h> // #include "stdlib.h" enum EventType { Arrival, Departure }; class Event { //事件類定義 public: Event ( ); //構造函數 Event ( int t, EventType et, int cn, int tn, int wt, int st ); //構造函數 int GetTime ( ) const; //取出到達或離開時間,視類型不同 EventType GetEventType ( ) const; //取出事件類型 int GetCustomerID ( ) const; //取出客戶標識 int GetTellerID ( ) const; //取出出納窗口標識 int GetWaitTime ( ) const; //取出等待時間 int GetServiceTime ( ) const; //取出服務時間 private: int time; //客戶到達 | 離開時間 EventType eType; //客戶類型:Arrival | Departure int customerID; //客戶標識,編號為1, 2, 3, … int tellerID; //出納窗口標識,編號為1, 2, 3, … int waitTime; //客戶等待時間 int serviceTime; //客戶服務時間 }; struct TellerStatus { //有關出納窗口的信息的記錄 int finishService; //什么時候出納窗口空閑 int totalCustomerCount; //服務過的客戶總數 int totalCustomerWait; //客戶總的等待時間 int totalService; //總的服務時間 }; #include <pqueue.h>class Simulation { //模擬類聲明 public: Simulation ( ); //構造函數 void RunSimulation ( ); //執行模擬 void PrintSimulationResults ( ); //打印狀態 private: int simulationLength; //模擬的時間長度 int numTellers; //出納窗口個數 int nextCustomer; //下一位客戶的編號 int arrivalLow, arrivalHigh; //下一次到達的時間范圍 TellerStatus tstat [11]; //最多10個出納窗口 PQueue<Event> pq; //優先級隊列 //RandomNumber rnd; //用于到達和服務的時間 int NextArrivalTime ( ); //私有函數: 產生下一次到達的時間 int GetServiceTime ( ); //私有函數: 取得服務時間 int NextAvailableTeller ( ); //私有函數: 產生下一個可用的出納窗口 }; Simulation::Simulation ( ) { //構造函數 Event firstEvent ( 0, Arrival, 1, 0, 0, 0 ); //第一個到達事件 for ( int i=1; i<=10; i++ ) { //初始化出納窗口信息 tstat[i].finishService = 0; tstat[i].totalService = 0; tstat[i].totalCustomerWait = 0; tstat[i].totalCustomerCount = 0; } nextCustomer = 1; //下一位客戶編號從1開始 cout << "Enter the simulation time in minutes : "; cin >> simulationLength; //輸入模擬時間長度(以分鐘計) cout << "Enter the number of bank tellers : "; cin >> numTellers; //輸入出納窗口個數 cout << "Enter the range of arrival time in minutes : "; cin >> arrivalLow >> arrivalHigh; //輸入下一次到達的時間范圍 cout << "Enter the range of service time in minutes : "; cin >> serviceLow >> serviceHigh; //輸入服務的時間范圍 pq.PQInsert ( firstEvent ); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -