北京工業(yè)大學(xué) 數(shù)據(jù)結(jié)構(gòu)課設(shè)_理發(fā)館 報(bào)告_第1頁(yè)
北京工業(yè)大學(xué) 數(shù)據(jù)結(jié)構(gòu)課設(shè)_理發(fā)館 報(bào)告_第2頁(yè)
北京工業(yè)大學(xué) 數(shù)據(jù)結(jié)構(gòu)課設(shè)_理發(fā)館 報(bào)告_第3頁(yè)
北京工業(yè)大學(xué) 數(shù)據(jù)結(jié)構(gòu)課設(shè)_理發(fā)館 報(bào)告_第4頁(yè)
北京工業(yè)大學(xué) 數(shù)據(jù)結(jié)構(gòu)課設(shè)_理發(fā)館 報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩21頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、理發(fā)館學(xué) 號(hào)_110703xx_ 姓 名_xxx_指導(dǎo)教師_xx_2013年10月目錄1 需求分析 31.1 程序功能介紹 31.2 程序數(shù)據(jù)要求 3 1.3 開(kāi)發(fā)與運(yùn)行環(huán)境需求 41.4 用戶界面設(shè)計(jì) 52 數(shù)據(jù)結(jié)構(gòu)設(shè)計(jì) 72.1 主要數(shù)據(jù)結(jié)構(gòu) 72.2 程序整體結(jié)構(gòu) 112.3 模塊功能描述 113 詳細(xì)設(shè)計(jì) 124 測(cè)試 224.1 正確運(yùn)行示例 224.2 錯(cuò)誤運(yùn)行示例 245 總結(jié)提高 251需求分析1.1程序功能介紹本程序模擬理發(fā)館一天的經(jīng)營(yíng)狀況,理發(fā)館的環(huán)境如下:1理發(fā)館有N把理發(fā)椅,可同時(shí)為N位顧客進(jìn)行理發(fā)(2<N<9);2理發(fā)師按技術(shù)水平分為三個(gè)等級(jí)(一級(jí)最高,三

2、級(jí)最低),對(duì)應(yīng)不同的服務(wù)收費(fèi)。理發(fā)館一天的工作過(guò)程如下:1顧客進(jìn)門時(shí),需要選擇某級(jí)別的理發(fā)師,只要該級(jí)別的理發(fā)師有空椅,則可立即坐下理發(fā),否則需排隊(duì)等候;2一旦該級(jí)別的理發(fā)師有顧客理發(fā)完離去,排在該位理發(fā)師隊(duì)列隊(duì)頭的顧客便可以開(kāi)始理發(fā)。理發(fā)館老板統(tǒng)計(jì)每天不同級(jí)別理發(fā)師的營(yíng)業(yè)時(shí)間、創(chuàng)收和每天理發(fā)館總創(chuàng)收,并寫入文本文件中,可作為理發(fā)師工資與獎(jiǎng)金的發(fā)放依據(jù)。1.2程序數(shù)據(jù)要求1.2.1輸入數(shù)據(jù)(由文本文件輸入):7 :3061 12 13 24 35 26 30.6數(shù)據(jù)說(shuō)明:第一行的09:30表示理發(fā)館將于九點(diǎn)半開(kāi)門;第二行的6表示理發(fā)館有6張理發(fā)椅(此處可輸入39的任意值);隨后的N行:表示第i

3、張椅子的理發(fā)師的級(jí)別(如:第1張理發(fā)椅是1級(jí)理發(fā)師,第2張理發(fā)椅是1級(jí)理發(fā)師)。最后一行的0.6代表折扣(可選)1.2.2隨機(jī)數(shù)據(jù)需求:每個(gè)顧客進(jìn)門時(shí)將負(fù)責(zé)生成三個(gè)隨機(jī)數(shù):1)理發(fā)時(shí)間durtime:進(jìn)門顧客理發(fā)所需服務(wù)時(shí)間;2)間隔時(shí)間intertime:該顧客與下一位顧客到達(dá)的時(shí)間間隔;3)服務(wù)選項(xiàng)select:該顧客選擇理發(fā)師的級(jí)別。由隨機(jī)數(shù)函數(shù)產(chǎn)生。1.2.3輸出數(shù)據(jù)(輸出到文本文件中): 本日賬目清單 =按理發(fā)師=理發(fā)師編號(hào): 1 級(jí)別: 1 工作時(shí)長(zhǎng): 17 本日盈收: 17理發(fā)師編號(hào): 2 級(jí)別: 1 工作時(shí)長(zhǎng): 29 本日盈收: 29理發(fā)師編號(hào): 3 級(jí)別: 2 工作時(shí)長(zhǎng): 2

