数据结构项目课程报告--停车场管理系统.doc_第1页
数据结构项目课程报告--停车场管理系统.doc_第2页
数据结构项目课程报告--停车场管理系统.doc_第3页
数据结构项目课程报告--停车场管理系统.doc_第4页
数据结构项目课程报告--停车场管理系统.doc_第5页
已阅读5页,还剩28页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

安阳师范学院 数据结构项目课程 数据结构项目课程报告 一、 问题描述及分析题目要求: 设停车场内只有一个可停放n辆汽车的狭长通道,且只有一个大门可供汽车进出。汽车在停车场内按车辆到达时间的先后顺序,依次由北向南排列(大门在最南端,最先到达的第一辆车停放在车场的最北端),若车场内已停满n辆汽车,则后来的汽车只能在门外的便道上等候,一旦有车开走,则排在便道上的第一辆车即可开入;当停车场内某辆车要离开时,在它之后开入的车辆必须先退出车场为它让路,待该车辆开出大门外,其他车辆再按原次序进入车场,每辆车停放在车场的车在它离开停车场时必须按它停留的时间长短交纳费用。试为停车场编制按上述要求进行管理的模拟程序。分析:由题目只有一个大门进出并且“先到后处理”可知,应使构造栈模拟停车场,进入离开停车场即入栈出栈的过程;而便道等候的汽车符合“先到先处理”原则 ,应构造线性队列模拟;构造存储结构,存放车辆信息,车牌号,到达离开时间;通过time.h头文件中的函数获取汽车到来以及离开时间,利用时间差计算价钱。主要模块如下图:停车场管理系统车辆到达停车场车辆进入停车场车辆离开停车场车辆停留在便道车辆进入停车场输出车辆的进入信息记录进入的时间位置输出车辆的离开信息记录车辆离开的时间位置输出应缴纳的费用便道的车辆进入停车场二、 功能模块及数据结构描述头文件、宏定义以及存储结构结构体定义相关类型的链表空间有顺序栈的定义、链队、车辆信息结构体、时间计算结构体、车辆位置字符型结构体数组和循环单链表存储下一个地址空间。#include #include #include #include #include #define OK 1#define ERROR 0typedef struct time1char times100;long time2;time1;typedef struct nodechar num10;time1 reach;time1 leave;Car;typedef struct StackCar *stack100;int top;SqStack;typedef struct carCar *data;struct car *next;QNode;typedef struct NodeQNode *front;QNode *rear;LinkQueue;主函数void main()SqStack In, Out;LinkQueue Wait;int ch;int MAX;float price;printf(请输入停车场的容量:);scanf(%d, &MAX);printf(请输入停车场的收费标准(元 / 小时) :);scanf(%f, &price);InitStack(&In, MAX);InitStack(&Out, MAX);InitQueue(&Wait);while (1)system(color 0A);printf( = = = = 欢迎使用停车场管理系统 = = = = = = = = = = n);printf(输入的停车场容量为%d位,费用为%2.1f元 / 小时, 请按任意键进入系统, MAX, price);getchar();system(CLS);printf( = = = = 欢迎使用停车场管理系统 = = = = = = = = = n);printf(您输入的停车场容量为%d位,费用为%2.1f元 / 小时。n, MAX, price);printf(n = = = = = = = = = = = = = n);printf(1)车辆到达n(2)车辆离开n(3)停车场信息n(4)退出系统n请选择n);printf(n = = = = = = = = = = = = = = n);while (1)printf(请输入操作的序号);scanf(%d, &ch);switch (ch)case 1:arrive(&In, &Wait, MAX, price);break;case 2:leave(&In, &Out, &Wait, MAX, price);break;case 3:info(In, Wait);break;case 4: system(CLS); printf(n = = = = = = = = = = = = = = n); printf( 谢谢使用!n); printf(n = = = = = = = = = = = = = = = = = = = = = n); exit(0);default:printf(n按键无效,请重新按键选择);getchar();system(CLS);printf( = = = = = 欢迎使用停车场管理系统 = = = = = n);printf(您输入的停车场容量为%d位,费用为%2.1f元 / 小时。n, MAX, price);printf(n = = = = = = = = = = = = = = = = = = = = n);printf(1)车辆到达n(2)车辆离开n(3)停车场信息n(4)退出系统n请选择n);printf(n = = = = = = = = = = = = = = = = = = = = = n);费用计算函数,通过时间差计算费用void print(Car *p, int room, int MAX, float price)time_t rawtime; struct tm * timeinfo; long A1, A2, B1, B2;time ( &rawtime );timeinfo = localtime ( &rawtime );p-leave.time2=rawtime;printf(n车离开的时间为:%s ,asctime (timeinfo);strcpy(p-leave.times,asctime (timeinfo);printf(n车牌号码:);puts(p-num);printf(n车到达的时间是: %s , p-reach.times);printf(n车离开的时间是: %s , p-leave.times);A1=p-leave.time2;A2=p-reach.time2;B1=p-leave.time2-p-reach.time2;if(B1=0)printf(n费用为: %2.1f元, price);elseprintf(n费用为: %2.1f元, B1/3600*price);free(p);/消费计算函数车辆到达函数,获取车辆信息,判断是否有车位,进行入栈或入队操作int arrive(SqStack *In, LinkQueue *W, int MAX, float price)Car *p;QNode *t;time_t rawtime; struct tm * timeinfo; /time ( &rawtime ); / 获取时间,以秒计,从1970年1月一日起算,存于rawtime/timeinfo = localtime ( &rawtime ); /转为当地时间,tm 时间结构 /printf ( 当前系统时间: %s, asctime (timeinfo) );/asctime (timeinfo); / 转为标准ASCII时间格式:p = (Car *)malloc(sizeof(Car);printf( = = = = = = = = = = = 欢迎使用停车场管理系统 = = = = = = = = = = = n);printf(您输入的停车场容量为%d位,费用为%2.1f元 / 小时。n, MAX, price);printf(停车场还有%d停车位, 车可先进入便道等待, MAX - In-top);printf(n请输入车牌号码(例:警A1035) :);getchar();scanf(%s, p-num);getchar();if (In-top reach.time2=rawtime;timeinfo = localtime ( &rawtime );In-top+;printf(停车的位置:%d号停车位。, In-top);printf(n车到达的时间为%s: ,asctime (timeinfo);strcpy(p-reach.times,asctime (timeinfo);In-stackIn-top = p;printf(请按任意键返回n);printf(n = = = = = = = = = = = = = = = = = = = = = = = n);getchar();return OK;elseprintf( = = = = = 欢迎使用停车场管理系统 = = = = = = = = = n);printf(您输入的停车场容量为%d位,费用为%2.1f元 / 小时。n, MAX, price);printf(n = = = = = = = = = = = = = = = = = = = = = n);printf(停车位已满,该车须在便道等待!);t = (QNode *)malloc(sizeof(QNode);t-data = p;t-next = NULL;W-rear-next = t;W-rear = t;printf(n请按任意键返回);getchar();return OK;getchar();车辆离开函数,如果是最前面的车离开,后面的车必须都进行出栈操作进入到另一个栈中让需要离开的车离开后再重新进入;如果便道有车那么便道的前面的车即先入队的车进行出队入栈void leave(SqStack *In, SqStack *Out, LinkQueue *W, int MAX, float price)int place;Car *p, *t;QNode *q;time_t rawtime;struct tm * timeinfo;system(CLS);if (In-top0)while (1)printf( = = = = 欢迎使用停车场管理系统 = = = = = = = = = n);printf(您输入的停车场容量为%d位,费用为%2.1f元 / 小时。n, MAX, price);printf(n = = = = = = = = = = = = = = = = = = = = = = = = = = n);printf(请输入车在停车场的位置(1 - %d):, In-top);scanf(%d, &place);if (place = 1 & place top) break;while (In-topplace)Out-top+;Out-stackOut-top = In-stackIn-top;In-stackIn-top = NULL;In-top-;p = In-stackIn-top;In-stackIn-top = NULL;In-top-;while (Out-top = 1)In-top+;In-stackIn-top = Out-stackOut-top;Out-stackOut-top = NULL;Out-top-;print(p, place, MAX, price);if (W-front != W-rear) & In-topfront-next;t = q-data;In-top+;printf(n便道的%s号车进入车场第%d号停车位。, t-num, In-top);printf(n车到达的时间: %s ,asctime (timeinfo);t-reach.time2=rawtime;strcpy(t-reach.times,asctime (timeinfo);W-front-next = q-next;if (q = W-rear) W-rear = W-front;In-stackIn-top = t;free(q);elseprintf(n = = = = = = = = = = = = = = = = = = = = = = = = = n);printf(停车场里没有车n);printf(n请按任意键返回);printf(nn = = = = = = = = = = = = = = = = = = = = = = = = = = n);getchar();getchar();停车场信息函数,遍历队列和栈能知道便道中和停车场中车辆信息void info1(SqStack *S)int i;if (S-top0)printf(n 停车场n);for (i = 1; i top; i+)printf(n 位置: n %dn, i);printf( 到达时间:n%s 车牌号: n %sn, S-stacki-reach.times,S-stacki-num);elseprintf(n = = = = = = = = = = = = = = = = = = = = = n);printf(停车场里没有车);void info2(LinkQueue *W)QNode *p;p = W-front-next;if (W-front != W-rear)printf(n便道中车辆的号码为:n);while (p != NULL)printf(%sn, p-data-num);p = p-next;else printf(n便道里没有车n);printf(n请按任意键返回n);printf(nn = = = = = = = = = = = = = = = = = = = = = n);getchar();void info(SqStack S, LinkQueue W)system(CLS);info1(&S);info2(&W);getchar();队列和栈的初始化void InitStack(SqStack *s, int MAX)int i;s-top = 0;for (i = 0; i stacks-top = NULL;int InitQueue(LinkQueue *Q)Q-front = (QNode *)malloc(sizeof(QNode);if (Q-front != NULL)Q-front-next = NULL;Q-rear = Q-front;return OK;else return ERROR;/队列和栈初始函数三、 主要算法流程描述及部分核心算法流程描述1.车辆到达停车场其中车辆到达时需要用户输入车辆信息,接着要判断栈是否已满,如当前栈未满,则进行入栈操作,即车辆进入停车场;如果栈已满,则车辆必须进入便道等待。2. 车辆进入停车场车辆进入,则进行入栈操作,即将车辆信息结点进行入栈操作。3. 车辆离开停车场车辆的离开,则需要另设一个栈,给离去的汽车让路而从停车场退出来的汽车临时停放,也用顺序栈实现,车辆离开后需检查便道内是否有车辆等待,若有等待车辆则进行便道内的车辆进入停车场的操作,即将车辆信息结点进行入栈操作,输入当前时间后开始计费,最后进行出队操作,表示车辆已离开便道。核心算法车辆到达停车场获取车辆到达时间是车辆进入停车场开 始记录车辆信息和到达时间判断是否重复有车辆否是储存车辆信息和时间信息结 束车辆离开停车场开 始获取车辆离开信息和时间计算时间差运算停车费用判断便道中是否有车否输出离开停车场信息和收费金额车辆离开停车场更新栈表结 束是输出车辆现在停止在便道位置等待车辆离开四、 系统使用说明运行环境为VC+6.0,如果需要在VS上运行需要改动scanf函数为scanf_s运行截图附:源码#include #include #include #include #include #define OK 1#define ERROR 0typedef struct time1char times100;long time2;time1;typedef struct nodechar num10;time1 reach;time1 leave;Car;typedef struct StackCar *stack100;int top;SqStack;typedef struct carCar *data;struct car *next;QNode;typedef struct NodeQNode *front;QNode *rear;LinkQueue;void print(Car *p, int room, int MAX, float price);int arrive(SqStack *In, LinkQueue *W, int MAX, float price);void leave(SqStack *In, SqStack *Out, LinkQueue *W, int MAX, float price);void info1(SqStack *S);void info2(LinkQueue *W);void info(SqStack S, LinkQueue W);void InitStack(SqStack *s, int MAX);int InitQueue(LinkQueue *Q);void main()SqStack In, Out;LinkQueue Wait;int ch;int MAX;float price;printf(请输入停车场的容量:);scanf(%d, &MAX);printf(请输入停车场的收费标准(元 / 小时) :);scanf(%f, &price);InitStack(&In, MAX);InitStack(&Out, MAX);InitQueue(&Wait);while (1)system(color 0A);printf( = = = = 欢迎使用停车场管理系统 = = = = = = = = = = n);printf(输入的停车场容量为%d位,费用为%2.1f元 / 小时, 请按任意键进入系统, MAX, price);getchar();system(CLS);printf( = = = = 欢迎使用停车场管理系统 = = = = = = = = = n);printf(您输入的停车场容量为%d位,费用为%2.1f元 / 小时。n, MAX, price);printf(n = = = = = = = = = = = = = n);printf(1)车辆到达n(2)车辆离开n(3)停车场信息n(4)退出系统n请选择n);printf(n = = = = = = = = = = = = = = n);while (1)printf(请输入操作的序号);scanf(%d, &ch);switch (ch)case 1:arrive(&In, &Wait, MAX, price);break;case 2:leave(&In, &Out, &Wait, MAX, price);break;case 3:info(In, Wait);break;case 4: system(CLS); printf(n = = = = = = = = = = = = = = n); printf( 谢谢使用!n); printf(n = = = = = = = = = = = = = = = = = = = = = n); exit(0);default:printf(n按键无效,请重新按键选择);getchar();system(CLS);printf( = = = = = 欢迎使用停车场管理系统 = = = = = n);printf(您输入的停车场容量为%d位,费用为%2.1f元 / 小时。n, MAX, price);printf(n = = = = = = = = = = = = = = = = = = = = n);printf(1)车辆到达n(2)车辆离开n(3)停车场信息n(4)退出系统n请选择n);printf(n = = = = = = = = = = = = = = = = = = = = = n);/主函数菜单void print(Car *p, int room, int MAX, float price)time_t rawtime; struct tm * timeinfo; long A1, A2, B1, B2;time ( &rawtime );timeinfo = localtime ( &rawtime );p-leave.time2=rawtime;printf(n车离开的时间为:%s ,asctime (timeinfo);strcpy(p-leave.times,asctime (timeinfo);printf(n车牌号码:);puts(p-num);printf(n车到达的时间是: %s , p-reach.times);printf(n车离开的时间是: %s , p-leave.times);A1=p-leave.time2;A2=p-reach.time2;B1=p-leave.time2-p-reach.time2;if(B1=0)printf(n费用为: %2.1f元, price);elseprintf(n费用为: %2.1f元, B1/3600*price);free(p);/消费计算函数int arrive(SqStack *In, LinkQueue *W, int MAX, float price)Car *p;QNode *t;time_t rawtime; struct tm * timeinfo; /time ( &rawtime ); / 获取时间,以秒计,从1970年1月一日起算,存于rawtime/timeinfo = localtime ( &rawtime ); /转为当地时间,tm 时间结构/printf ( 当前系统时间: %s, asctime (timeinfo) );/asctime (timeinfo); / 转为标准ASCII时间格式:p = (Car *)malloc(sizeof(Car);printf( = = = = = = = = = = = 欢迎使用停车场管理系统 = = = = = = = = = = = n);printf(您输入的停车场容量为%d位,费用为%2.1f元 / 小时。n, MAX, price);printf(停车场还有%d停车位, 车可先进入便道等待, MAX - In-top);printf(n请输入车牌号码(例:警A1035) :);getchar();scanf(%s, p-num);getchar();if (In-top reach.time2=rawtime;timeinfo = localtime ( &rawtime );In-top+;printf(停车的位置:%d号停车位。, In-top);printf(n车到达的时间为%s ,asctime (timeinfo);strcpy(p-reach.times,asctime (timeinfo);In-stackIn-top = p;printf(请按任意键返回n);printf(n = = = = = = = = = = = = = = = = = = = = = = = n);getchar();return OK;elseprintf( = = = = = 欢迎使用停车场管理系统 = = = = = = = = = n);printf(您输入的停车场容量为%d位,费用为%2.1f元 / 小时。n, MAX, price);printf(n = = = = = = = = = = = = = = = = = = = = = n);printf(停车位已满,该车须在便道等待!);t = (QNode *)malloc(sizeof(QNode);t-data = p;t-next = NULL;W-rear-next = t;W-rear = t;printf(n请按任意键返回);getchar();return OK;getchar();void leave(SqStack *In, SqStack *Out, LinkQueue *W, int MAX, float price)int place;Car *p, *t;QNode *q;time_t rawtime;struct tm * timeinfo;system(CLS);if (In-top0)while (1)printf( = = = = 欢迎使用停车场管理系统 = = = = = = = = = n);printf(您输入的停车场容量为%d位,费用为%2.1f元 / 小时。n, MAX, price);printf(n = = = = = = = = = = = = = = = = = = = = = = = = = = n);printf(请输入车在停车场的位置(1 - %d):, In-top);scanf(%d, &place);if (place = 1 & place top) break;while (In-topplace)Out-top+;Out-stackOut-top = In-stackIn-top;In-stackIn-top = NULL;In-top-;p = In-stackIn-top;In-stackIn-top = NULL;In-top-;while (Out-top = 1)In-top+;In-stackIn-top = Out-stackOut-top;Out-stackOut-top = NULL;Out-top-;print(p, place, MAX, price);if (W-front != W-rear) & In-topfront-next;t = q-data;In-top+;printf(n便道的%s号

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论