问题描述
#include<stdio.h>#include<malloc.h>#include<stdlib.h>#include<conio.h>#include<time.h>#definen3intVIP1=0;inty,z;floatsum1=0,sum2=0,sum3=0,sum4=0,sum5=0;floati1=0,i2=0,i3=0,i4=0,i5=0;floatave1=0,ave2=0,ave3=0,ave4=0,ave5=0;structList{intA[n+1];intlen;}L;structLnode{intdata;Lnode*next;};structLinkqueue{Lnode*front,*rear;}Q;voidinitshuzu(){for(inti=1;i<=n;i++)L.A[i]=0;L.len=0;}//等待的客户进入等待队列voidEnqueue(Linkqueue*Q,intelem){Lnode*s;s=(Lnode*)malloc(sizeof(Lnode));s->data=elem;//elem进入等待客户序列s->next=NULL;Q->rear->next=s;Q->rear=s;}//等待队列客户出队intDlqueue(Linkqueue*Q){Lnode*t;intx;if(Q->front==Q->rear){printf("队列为空!n");exit(1);}else{t=Q->front->next;Q->front->next=t->next;x=t->data;free(t);returnx;}}//初始化线性voidInitshuzu(){for(inti=1;i<=n;i++)L.A[i]=0;L.len=0;}voidprint1(){//输出办理业务的顾客数组inti;printf("正在办理业务的顾客的编号为:一号柜台二号柜台三号柜台n");printf("");for(i=1;i<L.len;i++){printf("%d号客户",L.A[i]);}printf("n");}voidprint2(){//输出办理业务排队顾客序列inti=0;printf("正在等候办理业务的顾客编号为:");Lnode*s=Q.front->next;while(s!=NULL){printf("%d",s->data);s=s->next;i++;}printf("n您的前边一共有%d人在排队,请稍后!",i);printf("n");}voiddaoda(intx){//处理到达事件inti=L.len+1;if(L.len<n){//将到达客户号存入数组L.A[i]=x;i++;L.len++;}elseEnqueue(&Q,x);}voidlikai(intx){//处理离开事件inti=0;do{if(x>L.len){printf("输入有误!n请从新输入:");scanf("%d",&x);}elsefor(i=0;i<=L.len;i++){if(i==x){printf("尊敬的%d号客户您好!n",x);L.A[i]=0;L.len--;if(Q.front!=Q.rear){inty=Dlqueue(&Q);L.A[i]=y;L.len++;}}}}while(i==0);}//判断输入的柜台号是否正确intguitai(){inty=0;printf("请输入您所办理业务的柜台号(1-3):n");printf("%d",&y);if(y<1||y>3){printf("您输入的柜台号有误,请重新输入!n");printf("请输入您所办理的业务的柜台号(1-3):n");scanf("%d",&y);}elseprintf("%d.n",y);returny;}//判断输入的评分是否正确intpingfeng(){inty=0;printf("请输入您评分(1-5):n1分........非常不满意;n2分.........比较不满意;n3分...........一般满意;n4分...........比较满意;n5分...............非常满意");printf("请输入:");printf("%d",&y);if(y<1||y>3){printf("您输入的评分有误,请重新输入!n");printf("您输入的评分n");scanf("%d",&y);}elseprintf("您的评分为%d.n",y);returny;}//8.主函数评分voidmygrade(){printf("为了改善服务质量,请您对我们的服务进行评价,谢谢!n");z=guitai();y=pingfeng();switch(z)//柜台评分处理{case1:{sum1+=y;i1++;ave1=sum1/i1;printf("%d号柜台的平均满意度为%0.2f。感谢您的评分,谢谢!!!n",z,ave1);break;}case2:{sum2+=y;i2++;ave2=sum2/i2;printf("%d号柜台的平均满意度为%0.2f。感谢您的评分,谢谢!!!n",z,ave2);break;}case3:{sum3+=y;i3++;ave3=sum3/i3;printf("%d号柜台的平均满意度为%0.2f。感谢您的评分,谢谢!!!n",z,ave3);break;}default:printf("您的输入有误,请重新输入!n");}getch();}//VIP用户认证voidVIP(intx){inti,a=x,k=0;charch[3];switch(a){case1:{printf("请输入您的卡号:");scanf("%d",&i);printf("请输入5位密码:");while(ch[k-1]!='')//空格为密码输入的结束符{ch[k]=getch();k++;printf("*");}//符合vip帐号的具体帐户和密码if(i==100&&ch[0]=='1'&&ch[1]=='1'&&ch[2]=='1'&&ch[3]=='1'){printf("n尊敬的VIP用户您好,请您直接到VIP区办理业务!n");VIP1++;}elseif(i==200&&ch[0]=='2'&&ch[1]=='2'&&ch[2]=='2'&&ch[3]=='2'){printf("n尊敬的VIP用户您好,请您直接到VIP区办理业务!n");VIP1++;}elseif(i==300&&ch[0]=='3'&&ch[1]=='3'&&ch[2]=='3'&&ch[3]=='3'){printf("n尊敬的VIP用户您好,请您直接到VIP区办理业务!n");VIP1++;}elseif(i==400&&ch[0]=='4'&&ch[1]=='4'&&ch[2]=='4'&&ch[3]=='4'){printf("n尊敬的VIP用户您好,请您直接到VIP区办理业务!n");VIP1++;}elseif(i==500&&ch[0]=='5'&&ch[1]=='5'&&ch[2]=='5'&&ch[3]=='5'){printf("n尊敬的VIP用户您好,请您直接到VIP区办理业务!n");VIP1++;}elseprintf("n您输入有误!n");break;}default:break;}}//时间函数voidtime(){time_ttimep;time(&timep);printf("现在时刻是:%s",ctime(&timep));}//初始化等待队列voidInitqueue(){Q.front=Q.rear=(Lnode*)malloc(sizeof(Lnode));Q.front->next=NULL;}//主函数voidmain(){system("color1f");//屏幕颜色设定system("modecon:cols=90lines=35");time_ta1,a2,a3,a4,a5,a6,a7,a8,a9,a10,start,end;doubleb1=0,b2=0,b3=0,b4=0,b5=0,b6=0,b7=0,b8=0,b9=0,b10=0,allsum=0,average=0,x1=0;doubleA[10]={0,0,0,0,0,0,0,0,0,0};intc,x,v=0,w=0;//v为办理客户的计数,w已办理客户的计数Initshuzu();Initqueue();doublesum=0;while(1){printf("n*********************************欢迎光临*******************************************n");printf("nn");printf("1顾客到达n");printf("2顾客离开n");printf("3查看业务办理n");printf("4查看排队情况n");printf("5系统查询n");printf("6退出nn");time();printf("n提示:请按回车键进行下一步操作n");printf("nn");printf("********************************欢迎光临中国银行**************************************n");printf("请输入:n");scanf("%d",&c);switch(c){case1:{system("cls");printf("n*******************顾客到达界面********************nn");intk=0,a;printf("请选择您的用户类型:VIP用户请按1:n普通卡用户请按2.n");printf("请输入:");scanf("%d",&a);if(a==1){VIP(a);getch();}else{v++;printf("尊敬的普通卡用户,您的业务号为%d.n",v);daoda(v);if(v==1){a1=time(NULL);system("pause");}elseif(v==2){a2=time(NULL);system("pause");}elseif(v==3){a3=time(NULL);system("pause");}elseif(v==4){a4=time(NULL);system("pause");}elseif(v==5){a5=time(NULL);system("pause");}elseif(v==6){a6=time(NULL);system("pause");}elseif(v==7){a7=time(NULL);system("pause");}elseif(v==8){a8=time(NULL);system("pause");}elseif(v==9){a9=time(NULL);system("pause");}elseif(v==10){a10=time(NULL);system("pause");}else{printf("请稍后拿号,谢谢!");//超过10个客户的等候system("pause");}}system("cls");break;}case2:{system("cls");printf("n*******************顾客离开界面**********************nn");printf("请输入离开顾客的编号:n");scanf("%d",&x);likai(x);mygrade();w++;if(x=1){end=time(NULL);A[0]=difftime(end,a1);printf("您办理业务所用时间为%0.2f秒.n",difftime(end,a1));}elseif(x=2){end=time(NULL);A[1]=difftime(end,a2);printf("您办理业务所用时间为%0.2f秒.n",difftime(end,a2));}elseif(x=3){end=time(NULL);A[2]=difftime(end,a3);printf("您办理业务所用时间为%0.2f秒.n",difftime(end,a3));}elseif(x=4){end=time(NULL);A[3]=difftime(end,a4);printf("您办理业务所用时间为%0.2f秒.n",difftime(end,a4));}elseif(x=5){end=time(NULL);A[4]=difftime(end,a5);printf("您办理业务所用时间为%0.2f秒.n",difftime(end,a5));}elseif(x=6){end=time(NULL);A[5]=difftime(end,a6);printf("您办理业务所用时间为%0.2f秒.n",difftime(end,a6));}elseif(x=7){end=time(NULL);A[6]=difftime(end,a7);printf("您办理业务所用时间为%0.2f秒.n",difftime(end,a7));}elseif(x=8){end=time(NULL);A[7]=difftime(end,a8);printf("您办理业务所用时间为%0.2f秒.n",difftime(end,a8));}elseif(x=9){end=time(NULL);A[8]=difftime(end,a9);printf("您办理业务所用时间为%0.2f秒.n",difftime(end,a9));}elseif(x=10){end=time(NULL);A[9]=difftime(end,a10);printf("您办理业务所用时间为%0.2f秒.n",difftime(end,a10));}allsum+=A[0];getch();system("cls");break;}case3:{system("cls");printf("n********************业务查询界面*********************nn");print1();getch();system("cls");break;}case4:{system("cls");printf("n*******************排队查询界面*******************nn");print2();getch();system("cls");break;}case5:{system("cls");printf("n********************系统查询界面**********************nn");charcool[3];inti=0,k=0;printf("请输入您的卡号:");scanf("%d",&i);printf("请您输入5位密码:");while(cool[k-1]!=''){cool[k]=getch();k++;printf("*");}if(i==000&&cool[0]=='1'&&cool[1]=='1'&&cool[2]=='1'&&cool[3]=='1'){average=allsum/w;printf("n至今已有%d位普通用户,%d位VIP用户成功办理业务!",w,VIP1);printf("n普通用户业务办理总共用时%0.2f秒,平均用时%0.2f秒n",allsum,average);}getch();system("cls");break;}return;getch();system("cls");case6:return;getch();system("cls");default:printf("输入有误,请重新输入:n");getch();system("cls");}}}