4、8 本日盈收: 14理發(fā)師編號(hào): 4 級(jí)別: 3 工作時(shí)長(zhǎng): 73 本日盈收: 23理發(fā)師編號(hào): 5 級(jí)別: 2 工作時(shí)長(zhǎng): 24 本日盈收: 12理發(fā)師編號(hào): 6 級(jí)別: 3 工作時(shí)長(zhǎng): 27 本日盈收: 9理發(fā)師編號(hào): 7 級(jí)別: 3 工作時(shí)長(zhǎng): 20 本日盈收: 6理發(fā)師編號(hào): 8 級(jí)別: 1 工作時(shí)長(zhǎng): 30 本日盈收: 30=按級(jí)別=1級(jí)別理發(fā)師總工時(shí): 76 總收入: 762級(jí)別理發(fā)師總工時(shí): 52 總收入: 263級(jí)別理發(fā)師總工時(shí): 120 總收入: 38=總匯=本日總創(chuàng)收: 1401.3開(kāi)發(fā)與運(yùn)行環(huán)境需求1.3.1開(kāi)發(fā)環(huán)境: Visual studio 20101.3.2運(yùn)行環(huán)

5、境: Win xp/Win 7/Win 81.4用戶界面設(shè)計(jì)1.4.1初始化界面(例:6個(gè)隊(duì)列)8隊(duì)列界面1.4.2顧客到達(dá)、理發(fā)及等待界面1.4.3顧客離開(kāi)界面1.4.4 DOS/GUI同步演示程序過(guò)程1.4.5折扣選擇界面2數(shù)據(jù)結(jié)構(gòu)設(shè)計(jì)2.1 主要數(shù)據(jù)結(jié)構(gòu) 2.1.1事件類(Event)/事件類:包含事件發(fā)生時(shí)間,事件類型,和下一個(gè)事件(指針)三個(gè)數(shù)據(jù)成員class Event public: int occurtime; int event_type; Event* next_event; Event() Event(int occurtime, int event_type): occ

6、urtime(occurtime), event_type(event_type), next_event(NULL) Event() ;2.1.2事件表(EventList)/事件表類:數(shù)據(jù)成員 :頭指針,兩個(gè)用于插入刪除事件結(jié)點(diǎn)的指針,和事件表長(zhǎng)度class EventList public: Event *head, *ptr_before, *ptr_after; int length; /事件表長(zhǎng)度 EventList() head = new Event(-1, -1); length=1; EventList() void OrderIn(Event* new_in); int

7、ListEmpty(); int Cmp(Event* new_in, Event* t1) ;2.1.3顧客類(Customer)class Customer public: int durtime; int select; Customer* next; Customer(): select(-1) Customer(int durtime, int select): durtime(durtime), select(select), next(NULL) Customer() ;2.1.4顧客隊(duì)列類(CustomerQueue)class CustomerQueue public: Cu

8、stomer *front, *rear; int select; int length; int worktime; int money; CustomerQueue(): front(NULL), rear(NULL), select(-1), length(0), money(0), worktime(0) CustomerQueue() void EnQueue(Customer* add); void DelQueue();2.1.5隨機(jī)函數(shù)類(Random):class Random public: int durtime; int intertime; int select; R

9、andom() srand(int)time(NULL); Random() int Durtime(); int Intertime(); int Select();2.1.6文件操作類(FileOperation):class FileOperation public: int input_time2;/接收輸入時(shí)間 小時(shí)、分鐘 char maohao;/接收中間的冒號(hào) int number11;/用于接收理發(fā)師編號(hào)信息 int chairs;/理發(fā)師人數(shù) float discount;/折扣(可選) char zhekou; FileOperation(): discount(1.0)

