停车场管理实验报告

本科学生设计性实验报告

项目组长   ***     学号        

成    员    ***      

专    业              软件工程                    

实验项目           模拟停车场管理                 

指导教师及职称    ****               

上课时间   201472     2014719


一、实验设计方案

二、实验结果与分析



 [S1]亲,你看这些地方要不要适当的加点程序运行的图片,你看着办~

 

第二篇:数据结构实验——综合实验·停车场管理·实验报告——附加详细注释

#include<stdio.h>#include<stdlib.h>#include<string.h>/*输入输出说明:输入,输入n和k,n代表车库容量,k代表单位时间内所要收取的费用接下去每行输入三个数据,status,carnum,time,含义如下,status 代表车辆的状态,有且只有两种状态,分别为A 表示车辆要挺入车库,D 表示车辆要驶离车库,然后,carnum 表示车辆的号码且对每一辆车都具有唯一性time 表示车辆在某一状态下的时刻*注意:1、必须要保证至少有1辆车!2、可更具需要通过输入 inf 实时查看车辆整体信息和状态输出,输出对应操作或状态下所发生的事件样例输入(一条条输入信息)3 1A 1 5D 1 10A 1 5A 2 10A 3 15A 4 18inf样例输出3 1A 1 5D 1 10Attetion! The car No.1 had left just now!It stays about 5 units time and costs $5!A 1 5A 2 10A 3 15A 4 18Warning! The parking lots is full!The car No.4 is waiting now!inf******************************************************************* ** There are 3 cars in the parking lots! That's the following, ** car No.1 ** car No.2 ** car No.3 ** ** And there is 1 car in waiting! That's the following, ** car No.4 ** *******************************************************************更多样例输入,注意,中间可更具需要通过输入 inf 实时查看车辆整体信息和状态。此处省略。3 1A 1 5A 2 10A 3 16D 2 20A 4 25A 5 22D 3 26D 1 30D 5 45D 4 50A 1 5A 2 10A 3 16A 4 20A 5 25D 1 30D 2 35D 4 37D 3 39D 5 45E 0 0*/struct hi{int carnum,time;hi *next,*last;};struct oh{int tempcar,temptime;oh *follow;//same as *next};hi *find(hi *tempDstack,int tempnum){while(tempDstack!=NULL)//找出要离开的车原来在栈中的位置{if(tempDstack->carnum==tempnum){return tempDstack;}tempDstack=tempDstack->next;}return NULL;}int main(){int i,j,m,n,k,count,tempnum;int capacity,index1,index2,leave,flag;char ch[5];scanf("%d%d",&n,&k);//输入车库容量(大于0)和费用hi *Dstack,*temp,*top,*freenode,*pointer,*info;//双向栈oh *queue,*Qtemp,*tail,*Qfreenode,*Qpointer,*Qinfo;capacity=0;//车库容量计数器(栈容量计数器)count=0;//过道车辆计数器(队列容量计数器)flag=0;Dstack=top=(hi*)malloc(sizeof(hi));

Dstack->last=NULL;//封栈底queue=tail=(oh*)malloc(sizeof(oh));scanf("%s%d%d",ch,&index1,&index2);if(ch[0]=='E'||ch[0]=='D'){printf("There's no such car!!\n");}else {top->carnum=index1;//首次赋值,压栈垫底 care!top->time=index2;capacity++;while(true){scanf("%s",ch);//实时信息板if(strcmp(ch,"inf")==0){printf(" ******************************************************************\n");printf(" * *\n");if(capacity==0){printf(" * There is no car in the parking lots! *\n");}else if(capacity==1){printf(" * There is %-2d car in the parking lots! That's the following, *\n",capacity);printf(" * car No.%-2d *\n",Dstack->carnum);}else if(capacity>1){printf(" * There are %-2d cars in the parking lots! That's the following, *\n",capacity);info=Dstack;tempnum=capacity;while(tempnum>0){tempnum--;printf(" * car No.%-2d *\n",info->carnum);info=info->next;}}printf(" * *\n");if(count==0){printf(" * And There is no car in waiting! *\n");}else if(count==1){printf(" * And there is %-2d car in waiting! That's the following, *\n",count);printf(" * car No.%-2d *\n",queue->tempcar);}else if(count>1){printf(" * And there are %-2d cars in waiting! That's the following, *\n",count);Qinfo=queue;tempnum=count;while(tempnum>0){tempnum--;printf(" * car No.%-2d *\n",Qinfo->tempcar);Qinfo=Qinfo->follow;}}printf(" * *\n");printf(" ******************************************************************\n");}//数据输入else{scanf("%d%d",&index1,&index2);if(ch[0]=='E'){break;}temp=(hi*)malloc(sizeof(hi));temp->carnum=index1;//数据转移,temp吸收temp->time=index2;//停车if(ch[0]=='A'){if(capacity<n)//车库没满才进来{if(capacity<=0){Dstack->carnum=top->carnum=temp->carnum;Dstack->time=top->time=temp->time;}else {temp->last=top;//构造双指向关系top->next=temp;top=temp;//压栈-维持栈顶}capacity++;//停入一辆车则车库容量加1}//如果

