数据结构课设报告-理发馆经营状况模拟系统.docx

上传人:wux****ua 文档编号:8976751 上传时间:2020-04-02 格式:DOCX 页数:25 大小:83.58KB
返回 下载 相关 举报
数据结构课设报告-理发馆经营状况模拟系统.docx_第1页
第1页 / 共25页
数据结构课设报告-理发馆经营状况模拟系统.docx_第2页
第2页 / 共25页
数据结构课设报告-理发馆经营状况模拟系统.docx_第3页
第3页 / 共25页
点击查看更多>>
资源描述
数据结构课设报告 姓名:xxx学号:xxxxxxxx学院:计算机学院完成日期:2013年9月题目:理发馆经营状况模拟系统一、 程序基本功能1. 能够从文件中读取所需条件。2. 随机产生每个顾客进门时的理发时间durtime、间隔时间intertime、服务选项select。3. 统计每天不同级别理发师的营业时间、创收和每天理发馆总创收并写入到文本文件中二、 需求分析1. 本演示程序中用户和计算机以文本方式进行交流,即用户将所需数据写入到data.txt文件中,计算机将结果输出到sesult.txt文件中。2. 演示程序以图形界面输出当前状况。3. 演示程序中需要用到数据结构中的离散模型、顺序存储、有序表、线性结构。4. 程序执行命令包括:a) 读出data.txt文件中的相应数据。b) 生成顾客信息。c) 进行理发服务,并计算相应数据。d) 结果存入到result.txt文件中。5. 测试数据09:3018:0091 32 13 24 15 26 37 38 19 2三、 概要设计本程序主要分为四大模块为了实现上述程序功能,应以有序表表示理发队列1. 理发队列:typedef struct Qnodeint num; /理发者编号struct Qnode *next;Qnode,*Queueptr;2. 等待队列:typedef structQueueptr front; /队头指针Queueptr rear; /队尾指针LinkQueue;LinkQueue A; /等待队列A为1LinkQueue B; /等待队列B为2LinkQueue C; /等待队列C为33. 顾客参数的抽象数据类型;typedef struct customerint no; /编号int intime; /进入理发店间int durtime; /所需服务时间int intertime; /下一个顾客到达所需时间int select; /选择服务等级:1,2,3int starttime; /开始理发时间int leavetime; /离开时间int serve_flag; /是否在理发float turnover; /营业额customer ;4. 理发师参数的抽象数据类型:struct barberint No; /理发师编号int level; /理发师级别BrN; /理发师5. 离散模型:while(currenttimeT) /判断是否属于营业时间,是否禁止顾客进入for(i=1;i0 & !QueueEmpty(A)customer_serve(DeQueue(A); while(Bchair0 & !QueueEmpty(B)customer_serve(DeQueue(B); while(Cchair0 & !QueueEmpty(C)customer_serve(DeQueue(C); if(custotalcustom.intime+custotalcustom.intertime)=currenttime)customer_in(); /判断有无人进入currenttime+;while(!QueueEmpty(A)char sInfo128 = 0;currenttime+;for(i=1;i0 & !QueueEmpty(A) /让等待队列中的人去理发 customer_serve(DeQueue(A); OutputDebugString(while 2 is done.);while(!QueueEmpty(B)currenttime+;for(i=1;i0 & !QueueEmpty(B) /让等待队列中的人去理发 customer_serve(DeQueue(B); while(!QueueEmpty(C)currenttime+;for(i=1;i0 & !QueueEmpty(C) /让等待队列中的人去理发 customer_serve(DeQueue(C); lasttime=cus1.leavetime; /求出最后离开的顾客的离开时间for(i=2;i=totalcustom;i+)lasttime = lasttime cusi.leavetime ? cusi.leavetime : lasttime;while(currenttime+lasttime) /队列为空,继续为正在理发的顾客服务for(i=1;i=totalcustom;i+) if(cusi.serve_flag=TRUE)&(cusi.starttime+cusi.durtime=currenttime)customer_leave(i);6. 本程序包含三个模块:1) 主程序模块:int _tmain(int argc, _TCHAR* argv)初始化;数据下载;数据生成;程序运行;数据处理、存储;退出程序return 0;2) 数据下载、存储模块:load (); /数据下载save (); /数据存储3) 图形界面模块实现图形界面构建及点击设置。4) 理发模块实现理发模拟,并处理数据。各模块间调用关系如下:四、 详细设计/ barber.cpp : 定义控制台应用程序的入口点。/#include stdafx.h/是从工程文件里边取,而是从电脑的库文件里边取#include #include #include #include #include #include #include #include #define MAX 30000#define TRUE 1#define FALSE 0#define R rand()#define N 20float wait_length; /等待队列长度int totalcustom; /总顾客数int totaltime; /总理发时间int currenttime; /当前时间int addtime; /加班时间int Achair; /当前A级可用椅子int Bchair; /当前B级可用椅子int Cchair; /当前C级可用椅子int h1; /开始时间int min1; /开始分钟int h2; /结束时间int min2; /结束分钟double wait_A;double wait_B;double wait_C;double aver_serve_time; /平均服务时间double aver_wait_len; /平均等待长度double wait_len_A; /理发队列长度double wait_len_B; double wait_len_C; int n; /理发师人数float discount; /折扣int x,y; /画方格横纵坐标int i,a,b,c,d,e,f,h,k; /参数int T; /营业总时长(分钟)int lasttime; /最后一个离开时间float allturnover; /总营业额int Atime; /1级理发师营业额int Btime; /2级理发师营业额int Ctime; /3级理发师营业额float Aturnover; /1级理发师营业时间float Bturnover; /2级理发师营业时间float Cturnover; /3级理发师营业时间int r;struct barberint No; /理发师编号int level; /理发师级别BrN; /理发师typedef struct customerint no; /编号int intime; /进入理发店时间int durtime; /所需服务时间int intertime; /下一个顾客到达所需时间int select; /选择服务等级:1,2,3int starttime; /开始理发时间int leavetime; /离开时间int serve_flag; /是否在理发float turnover; /营业额customer ;customer cusMAX;typedef struct Qnodeint num; /理发者编号struct Qnode *next;Qnode,*Queueptr;typedef structQueueptr front; /队头指针Queueptr rear; /队尾指针LinkQueue;LinkQueue A; /等待队列A为1LinkQueue B; /等待队列B为2LinkQueue C; /等待队列C为3void Myinterface(); /输出界面void load(); /读取文件void InitQueue(LinkQueue &Q); /队列初始化int Queue_length(LinkQueue & Q); /求等待队列当前长度void EnQueue(LinkQueue &Q,int e); /将顾客插入队尾int DeQueue(LinkQueue &Q); /队头出队,e返回去编号int QueueEmpty(LinkQueue & Q); /判断队列是否为空,空返回1void customer_serve(int n); /服务void customer_in(); /顾客到达void customer_leave(int n); /顾客离开void list(); /平均等待长度和等待时间void save(); /存取数据void click(); /显示当前状态void close(); /关闭图形界面void currentstate(int e,int f); /修改界面void clearstate();void initialize(); /初始化void time_initialize(); /时间初始化void haircut();void clk(int n);void outget();int _tmain(int argc, _TCHAR* argv)initialize();load();Myinterface();time_initialize();click();InitQueue(A); /初始化队列InitQueue(B);InitQueue(C);customer_in();haircut();for(b=1;b=totalcustom;b+)allturnover = cusb.turnover+allturnover; /总营业额addtime=lasttime-T;list();save();outget();outtextxy(400,300,ok);close(); / 关闭图形界面getch(); / 按任意键继续return 0;void Myinterface()int i;x=100;y=100;for(i=1;inext=NULL;int Queue_Length(LinkQueue &Q) /求等待队列当前长度int length=0;Queueptr p;p=Q.front;while(p-next)p=p-next;+length;return length; void EnQueue(LinkQueue &Q,int e) /将顾客插入队尾Queueptr p;p=(Queueptr)malloc(sizeof(Qnode);p-num=e;p-next=NULL;Q.rear-next=p;Q.rear=p;int DeQueue(LinkQueue &Q) /队头出队,e返回去编号Queueptr p;int e;p=Q.front-next;e=p-num;Q.front-next=p-next;if(Q.rear=p)Q.rear=Q.front;free(p);return e;int QueueEmpty(LinkQueue & Q) /判断队列是否为空return(Q.front=Q.rear? TRUE:FALSE); void customer_serve(int n) /理发cusn.starttime=currenttime; cusn.leavetime=cusn.durtime+currenttime;switch(cusn.select) /理发座位-1case 1:Achair-;click();break;case 2:Bchair-;click();break;case 3:Cchair-;click();break;default:break;cusn.serve_flag=TRUE; void customer_in()totalcustom+;custotalcustom.no=totalcustom;custotalcustom.intime=currenttime; /记录顾客进入时间custotalcustom.durtime=25+rand()%50; /生成所需服务时间custotalcustom.intertime=15+rand()%30; /下一个顾客到达时间custotalcustom.select=1+R%3; /生成服务等级1-3custotalcustom.turnover=(20.0000+custotalcustom.durtime*custotalcustom.select/1.0000)*(discount/100.0000);/单人营业额switch(custotalcustom.select)case 1:if(QueueEmpty(A)&Achair0)customer_serve(totalcustom);elsecustotalcustom.serve_flag=FALSE; /否则入队等待EnQueue(A,totalcustom);wait_len_A=wait_len_A+Queue_Length(A); /累计队长char lengthA5; sprintf(lengthA,%d,Queue_Length(A); outtextxy(100,400,lengthA);break;case 2:if(QueueEmpty(B)&Bchair0)customer_serve(totalcustom);elsecustotalcustom.serve_flag=FALSE; /否则入队等待EnQueue(B,totalcustom);wait_len_B=wait_len_B+Queue_Length(B); /累计队长break;case 3:if(QueueEmpty&Cchair0)customer_serve(totalcustom);elsecustotalcustom.serve_flag=FALSE; /否则入队等待EnQueue(C,totalcustom);wait_len_C=wait_len_C+Queue_Length(C); /累计队长break;default:break;void customer_leave(int n) /顾客离开cusn.serve_flag=FALSE;switch(cusn.select) /理发座位+1case 1:Achair+;click();break;case 2:Bchair+;click();break;case 3:Cchair+;click();break;default:break;totaltime = totaltime+currenttime-cusn.intertime;void list()aver_serve_time=totaltime/totalcustom-c; wait_length=wait_len_A+wait_len_B+wait_len_C;aver_wait_len=wait_length/(totalcustom*1.00000); for(i=1;i=totalcustom;i+)switch(cusi.select)case 1 :Atime=Atime+cusi.durtime;Aturnover=Aturnover+cusi.turnover;break;case 2:Btime=Btime+cusi.durtime;Bturnover=Bturnover+cusi.turnover;break;case 3:Ctime=Ctime+cusi.durtime;Cturnover=Cturnover+cusi.turnover;break;default:break;void save()FILE *fp;int i;if(fp=fopen(result.txt,w)!=NULL)/打开文件char T1=开门时间: ;fprintf(fp,%s%d%c%dn,T1,h1,:,min1);char T2=关门时间:;fprintf(fp,%s%d%c%d%dn,T2,h2,:,min2,0);char bar=理发师人数: ;fprintf(fp,%s%dn,bar,n);char bars=理发师编号及等级: ;for(i=1;i=220 & m.x=190 & m.y=450 & m.x=190 & m.y=230) /450,190,500,230closegraph();printf(welcome to my shopn);break;void currentstate(int e,int f) /e为椅子数,f为等级k=f;h=e;for(d=1;d=n;d+)setcolor(GREEN);rectangle(50+d*50),100,(90+d*50),130);for(d=1;d=n;d+)int static g=0;if(g=h)break;elseif(Brd.level=k)g=g+1;setfillcolor(BLUE);fillrectangle(50+d*50),100,(90+d*50),107);elseif(Brd.level!=1&Brd.level!=2&Brd.level!=3)setfillcolor(BLACK);fillrectangle(50+d*50),100,(90+d*50),107);void clearstate()for(d=1;d=n;d+)setfillcolor(WHITE);clearrectangle(50+d*50),100,(90+d*50),107);void initialize()Atime=0;Btime=0;Ctime=0;Aturnover=0;Bturnover=0;Cturnover=0;allturnover=0;currenttime=0;totaltime=0;totalcustom=0;wait_length=0;Achair=0;Bchair=0;Cchair=0;wait_len_A=0;wait_len_B=0;wait_len_C=0;wait_A=0;wait_B=0;wait_C=0;discount=10;srand(time(0);initgraph(640,480); /生成640*480的图形界面setcolor(WHITE);outtextxy(200,20,Welcome to my barber shop!);setcolor(YELLOW);outtextxy(150,50,The yellow is the No); setcolor(RED);outtextxy(300,50, LPCTSTR( The red is the level);rectangle(220,190,340,230);outtextxy(230,200,显示当前状态);rectangle(450,190,500,230);outtextxy(460,200,退出);void time_initialize()T=h2*60+min2;for(i=1;i=n;i+)switch(Bri.level)case 1:Achair+;break;case 2:Bchair+;break;case 3:Cchair+;break;default:break;c=h1*60+min1;currenttime=h1*60+min1; /当前时间clk(currenttime);void haircut()while(currenttimeT) /判断是否属于营业时间,是否禁止顾客进入for(i=1;i0 & !QueueEmpty(A)customer_serve(DeQueue(A); while(Bchair0 & !QueueEmpty(B)customer_serve(DeQueue(B); while(Cchair0 & !QueueEmpty(C)customer_serve(DeQueue(C); if(custotalcustom.intime+custotalcustom.intertime)=currenttime)customer_in(); /判断有
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 管理文书 > 工作总结


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!