10、FileOperation() void FileInput(ifstream &from_file, int &opentime, CustomerQueue cq, int &closetime); void FileOutput(ofstream &to_file, CustomerQueue cq, int& total_money);2.1.7繪圖類(barbergraph):class barbergraph public: IMAGE background_img;/顧客去背景圖片 IMAGE baber_desk;/理發(fā)師桌子背景 IMA

11、GE my_clock;/時(shí)鐘背景 IMAGE door;/門 char now_time10;/時(shí)鐘信息存儲(chǔ) char barber_info20;/理發(fā)師信息 char graphic_symbol15;/圖例信息 Customer* p;/獲取當(dāng)前動(dòng)作顧客 int chairs;/獲取理發(fā)師人數(shù) barbergraph() /讀取背景圖片集 loadimage(&background_img, _T("背景1.jpg"); loadimage(&baber_desk, _T("六張桌子.jpg"); loadimage(&m

12、y_clock, _T("時(shí)鐘.jpg"); loadimage(&door, _T("門.jpg"); void set_chairs (int chairs);/初始化理發(fā)師人數(shù) void CommonGraph(CustomerQueue cq, int opentime);/通用繪圖界面 void BarberGraph(CustomerQueue cq,int opentime);/無(wú)事件狀態(tài)界面 void ArriveBarberGraph(CustomerQueue cq, int arrival, int nowtime);/顧客

13、到來(lái)界面 void DepartBarberGraph(CustomerQueue cq, int departure, int nowtime);/顧客離開(kāi)界面 barbergraph() ;2.1.8理發(fā)館類(Barbershop):class BarberShop public: EventList ev;/事件表 CustomerQueue cq11;/六個(gè)顧客隊(duì)列110可選 int opentime;/開(kāi)門時(shí)間 Event* cur_event;/當(dāng)前事件 Event* new_event;/初始事件 Customer* new_customer;/新顧客 指針 int closet

14、ime;/TODO:目前為調(diào)試數(shù)據(jù)(22:00理想,未實(shí)現(xiàn)) int total_money;/理發(fā)館一天總收入 int chairs;/接收理發(fā)師人數(shù) BarberShop(): cur_event(NULL), new_customer(NULL), total_money(0) void OpenForDay(barbergraph &bg, int chairs);/開(kāi)門初始化函數(shù) int Minimum(int select);/求同級(jí)別最短隊(duì)列函數(shù) void CustomerArrived(Random &ran, barbergraph &bg);/顧客到

15、來(lái) void CustomerDeparture(barbergraph &bg);/顧客離開(kāi) void BarberSimulation(Random &ran, barbergraph &bg, int chairs);/事件驅(qū)動(dòng)模型 BarberShop() ;2.2 程序整體結(jié)構(gòu)main2.2.1函數(shù)調(diào)用圖:FileoutputFileinputBarberSimulationListEmptyCustomerDepartureCustomerArrivedOpenForDayDelQueueEnQueueOrderInBarberGraphMinimumDep

16、artBarberGraphArriveBarberGraph2.3 模塊功能描述2.3.1 Event:作為EventList的結(jié)點(diǎn)元素,數(shù)據(jù):事件類型、事件發(fā)生的時(shí)間2.3.2 EventList:事件表,為有序表。數(shù)據(jù):頭指針,時(shí)間表長(zhǎng)度length;操作:插入、刪除Event2.3.3 Customer:保存顧客信息。數(shù)據(jù):durtime,select2.3.4 CustomerQueue:保存顧客隊(duì)列信息以及理發(fā)師信息。數(shù)據(jù):select,length,worktime,money,頭尾指針;操作:入隊(duì),出隊(duì);2.3.5 Random:生成要求中的三個(gè)隨機(jī)數(shù)。2.3.6 FileOp

17、eration:從文件讀入數(shù)據(jù),向文件輸出數(shù)據(jù)。2.3.7 BarberGraph:繪制圖形界面,包括初始化界面、顧客到來(lái)、顧客離開(kāi)界面。2.3.8 barbershop:處理顧客到來(lái),顧客離開(kāi),含事件驅(qū)動(dòng)主程序。3詳細(xì)設(shè)計(jì)3.1.1 eventlist.cpp#include "eventlist.h"void EventList:OrderIn(Event* new_in)/插入事件表 if (1 = length) /如果長(zhǎng)度為一,直接插入 head->next_event = new_in; length+; return; else /如果長(zhǎng)度不為一,用兩指

18、針一前一后進(jìn)行插入操作 ptr_before = head->next_event; ptr_after = head; while (ptr_before != NULL) if (-1 = Cmp(new_in,ptr_before) /如果插入事件在前 new_in->next_event = ptr_before; ptr_after->next_event = new_in; length+; return; /如果在此結(jié)點(diǎn)之后,后移一位繼續(xù)比較 ptr_after = ptr_before; ptr_before = ptr_before->next_eve

19、nt; ptr_after->next_event = new_in;/如果在最后,直接插到表尾 length+; int EventList:ListEmpty() if (length > 1) return 0; else return 1;3.1.2 customerqueue.cpp#include "customerqueue.h"void CustomerQueue:EnQueue(Customer* add) if (NULL = rear) /如果隊(duì)伍沒(méi)人,直接入隊(duì) front = rear = add; else rear->next

20、= add; rear = rear->next; length+;void CustomerQueue:DelQueue() if (0 != length) Customer* p = front; front = front->next; if (rear = p) rear = NULL; delete p;/釋放隊(duì)頭結(jié)點(diǎn)空間 length-; 3.1.3 random.cpp#include "random.h"int Random:Durtime() return rand()%21+10;/隨機(jī)一個(gè)1030的數(shù)(持續(xù)時(shí)間)int Random:In

21、tertime() return rand()%6;/隨機(jī)一個(gè)0到5的數(shù)(間隔時(shí)間)int Random:Select() return rand()%3+1;/隨機(jī)一個(gè)13的數(shù)(級(jí)別)3.1.4 fileoperation.cpp#include "fileoperation.h"using namespace std;void FileOperation:FileInput(ifstream &from_file, int &opentime, CustomerQueue cq, int &closetime) from_file>>

22、input_time0>>maohao>>input_time1;/接收開(kāi)門時(shí)間 opentime = 60*input_time0+input_time1;/將時(shí)間轉(zhuǎn)化為int from_file>>chairs;/接收理發(fā)師人數(shù) if (chairs>8|chairs<3) cout<<"input error, the number of chairs should between 3 and 8!"<<endl; _getch(); exit(0); for (int i = 1; i <

23、 chairs+1; i+) /初始化理發(fā)師信息 from_file>>numberi; from_file>>cqi.select; from_file>>input_time0>>maohao>>input_time1;/接收關(guān)門時(shí)間 closetime = 60*input_time0+input_time1;/關(guān)門時(shí)間轉(zhuǎn)化 cout<<"提供折扣? y/n"<<endl; cin>>zhekou; if ('y' = zhekou) from_file&g

24、t;>discount; cout<<"本日折扣為 "<<discount <<" !"<<endl; else cout<<"本店今日不打折!"<<endl; from_file.close();/關(guān)閉讀文件void FileOperation:FileOutput(ofstream &to_file, CustomerQueue cq, int& total_money) int class_money4 = 0;/按理發(fā)師級(jí)別統(tǒng)計(jì)當(dāng)天收

25、入 int class_worktime4 = 0;/按理發(fā)師級(jí)別統(tǒng)計(jì)當(dāng)天工時(shí) to_file<<" 本日賬目清單 "<<endl<<endl; to_file<<"=按理發(fā)師="<<endl<<endl; for (int i = 1; i < chairs+1; i+) to_file<<"理發(fā)師編號(hào): "<<i<<" 級(jí)別: "<<cqi.select<<" 工作

26、時(shí)長(zhǎng): "<<cqi.worktime<<" 本日盈收: "<<cqi.money<<endl; to_file<<"=按級(jí)別="<<endl<<endl; for (int i = 1; i < chairs+1; i+) /按級(jí)別統(tǒng)計(jì)理發(fā)師工資和工時(shí) if (1 = cqi.select) class_money1 += cqi.money; class_worktime1 += cqi.worktime; if (2 = cqi.select) cl

27、ass_money2 += cqi.money; class_worktime2 += cqi.worktime; if (3 = cqi.select) class_money3 += cqi.money; class_worktime3 += cqi.worktime; for (int i = 1; i < 4; i+) /按級(jí)別將理發(fā)師的工資和工時(shí)、總創(chuàng)收輸出到文件中 to_file<<i<<"級(jí)別理發(fā)師總工時(shí): "<<class_worktimei<<" 總收入: "<<clas

28、s_moneyi<<endl; to_file<<"=總匯="<<endl<<endl; to_file<<"本日總創(chuàng)收: "<<total_money; to_file.close();/關(guān)閉寫文件3.1.5 barbergraph.cpp#include "barbergraph.h"void barbergraph:set_chairs (int chairs) this->chairs = chairs;/通用繪圖函數(shù),負(fù)責(zé)繪制圖例,時(shí)鐘,理發(fā)師信息

29、(不包括隊(duì)列),主要用于刷新界面void barbergraph:CommonGraph(CustomerQueue cq, int opentime) /此處的opentime為nowtime BeginBatchDraw();/開(kāi)始批量繪圖,避免閃爍 putimage(0, 0, &my_clock);/將圖片集分別插到對(duì)應(yīng)區(qū)域 putimage(120, 100, &background_img); putimage(120, 0, &baber_desk); putimage(0, 470, &door); rectangle(0, 0, 120, 65

30、0);/左側(cè)框 /輸出時(shí)鐘信息 if (opentime-420)%60 < 10) /如果分鐘小于10,在顯示前面加0 sprintf_s(now_time, "%d:0%d", 7+(opentime-420)/60, (opentime-420)%60); else sprintf_s(now_time, "%d:%d", 7+(opentime-420)/60, (opentime-420)%60); setfont(50, 0, "黑體");/設(shè)置時(shí)鐘字體 setcolor(RED);/時(shí)鐘字體顏色 outtextxy

31、(10, 20, now_time); setfont(15, 0, "黑體");/恢復(fù)初始字體 setcolor(WHITE);/恢復(fù)初始字體顏色 /輸出圖例信息 for (int i = 0; i < 5; i+) if (0 = i) sprintf_s(graphic_symbol, " 圖例:"); if (1 = i) sprintf_s(graphic_symbol, "顧客到達(dá)"); rectangle(20, 170+i*70, 90, 190+i*70); setfillstyle(BLUE,SOLID_FI

32、LL); floodfill(55, 175+i*70, WHITE); if (2 = i) sprintf_s(graphic_symbol, "顧客等待"); rectangle(20, 170+i*70, 90, 190+i*70); setfillstyle(RED,SOLID_FILL); floodfill(55, 175+i*70, WHITE); if (3 = i) sprintf_s(graphic_symbol, "顧客離開(kāi)"); rectangle(20, 170+i*70, 90, 190+i*70); setfillstyl

33、e(GREEN,SOLID_FILL); floodfill(55, 175+i*70, WHITE); if (4 = i) sprintf_s(graphic_symbol, "顧客理發(fā)中"); rectangle(20, 170+i*70, 90, 190+i*70); setfillstyle(YELLOW,SOLID_FILL); floodfill(55, 175+i*70, WHITE); outtextxy(20, 150+i*70,graphic_symbol); /繪制理發(fā)師信息 for (int i = 0; i < chairs; i+) re

34、ctangle(120+i*150, 0, 120+(i+1)*150, 100); for (int i = 1; i < chairs+1; i+) sprintf_s(barber_info, "編號(hào)%d 級(jí)別:%d", i, cqi.select); outtextxy(155+150*(i-1), 40, barber_info); /靜態(tài)繪圖函數(shù),用于初始化界面和顧客離開(kāi)后暫停畫面void barbergraph:BarberGraph(CustomerQueue cq,int opentime) CommonGraph(cq, opentime); fo

35、r (int i = 1; i < chairs+1; i+) p = cqi.front; int j = 0; while (p != NULL) circle(195+150*(i-1), 230+50*j+, 20); if (1= j) setfillstyle(YELLOW,SOLID_FILL);/設(shè)置填充模式: 黃色,固實(shí)填充 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐標(biāo)所在的封閉區(qū)域?yàn)樘畛鋵?duì)象,最后一個(gè)參數(shù)為邊框顏色 else setfillstyle(RED,SOLID_FILL);/設(shè)置填充模式: 紅色,固實(shí)填充

36、 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐標(biāo)所在的封閉區(qū)域?yàn)樘畛鋵?duì)象,最后一個(gè)參數(shù)為邊框顏色 p = p->next; EndBatchDraw();/結(jié)束批量繪圖 _getch(); /cleardevice();/以當(dāng)前背景色清屏(黑色)/繪制顧客到來(lái)瞬間界面void barbergraph:ArriveBarberGraph(CustomerQueue cq, int arrival, int nowtime) CommonGraph(cq, nowtime); for (int i = 1; i < chairs+1;

37、 i+) p = cqi.front; int j = 0; while (p != NULL) circle(195+150*(i-1), 230+50*j+, 20); if (1= j) setfillstyle(YELLOW,SOLID_FILL);/設(shè)置填充模式: 黃色,固實(shí)填充 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐標(biāo)所在的封閉區(qū)域?yàn)樘畛鋵?duì)象,最后一個(gè)參數(shù)為邊框顏色 if (i = arrival && p->next = NULL) setfillstyle(BLUE,SOLID_FILL);/設(shè)置填

