版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、理发馆学 号_110703xx_ 姓 名_xxx_指导教师_xx_2013年10月目录1 需求分析 31.1 程序功能介绍 31.2 程序数据要求 3 1.3 开发与运行环境需求 41.4 用户界面设计 52 数据结构设计 72.1 主要数据结构 72.2 程序整体结构 112.3 模块功能描述 113 详细设计 124 测试 224.1 正确运行示例 224.2 错误运行示例 245 总结提高 251需求分析1.1程序功能介绍本程序模拟理发馆一天的经营状况,理发馆的环境如下:1理发馆有N把理发椅,可同时为N位顾客进行理发(2<N<9);2理发师按技术水平分为三个等级(一级最高,三
2、级最低),对应不同的服务收费。理发馆一天的工作过程如下:1顾客进门时,需要选择某级别的理发师,只要该级别的理发师有空椅,则可立即坐下理发,否则需排队等候;2一旦该级别的理发师有顾客理发完离去,排在该位理发师队列队头的顾客便可以开始理发。理发馆老板统计每天不同级别理发师的营业时间、创收和每天理发馆总创收,并写入文本文件中,可作为理发师工资与奖金的发放依据。1.2程序数据要求1.2.1输入数据(由文本文件输入):7 :3061 12 13 24 35 26 30.6数据说明:第一行的09:30表示理发馆将于九点半开门;第二行的6表示理发馆有6张理发椅(此处可输入39的任意值);随后的N行:表示第i
3、张椅子的理发师的级别(如:第1张理发椅是1级理发师,第2张理发椅是1级理发师)。最后一行的0.6代表折扣(可选)1.2.2随机数据需求:每个顾客进门时将负责生成三个随机数:1)理发时间durtime:进门顾客理发所需服务时间;2)间隔时间intertime:该顾客与下一位顾客到达的时间间隔;3)服务选项select:该顾客选择理发师的级别。由随机数函数产生。1.2.3输出数据(输出到文本文件中): 本日账目清单 =按理发师=理发师编号: 1 级别: 1 工作时长: 17 本日盈收: 17理发师编号: 2 级别: 1 工作时长: 29 本日盈收: 29理发师编号: 3 级别: 2 工作时长: 2
4、8 本日盈收: 14理发师编号: 4 级别: 3 工作时长: 73 本日盈收: 23理发师编号: 5 级别: 2 工作时长: 24 本日盈收: 12理发师编号: 6 级别: 3 工作时长: 27 本日盈收: 9理发师编号: 7 级别: 3 工作时长: 20 本日盈收: 6理发师编号: 8 级别: 1 工作时长: 30 本日盈收: 30=按级别=1级别理发师总工时: 76 总收入: 762级别理发师总工时: 52 总收入: 263级别理发师总工时: 120 总收入: 38=总汇=本日总创收: 1401.3开发与运行环境需求1.3.1开发环境: Visual studio 20101.3.2运行环
5、境: Win xp/Win 7/Win 81.4用户界面设计1.4.1初始化界面(例:6个队列)8队列界面1.4.2顾客到达、理发及等待界面1.4.3顾客离开界面1.4.4 DOS/GUI同步演示程序过程1.4.5折扣选择界面2数据结构设计2.1 主要数据结构 2.1.1事件类(Event)/事件类:包含事件发生时间,事件类型,和下一个事件(指针)三个数据成员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)/事件表类:数据成员 :头指针,两个用于插入删除事件结点的指针,和事件表长度class EventList public: Event *head, *ptr_before, *ptr_after; int length; /事件表长度 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顾客队列类(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随机函数类(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;/接收输入时间 小时、分钟 char maohao;/接收中间的冒号 int number11;/用于接收理发师编号信息 int chairs;/理发师人数 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;/理发师桌子背景 IMA
11、GE my_clock;/时钟背景 IMAGE door;/门 char now_time10;/时钟信息存储 char barber_info20;/理发师信息 char graphic_symbol15;/图例信息 Customer* p;/获取当前动作顾客 int chairs;/获取理发师人数 barbergraph() /读取背景图片集 loadimage(&background_img, _T("背景1.jpg"); loadimage(&baber_desk, _T("六张桌子.jpg"); loadimage(&m
12、y_clock, _T("时钟.jpg"); loadimage(&door, _T("门.jpg"); void set_chairs (int chairs);/初始化理发师人数 void CommonGraph(CustomerQueue cq, int opentime);/通用绘图界面 void BarberGraph(CustomerQueue cq,int opentime);/无事件状态界面 void ArriveBarberGraph(CustomerQueue cq, int arrival, int nowtime);/顾客
13、到来界面 void DepartBarberGraph(CustomerQueue cq, int departure, int nowtime);/顾客离开界面 barbergraph() ;2.1.8理发馆类(Barbershop):class BarberShop public: EventList ev;/事件表 CustomerQueue cq11;/六个顾客队列110可选 int opentime;/开门时间 Event* cur_event;/当前事件 Event* new_event;/初始事件 Customer* new_customer;/新顾客 指针 int closet
14、ime;/TODO:目前为调试数据(22:00理想,未实现) int total_money;/理发馆一天总收入 int chairs;/接收理发师人数 BarberShop(): cur_event(NULL), new_customer(NULL), total_money(0) void OpenForDay(barbergraph &bg, int chairs);/开门初始化函数 int Minimum(int select);/求同级别最短队列函数 void CustomerArrived(Random &ran, barbergraph &bg);/顾客到
15、来 void CustomerDeparture(barbergraph &bg);/顾客离开 void BarberSimulation(Random &ran, barbergraph &bg, int chairs);/事件驱动模型 BarberShop() ;2.2 程序整体结构main2.2.1函数调用图:FileoutputFileinputBarberSimulationListEmptyCustomerDepartureCustomerArrivedOpenForDayDelQueueEnQueueOrderInBarberGraphMinimumDep
16、artBarberGraphArriveBarberGraph2.3 模块功能描述2.3.1 Event:作为EventList的结点元素,数据:事件类型、事件发生的时间2.3.2 EventList:事件表,为有序表。数据:头指针,时间表长度length;操作:插入、删除Event2.3.3 Customer:保存顾客信息。数据:durtime,select2.3.4 CustomerQueue:保存顾客队列信息以及理发师信息。数据:select,length,worktime,money,头尾指针;操作:入队,出队;2.3.5 Random:生成要求中的三个随机数。2.3.6 FileOp
17、eration:从文件读入数据,向文件输出数据。2.3.7 BarberGraph:绘制图形界面,包括初始化界面、顾客到来、顾客离开界面。2.3.8 barbershop:处理顾客到来,顾客离开,含事件驱动主程序。3详细设计3.1.1 eventlist.cpp#include "eventlist.h"void EventList:OrderIn(Event* new_in)/插入事件表 if (1 = length) /如果长度为一,直接插入 head->next_event = new_in; length+; return; else /如果长度不为一,用两指
18、针一前一后进行插入操作 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; /如果在此结点之后,后移一位继续比较 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) /如果队伍没人,直接入队 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;/释放队头结点空间 length-; 3.1.3 random.cpp#include "random.h"int Random:Durtime() return rand()%21+10;/随机一个1030的数(持续时间)int Random:In
21、tertime() return rand()%6;/随机一个0到5的数(间隔时间)int Random:Select() return rand()%3+1;/随机一个13的数(级别)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;/接收开门时间 opentime = 60*input_time0+input_time1;/将时间转化为int from_file>>chairs;/接收理发师人数 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+) /初始化理发师信息 from_file>>numberi; from_file>>cqi.select; from_file>>input_time0>>maohao>>input_time1;/接收关门时间 closetime = 60*input_time0+input_time1;/关门时间转化 cout<<"提供折扣? y/n"<<endl; cin>>zhekou; if ('y' = zhekou) from_file&g
24、t;>discount; cout<<"本日折扣为 "<<discount <<" !"<<endl; else cout<<"本店今日不打折!"<<endl; from_file.close();/关闭读文件void FileOperation:FileOutput(ofstream &to_file, CustomerQueue cq, int& total_money) int class_money4 = 0;/按理发师级别统计当天收
25、入 int class_worktime4 = 0;/按理发师级别统计当天工时 to_file<<" 本日账目清单 "<<endl<<endl; to_file<<"=按理发师="<<endl<<endl; for (int i = 1; i < chairs+1; i+) to_file<<"理发师编号: "<<i<<" 级别: "<<cqi.select<<" 工作
26、时长: "<<cqi.worktime<<" 本日盈收: "<<cqi.money<<endl; to_file<<"=按级别="<<endl<<endl; for (int i = 1; i < chairs+1; i+) /按级别统计理发师工资和工时 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+) /按级别将理发师的工资和工时、总创收输出到文件中 to_file<<i<<"级别理发师总工时: "<<class_worktimei<<" 总收入: "<<clas
28、s_moneyi<<endl; to_file<<"=总汇="<<endl<<endl; to_file<<"本日总创收: "<<total_money; to_file.close();/关闭写文件3.1.5 barbergraph.cpp#include "barbergraph.h"void barbergraph:set_chairs (int chairs) this->chairs = chairs;/通用绘图函数,负责绘制图例,时钟,理发师信息
29、(不包括队列),主要用于刷新界面void barbergraph:CommonGraph(CustomerQueue cq, int opentime) /此处的opentime为nowtime BeginBatchDraw();/开始批量绘图,避免闪烁 putimage(0, 0, &my_clock);/将图片集分别插到对应区域 putimage(120, 100, &background_img); putimage(120, 0, &baber_desk); putimage(0, 470, &door); rectangle(0, 0, 120, 65
30、0);/左侧框 /输出时钟信息 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, "黑体");/设置时钟字体 setcolor(RED);/时钟字体颜色 outtextxy
31、(10, 20, now_time); setfont(15, 0, "黑体");/恢复初始字体 setcolor(WHITE);/恢复初始字体颜色 /输出图例信息 for (int i = 0; i < 5; i+) if (0 = i) sprintf_s(graphic_symbol, " 图例:"); if (1 = i) sprintf_s(graphic_symbol, "顾客到达"); 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, "顾客离开"); 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, "顾客理发中"); 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); /绘制理发师信息 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, "编号%d 级别:%d", i, cqi.select); outtextxy(155+150*(i-1), 40, barber_info); /静态绘图函数,用于初始化界面和顾客离开后暂停画面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);/设置填充模式: 黄色,固实填充 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐标所在的封闭区域为填充对象,最后一个参数为边框颜色 else setfillstyle(RED,SOLID_FILL);/设置填充模式: 红色,固实填充
36、 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐标所在的封闭区域为填充对象,最后一个参数为边框颜色 p = p->next; EndBatchDraw();/结束批量绘图 _getch(); /cleardevice();/以当前背景色清屏(黑色)/绘制顾客到来瞬间界面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);/设置填充模式: 黄色,固实填充 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐标所在的封闭区域为填充对象,最后一个参数为边框颜色 if (i = arrival && p->next = NULL) setfillstyle(BLUE,SOLID_FILL);/设置填
38、充模式: 蓝色,固实填充 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐标所在的封闭区域为填充对象,最后一个参数为边框颜色 else if (j > 1) setfillstyle(RED,SOLID_FILL);/设置填充模式: 红色,固实填充 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐标所在的封闭区域为填充对象,最后一个参数为边框颜色 p = p->next; EndBatchDraw(); _getch(); /cleardevice();/以当前背景色清屏(黑色)/绘制顾
39、客离开瞬间界面void barbergraph:DepartBarberGraph(CustomerQueue cq, int departure, int nowtime) CommonGraph(cq, nowtime); for (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);/设置填充模式: 黄色,固实填
40、充 floodfill(195+150*(i-1), 230+50*(j-1), WHITE);/坐标所在的封闭区域为填充对象,最后一个参数为边框颜色 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);/设置填充模式: 红色,固实填充 floodfill(195+150*(i-1), 230+50*(j-1
41、), WHITE);/坐标所在的封闭区域为填充对象,最后一个参数为边框颜色 p = p->next; EndBatchDraw(); _getch(); /cleardevice();/以当前背景色清屏(黑色)3.1.6 barbershop.cpp#include "barbershop.h"using namespace std;void BarberShop:OpenForDay(barbergraph &bg, int chairs) this->chairs = chairs;/从输入函数中得到理发师人数 bg.set_chairs(chair
42、s);/将理发师人数传到绘图对象中 initgraph(1024+(chairs-6)*150, 650, 1);/初始化界面大小(根据理发师人数来初始化大小) setbkmode(TRANSPARENT);/设置文字或图片输出背景为透明 setfont(15, 0, "黑体");/初始化字体 setcolor(WHITE);/初始化字体颜色 bg.BarberGraph(cq, opentime);/初始化界面信息 Event* new_event = new Event(opentime, 0);/创建第一个事件 ev.OrderIn(new_event);/插入事件表
43、/OpenForDayint BarberShop:Minimum(int select) int min_cq = 1000;/最短队列初始值 int min_length = 1000;/假定初始最短长度为无穷 for (int i = 1; i <= chairs; i+) /寻找符合select的最短队列 if (cqi.select = select && cqi.length < min_length) min_length = cqi.length; min_cq = i; return min_cq;/返回最短队列号void BarberShop:C
44、ustomerArrived(Random &ran, barbergraph &bg, float discount) /处理客户到达事件 int select = ran.Select();/随机生成本顾客的理发师级别选择 int durtime = ran.Durtime();/随机生成本顾客的理发时长 int intertime = ran.Intertime();/随机生成下一个顾客的到来时间间隔 int money = durtime/select*discount;/本顾客的消费额(收费公式) int min_cq; /记录最短队列信息 new_customer
45、= new Customer(durtime, select);/生成本顾客实体 total_money += money;/计入总收入 min_cq = Minimum(select);/求最短队列 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;/时间转换公式 cqmin_cq.
47、money += money; /计入min_cq队列理发师总收入 cqmin_cq.worktime += durtime;/计入min_cq队列理发师工作时间 cqmin_cq.EnQueue(new_customer);/入队 bg.ArriveBarberGraph(cq, min_cq, cur_event->occurtime);/在图形界面上显示到来顾客 int t = cur_event->occurtime + intertime;/下一顾客的到来时间 if (t < closetime) /下一顾客到来未关门 new_event = new Event(t
48、, 0); ev.OrderIn(new_event);/生成下一顾客到达事件插入事件表 if (1 = cqmin_cq.length) /如果新来的顾客在队头 new_event = new Event(cur_event->occurtime+durtime, min_cq); ev.OrderIn(new_event);/生成本顾客的离开事件插入事件表 /CustomerArrived/客户离开事件void BarberShop:CustomerDeparture(barbergraph &bg) /注意:队列中超过两个人时下个人的离开事件从前一个人离开时开始计时。 in
49、t i = cur_event->event_type; /记录要删除的队列编号 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);/将离开的顾客用图形表示出来 cqi.DelQueue(); /删除第i队的排头客户 bg.BarberGraph(cq, cur_event->occurtime);/绘制顾客离开后的画面 if (0 != cqi.length) /设定第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);/开门初始化 while (!ev.ListEmpty() /事件驱动主体,只要事件表不为空则一直执行第一个事件 cur_event = ev.head->next_event;/获取当前事件(表中第二个结点) if (0 = cur_event->ev
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年南通科技职业学院单招职业技能测试必刷测试卷新版
- 2026年西安海棠职业学院单招综合素质考试必刷测试卷新版
- 2026年贵州建设职业技术学院单招职业技能测试题库必考题
- 2026年平凉职业技术学院单招职业适应性测试题库附答案
- 2026年河北省唐山市单招职业倾向性考试题库必考题
- 2026年绍兴文理学院单招综合素质考试必刷测试卷及答案1套
- 2026年南京铁道职业技术学院单招职业倾向性考试题库及答案1套
- 2026年苏州农业职业技术学院单招职业适应性考试必刷测试卷及答案1套
- 2026年江西水利职业学院单招综合素质考试题库附答案
- 2026年浙江省宁波市单招职业倾向性测试题库新版
- 检验三基培训
- 评估机构安全管理制度
- 临床慢性心衰伴LBBB行CRT-D植入术患者的护理疑难病例汇报
- T/CCAA 39-2022碳管理体系要求
- 个人汽车使用协议书
- 建房名额转让协议书
- 儿童自闭症康复中心项目投资可行性报告
- 幼儿园大班社会《首都北京》
- 消防喷淋协议书
- 《大学生创新创业基础(大赛案例版)》全套教学课件
- 贵州省建筑工程施工资料管理导则
评论
0/150
提交评论