超过车库容量else{printf("Warning! The parking lots is full!\n");printf("The car No.%d is waiting now!\n\n",temp->carnum);if(flag==0){//首个多出车辆进入队列tail->tempcar=temp->carnum;tail->temptime=temp->time;flag=1;count++;}else{Qtemp=(oh*)malloc(sizeof(oh));Qtemp->tempcar=temp->carnum;//数据转移,Qtemp吸收Qtemp->temptime=temp->time;tail->follow=Qtemp;//入队尾tail=Qtemp;//维持队尾tail->follow=NULL;count++;}}}//离开else if(ch[0]=='D'){pointer=find(Dstack,temp->carnum);if(pointer==NULL)//别玩儿我!{printf("There's no such car!!\n");break;}else{capacity--;//开走一辆车故容量减1printf("Attetion! The car No.%d had left just now!\n",temp->carnum);printf("It stays about %d units time and costs $%d!\n\n",temp->time-pointer->time,(temp->time-pointer->time)*k);leave=temp->time;//记录这辆车离开的时间freenode=pointer;if(capacity>0){if(pointer==Dstack)//如果元素到栈底了{Dstack=freenode->next;//就直接指向下一个}else if(pointer==top){top=top->last;top->next=NULL;}else{freenode->next->last=pointer->last;//双向栈优势所在pointer->last->next=freenode->next;}free(freenode);freenode=NULL;if(Dstack!=NULL){Dstack->last=NULL;//封栈底}}}//有过道上的车则进入if(count>0){count--;printf("Attention! The waiting car No.%d is entering!\n",queue->tempcar);printf("Now, the time is %d!\n\n",leave);temp=(hi*)malloc(sizeof(hi));temp->carnum=queue->tempcar;//导入车辆号码temp->time=leave;//导入时间(即为刚刚那辆车离开的时间)temp->last=top;//构造双向栈top->next=temp;top=temp;capacity++;//又进来一辆Qfreenode=queue;if(count>0){queue=Qfreenode->follow;free(Qfreenode);//释放过道上离开的车的空间}Qfreenode=NULL;}else{flag=0;}}}}}return 0;}/****************************停车场综合实验总结与感悟***************************总结:No.1不论是栈、队列还是链表,表头指针最好都一直保留到EOFNo.2用户的信息实时查看需求No.3永远不要单纯的只通过ADT的地址来判断是否为空,最好有一个一直伴随着的计数器No.4双向ADT(非循环)注意不要忘记确定是否要封顶或封底,中间很容易

忘记构造双向No.5坚持不懈! 终会成功!感悟:从最开始写到最后总共打搅了我宝贵的好几个晚上训练时间(虽然不是完全一直在做)!先是好几次地错误,然后,不断地非法访问、错误、调试、非法访问、错误、调试、非法访问、错误、调试...这个步骤花了我最最长时间!! 事实证明,不用计数器判断是太高估自己了!最后就是接近于应用的优化完善优化完善了。所以,在符合操作的情况下,请放心测试数据吧O(∩_∩)O~*///##如果发现八阿哥就一定要告诉我啰~

相关推荐