38、充模式: 藍(lán)色,固實(shí)填充 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐標(biāo)所在的封閉區(qū)域?yàn)樘畛鋵?duì)象,最后一個(gè)參數(shù)為邊框顏色 else if (j > 1) setfillstyle(RED,SOLID_FILL);/設(shè)置填充模式: 紅色,固實(shí)填充 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐標(biāo)所在的封閉區(qū)域?yàn)樘畛鋵?duì)象,最后一個(gè)參數(shù)為邊框顏色 p = p->next; EndBatchDraw(); _getch(); /cleardevice();/以當(dāng)前背景色清屏(黑色)/繪制顧

39、客離開(kāi)瞬間界面void barbergraph:DepartBarberGraph(CustomerQueue cq, int departure, int nowtime) CommonGraph(cq, nowtime); for (int i = 1; i < chairs+1; i+) /隊(duì)列動(dòng)態(tài)變換部分 p = cqi.front; int j = 0; while (p != NULL) circle(195+150*(i-1), 230+50*j+, 20); if (1= j) setfillstyle(YELLOW,SOLID_FILL);/設(shè)置填充模式: 黃色,固實(shí)填

40、充 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐標(biāo)所在的封閉區(qū)域?yàn)樘畛鋵?duì)象,最后一個(gè)參數(shù)為邊框顏色 if (i = departure && p = cqi.front) setfillstyle(GREEN,SOLID_FILL); floodfill(195+150*(i-1), 230+50*(j-1), WHITE); else if (j > 1) setfillstyle(RED,SOLID_FILL);/設(shè)置填充模式: 紅色,固實(shí)填充 floodfill(195+150*(i-1), 230+50*(j-1

41、), WHITE);/坐標(biāo)所在的封閉區(qū)域?yàn)樘畛鋵?duì)象,最后一個(gè)參數(shù)為邊框顏色 p = p->next; EndBatchDraw(); _getch(); /cleardevice();/以當(dāng)前背景色清屏(黑色)3.1.6 barbershop.cpp#include "barbershop.h"using namespace std;void BarberShop:OpenForDay(barbergraph &bg, int chairs) this->chairs = chairs;/從輸入函數(shù)中得到理發(fā)師人數(shù) bg.set_chairs(chair

42、s);/將理發(fā)師人數(shù)傳到繪圖對(duì)象中 initgraph(1024+(chairs-6)*150, 650, 1);/初始化界面大?。ǜ鶕?jù)理發(fā)師人數(shù)來(lái)初始化大?。?setbkmode(TRANSPARENT);/設(shè)置文字或圖片輸出背景為透明 setfont(15, 0, "黑體");/初始化字體 setcolor(WHITE);/初始化字體顏色 bg.BarberGraph(cq, opentime);/初始化界面信息 Event* new_event = new Event(opentime, 0);/創(chuàng)建第一個(gè)事件 ev.OrderIn(new_event);/插入事件表

43、/OpenForDayint BarberShop:Minimum(int select) int min_cq = 1000;/最短隊(duì)列初始值 int min_length = 1000;/假定初始最短長(zhǎng)度為無(wú)窮 for (int i = 1; i <= chairs; i+) /尋找符合select的最短隊(duì)列 if (cqi.select = select && cqi.length < min_length) min_length = cqi.length; min_cq = i; return min_cq;/返回最短隊(duì)列號(hào)void BarberShop:C

44、ustomerArrived(Random &ran, barbergraph &bg, float discount) /處理客戶到達(dá)事件 int select = ran.Select();/隨機(jī)生成本顧客的理發(fā)師級(jí)別選擇 int durtime = ran.Durtime();/隨機(jī)生成本顧客的理發(fā)時(shí)長(zhǎng) int intertime = ran.Intertime();/隨機(jī)生成下一個(gè)顧客的到來(lái)時(shí)間間隔 int money = durtime/select*discount;/本顧客的消費(fèi)額(收費(fèi)公式) int min_cq; /記錄最短隊(duì)列信息 new_customer

45、= new Customer(durtime, select);/生成本顧客實(shí)體 total_money += money;/計(jì)入總收入 min_cq = Minimum(select);/求最短隊(duì)列 cout<<"min_cq:"<<min_cq<<" " cout<<"selece:"<<select<<" "<<"durtime:"<<durtime<<" "&l

46、t;<"intertime:"<<intertime<<" " cout<<"("<<7+(cur_event->occurtime-420)/60<<":" <<(cur_event->occurtime-420)%60<<","<<cur_event->event_type<<")"<<endl;/時(shí)間轉(zhuǎn)換公式 cqmin_cq.

47、money += money; /計(jì)入min_cq隊(duì)列理發(fā)師總收入 cqmin_cq.worktime += durtime;/計(jì)入min_cq隊(duì)列理發(fā)師工作時(shí)間 cqmin_cq.EnQueue(new_customer);/入隊(duì) bg.ArriveBarberGraph(cq, min_cq, cur_event->occurtime);/在圖形界面上顯示到來(lái)顧客 int t = cur_event->occurtime + intertime;/下一顧客的到來(lái)時(shí)間 if (t < closetime) /下一顧客到來(lái)未關(guān)門 new_event = new Event(t

48、, 0); ev.OrderIn(new_event);/生成下一顧客到達(dá)事件插入事件表 if (1 = cqmin_cq.length) /如果新來(lái)的顧客在隊(duì)頭 new_event = new Event(cur_event->occurtime+durtime, min_cq); ev.OrderIn(new_event);/生成本顧客的離開(kāi)事件插入事件表 /CustomerArrived/客戶離開(kāi)事件void BarberShop:CustomerDeparture(barbergraph &bg) /注意:隊(duì)列中超過(guò)兩個(gè)人時(shí)下個(gè)人的離開(kāi)事件從前一個(gè)人離開(kāi)時(shí)開(kāi)始計(jì)時(shí)。 in

49、t i = cur_event->event_type; /記錄要?jiǎng)h除的隊(duì)列編號(hào) cout<<"dep_cq:"<<i<<" " cout<<"("<<7+(cur_event->occurtime-420)/60<<":" <<(cur_event->occurtime-420)%60<<","<<cur_event->event_type<<&quo

50、t;)"<<endl; bg.DepartBarberGraph(cq, i, cur_event->occurtime);/將離開(kāi)的顧客用圖形表示出來(lái) cqi.DelQueue(); /刪除第i隊(duì)的排頭客戶 bg.BarberGraph(cq, cur_event->occurtime);/繪制顧客離開(kāi)后的畫面 if (0 != cqi.length) /設(shè)定第i隊(duì)列的隊(duì)頭離開(kāi)事件插入事件表 new_event = new Event(cur_event->occurtime + cqi.front->durtime, i); ev.OrderIn(new_event); /CustomerDeparturevoid BarberShop:BarberSimulation(Random &ran, barbergraph &bg, int chairs, float discount) OpenForDay(bg, chairs);/開(kāi)門初始化 while (!ev.ListEmpty() /事件驅(qū)動(dòng)主體,只要事件表不為空則一直執(zhí)行第一個(gè)事件 cur_event = ev.head->next_event;/獲取當(dāng)前事件(表中第二個(gè)結(jié)點(diǎn)) if (0 = cur_event->ev

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論