资源描述
重庆科技学院
课程设计报告
院(系):_电气与信息工程学院___ 专业班级: 计科普0902
学生姓名: 杨宝 学 号: 2009441658
设计地点(单位)__ _计算机自主学习中心I306 _ _ _____ __
设计题目:_______停车场管理系统的设计________ _____
完成日期: 年 月 日
指导教师评语: _______________________________________
_________________________________________________________________________________________________________________________________________________________________________________________________________ __________ _
成绩(五级记分制):______ __________
指导教师(签字):________ ________
重庆科技学院
课程设计任务书
设计题目:停车场管理系统的设计
学生姓名
杨宝
课程名称
数据结构课程设计
专业班级
计科2009-02
地 点
计算机基础自主学习中心
起止时间
2011.01.4-2011.01.14
设计内容及要求
问题描述:
设停车场是一个可停放n辆汽车的狭长通道,且只有一个大门可供汽车进出。汽车在停车场内按车辆到达时间的先后顺序,依次由北向南排列(大门在最南端,最先到达的第一辆车停放在停车场的最北端),若停车场内已停满n辆汽车,则后来的汽车只能在门外的便道上等候,一旦有车开走,则排在便道上的第一辆车即可开入;当停车场内某辆车要离开时,在它之后进入的车辆必须先退出车场为它让路,待该辆车开出大门外,其他车辆再按原次序进入车场,每辆停放在车场的车在它离开停车场时必须按它停留的时间长短交纳费用。试为停车场编制按上述要求进行管理的模拟程序。
基本要求
以栈模拟停车场,以队列模拟车场外的便道,按照从终端读入的输入数据序列进行模拟管理。每一组输入数据包括三个数据项:汽车“到达”或“离去”信息、汽车牌照号码以及到达或离去的时刻。对每一组输入数据进行操作后的输出信息为:若是车辆到达,则输出汽车在停车场内或便道上的停车位置;若是车辆离去,则输出汽车在停车场内停留的时间和应交纳的费用(在便道上停留的时间不收费)。栈以顺序结构实现,队列以链表结构实现。
设计
参数
设n=2,输入数据为:(‘A’,1,5),(‘A’,2,10),(‘D’,1,15),(‘A’,3,20),(‘A’,4,25),(‘A’5,30),(‘D’,2,35),(‘D’,4,40),(‘E’,0,0)。
其中:‘A’表示到达(arrival);‘D’表示离去(departure);‘E’表示输出结束(end)。
进度
要求
2011.1.4 星期二(上午教师指导,下午学生独立完成)、完成任务的讲解、并接受课程设计任务,选定课程设计的题目
2011.1.5 星期三(上午教师指导,下午学生独立完成)、了解任务的算法、并画出算法的程序流程图
2011.1.6 星期四(上午教师指导,下午学生独立完成)、对任务的关键技术进行验证、并确定解决办法
2011.1.7 星期五(上午教师指导,下午学生独立完成)、编制任务的程序
2011.1.10 星期一(上午教师指导,下午学生独立完成)、编制任务的程序
2011.1.11 星期二(上午教师指导,下午学生独立完成)、对程序的调试,并试运行。
2011.1.12 星期三(上午教师指导,下午学生独立完成)、整理课程设计过程中的各个参数、并进行总结,提出改进意见
2011.1.13 星期四(上午教师指导,下午学生独立完成)、编写课程设计报告、准备答辨
2011.1.14 星期五(上午答辨)、进行答辨验收工作。
参考资料
1.严蔚敏 吴伟民 著, 数据结构(C语言版),清华大学出版社,2007.4
2.Richard F.Gilberg Behrouz A.Forouzan, Data Structures A Pseudocode Approach with C,second edition, Thomson, 2005.1
3. 李春葆 著,数据结构教程,清华大学出版社,2005.1
其它
说明
1.本表应在每次实施前一周由负责教师填写二份,院系审批后交院系办备案,一份由负责教师留用。2.若填写内容较多可另纸附后。3.一题多名学生共用的,在设计内容、参数、要求等方面应有所区别。
教研室主任: 指导教师:向毅、陈刘奎、熊茜
2010年 12 月 20日
摘要
该程序要是解决单向停车场停车的问题。先停的车停在距出口比较远的地方,最后停的一辆车在距出口最近的地方,当停在里面的车要离开停车时,在它之后停的车都将要退出停车场,让它出来,然后再依次重新进入。
关键字:堆栈 数组 停车管理管理系统
目录
一 软件需求分析说明 1
1 软件的功能 1
1.1 设置停车的容量 1
2 界面要求 1
3 数据库要求 1
二 系统分析与设计 2
1 输入输出界面 2
1.1 设置容量: 2
1.2 选择命令 2
1.4 汽车离开停车场时 3
1.5 过道里带停的车 3
1.6 退出系统 4
2 数据结构的设计 4
2.1 汽车结构体的设计 4
2.2 停车场的设计 4
2.3 汽车过道的设计 5
3 程序流程图 5
三 软件测试 7
四 软件使用说明书 8
致谢 9
参考文献 10
附录 11
5
一需求分析
1 设置停车的容量
在运行程序后的第一步就是设置停车场容量的大小,设置好后保存下来。在汽车进场停车时,程序会自动返还停车内是否有车位的信息,车主即可通过这个信息知道当前所在的停车场还能否停车。
2 界面要求
程序需要给用户提供的信息,所以应该尽可能的简单,让观看者知道整个停车场当前的所有情况。
3 数据库要求
该程序是一个停车场管理系统,所以需要的数据比较简单。但程序正常运行时,关于停车的时间是由系统自动的获取,在汽车离开时,系统又会根据当前系统时间算出该车停留的总时间。关于汽车的信息,主要是量的问题,考虑到全部由键盘输入的话,数据量会比较大,所以将汽车本身的信息存在文件里,在程序运行时,由用户选择命令。
二 系统分析与设计
1 输入输出界面
1.1 设置容量:
该界面是在程序运行后的第一个界面,正确的操作为输入一个大于零的整数。该整数就是停车场的最大停车数,当停车场内停的车的数量超过最大容量,系统将自动提醒用户该停车场已经停满了。
1.2 命令选择
程序运行后,用户要在当前界面做出选择,停车选择“A”选项,提车选“D”选项, 退出系统选“O”选型。
1.3 显示停车场内的车
当用户停车后,。系统会自动记录该车所在的位置,同时将停车场内已停车的信息显示出来,同时也将显示在过道里的车的信息。
1.4 汽车离开停车场时
当汽车从停车场内出来时,需要将该车的信息显示出来,方便用户确认以及缴纳相关的费用。
2 数据结构的设计
2.1汽车结构体的设计
typedef struct
{
int CarType;
char CarNum [11];
int location;
double duration_begin;
double duration_end;
char CarsHost[24];
} Cars;
汽车的信息包括汽车类型(CarType),不同类型的车收费额度不同;车牌(CarNum [11],每辆车的车牌是唯一的,这个信息必须存储;车主(CarsHost[24]),要记录下停车时该车的驾驶人是谁,以及两个关于时间的量duration_begin和duration_end,这两个量分别用于存储该车停和离开时的时间,系统通过这两个时间算出需要交纳的费用。
2.2停车场的设计
代码如下:
typedef struct
{
int count;
int LagNunOfPar;
STACK_NODE* top;
} STACK;
该停车场有唯一的进出口,而且只能单向顺序通,所以行采用堆栈结构模拟停车场。 停车场的设计内容包括车辆计数(count),最大停车数(LagNunOfPar)以及一个指向汽车信息的指针(STACK_NODE* top),用于记录汽车的信息。
2.3 停车场外过道的设计
代码如下:
typedef struct{
QUEUE_NODE* front, * rear;
int count;
} QUEUE;
过道同样是单向通行,但有指定的入口和出口,并按进入的先后顺寻出来,所以在程序设计中采用队列模拟过道。过道的信息比较简单,两个指针(front)和(rear),全是指向汽车信息的指针,分别指向过道中第一辆汽车和最后一辆,还有过道的车辆计数(count),方便管理。
3 主程序结构图
开始
设置容量
设置待停的车
停车
离开
退出系统
选择命令
结束
4
图 2.8 主程序结构图
程序从“开始”处开始运行,首先需要设置一下最大容量,其次程序自动设置一部分待停的车在过道里,用户即可选择命令进行操作,。停车,取车还是退出系统
三 软件测试
1 设计停车场最大容量
图3.1 设子最大停车数
停车场内所能容纳的车辆数是有限的,因此,在程序运行的最开始需要对此进行设置,以便在以后停车时,判断是否还有车位。
2 停车
图3.2 选择停车命令
选择该命令后,系统将自动排在过道中的第一辆汽车停入停车场内,并将停车场内停车的情况显示出来,如图3.3
图3.3 停车情况
3 取车
当车主驾车离开停车场时,显示出该车的信息,并自动结算需要缴纳的费用。
图3.4 用户取车
4 退出系统
当用户离开是选择退出系统命令。
图3.5 退出系统
四 软件使用说明书
首先需要对停车场进行初始化,也就是设置所能容纳的最大数量,如图4.1所示。
(图4.1 设置容量)
因为软件的使用者将是大量的司机,所以要求程序应设计的比较通俗易用,因此,程序的界面非常的简单,选择“A”就是要停车(图4.2),“D”就是要取车(4.3),“O”就是退出(图4.4)。
(图 4.2 停车)
(图 4.3 取车)
(图 4.4 离开)
致谢
通过本次的程序设计,我对于相关数据结构的知识有了更好的理解,同时更加熟悉了C语言以及C++语言的知识。在本次程序设计中,遇到了很多的困难,比如结构体的封装,堆栈和队列的ADT编写以及相关操作的实现,特别是在函数参数传递和头文件的包含问题上,让我非常苦恼,在老师和同学的帮助下,都一一解决了,并且很好的掌握的相关知识。通过这次课程设计,我学到了很多知识,
同时,也加深了同学间的情感。
感谢老师的精心的知道,感谢同学们对我的帮助。
签名: 杨宝
日期:
参考文献
1.严蔚敏 吴伟民 著, 数据结构(C语言版),清华大学出版社,2007.4
2.Richard F.Gilberg Behrouz A.Forouzan, Data Structures A Pseudocode Approach with C,second edition, Thomson, 2005.1
3. 李春葆 著,数据结构教程,清华大学出版社,2005.1
附录
1 main
#include<iostream>
#include<stdio.h>
#include<windows.h>
#include"stackSADT.h"
#include"queueADT.h"
#include"CarsDataStr.h"
#include"PrintADT.h"
#include"Parking.h"
#include"Departure.h"
#include <stdlib.h>
#include<time.h>
using namespace std;
int main()
{
STACK* stack;
stack=createStack ( );
FILE* fpData = NULL;
QUEUE* queue;
queue=createQueue ( );
Cars *cars;
// double duration=0;
int LgtNumOfPar=0;
char choice;
int CarType;
int _while=1;
printf("/*************Welcome to parking program of Yang Bao********/\n\n");
printf("How many cars do your park can include, please set rigth now__ ");
fflush(stdin);
scanf("%d" ,&LgtNumOfPar);
while(LgtNumOfPar <= 0)
{
printf("Error ! Please set again \n");
system("pause");
system("cls");
printf("How many cars do your park can include, please set rigth now__ ");
fflush(stdin);
scanf("%d" ,&LgtNumOfPar);
}
printf("\n");
//========Waiting Cars=============
if (!queue)
{
printf("\aCannot create queue\n"),
exit (100);
}
fpData = fopen("waitingcars.dat", "r");
if (!fpData)
{
printf("\aError opening input file\n"),
exit (110);
}
while (fscanf(fpData, " %d", &CarType) == 1)
{
cars = (Cars*) malloc(sizeof(Cars));
if (!(cars))
printf("\aOut of Memory in build waiting cars\n"),
exit (100);
cars->CarType=CarType;
while ((fgetc(fpData)) != '\t')
;
while ((fgetc(fpData)) != '"')
;
fscanf(fpData, " %11[^\"], %*c", cars->CarNum);
while ((fgetc(fpData)) != '\t')
;
while ((fgetc(fpData)) != '"')
;
fscanf(fpData, " %24[^\"], %*c", cars->CarsHost);
// Insert into list */
while (fgetc(fpData) != '\n') ;
enqueue(queue, cars);
} // while
//==============Choice===================
printf("/-------------Arrive----------------A/\n");
printf("/-------------Departure-------------D/\n");
printf("/-------Just out of program-------- O/\n");
printf("Please take your choice__: ");
fflush(stdin);
scanf("%c",&choice);
//---------------------------------
//=====================Process =======================
while(_while != 0)
{
switch(choice)
{
case 'A':
ParkingCars( stack, queue, LgtNumOfPar);// 停车
break;
case 'a':
ParkingCars( stack, queue,LgtNumOfPar);// 停车
break;
case 'D':
departure(stack); // 离开
break;
case 'd':
departure(stack); // 离开
break;
case 'O':
printf("Thanks for your coming, see you again. Good lucky! \n"); // error input
return 0;
case 'o':
printf("Thanks for your coming, see you again. Good lucky! \n");
return 0;
}
if(choice != 'a' && choice != 'A' )
{
if(choice != 'd' && choice != 'D' )
{
if(choice != 'o' && choice != 'O' )
{
printf("Error choice. Please try again!\n");
system("pause");
}
}
}
system("cls");
printf("/-------------Arrive----------------A/\n");
printf("/-------------Departure-------------D/\n");
printf("/-------Just out of program-------- O/\n");
printf("Please take your choice__: ");
fflush(stdin);
scanf("%c",&choice);
}
//-------------------------------------------------------------------------------------
cout<<"Thanks for your using, see you again!" ;
return 0;
}
2 CarsDataStr.h
typedef struct
{
int CarType;
char CarNum [11];
int location;
double duration_begin;
double duration_end;
char CarsHost[24];
} Cars;
3 CreateQueue.h
/* ================= createQueue ================
Allocates memory for a queue head node from dynamic
memory and returns its address to the caller.
Pre nothing
Post head has been allocated and initialized
Return head if successful; null if overflow
*/
QUEUE* createQueue (void)
{
// Local Definitions
QUEUE* queue;
// Statements
queue = (QUEUE*) malloc (sizeof (QUEUE));
if (queue)
{
queue->front = NULL;
queue->rear = NULL;
queue->count = 0;
} // if
return queue;
} // createQueue
4 createStack.h
/* =============== createStack ==============
This algorithm creates an empty stack.
Pre Nothing
Post Returns pointer to a null stack
-or- NULL if overflow
*/
STACK* createStack (void)
{
// Local Definitions
STACK* stack;
// Statements
stack = (STACK*) malloc( sizeof (STACK));
if (stack)
{
stack->count = 0;
stack->top = NULL;
} // if
return stack;
} // createStack
5 Departure.h
//the process of depart
#include <stdlib.h>
#include<time.h>
clock_t end;
bool departure(STACK* stack)
{
STACK *ptStack;
STACK *ptStDep;
Cars *ptCars;
int location=0;
ptStDep=createStack();
ptStack=createStack();
if(stackCount(stack) == 0)
{
printf("Error ! This loction has no parking car ~~\n");
system("pause");
system("cls");
return false;
}
printf("Please tell me your car's location number: ");
fflush(stdin);
scanf("%d", &location);
if(stack->LagNunOfPar < location)
{
printf("Sorry , this location has no car~~\n\n");
system("pause");
system("cls");
return false;
}
system("cls");
while(stackCount(stack) > location)
{
ptCars=(Cars *)popStack(stack);
pushStack(ptStack, ptCars);
}
if(stackCount(stack) == location)
{
ptCars=(Cars *)popStack(stack);
pushStack(ptStDep, ptCars);
end = clock();
ptCars->duration_end=(double) (end)/CLOCKS_PER_SEC;
printf("/============Departure Cars===========*/\n");
switch(ptCars->CarType)
{
case 1:
printf("Cars'type: 大卡车 \n");
break;
case 2:
printf("Cars'type: 轿车 \n");
break;
case 3:
printf("Cars'type: 巴士 \n");
break;
}
// printf("Cars'type: %d\n", ptCars->CarType);
printf("Cars'num : %s\n", ptCars->CarNum);
printf("Cars' Host : %s\n\n", ptCars->CarsHost);
printf("This car has been parking for %f seconds! \n", (ptCars->duration_end-ptCars->duration_begin));
if(ptCars->CarType ==1)
printf("The money need to pay is : $ %d \n\n", (int )((ptCars->duration_end-ptCars->duration_begin)*1));
if(ptCars->CarType == 2)
printf("The money need to pay is : $ %d \n\n", (int )((ptCars->duration_end-ptCars->duration_begin)*2));
if(ptCars->CarType ==3)
printf("The money need to pay is : $ %d \n\n", (int )((ptCars->duration_end-ptCars->duration_begin)*3));
printf("/------------Departure Cars-----------*/\n\n");
while(stackCount(ptStack) != 0)
{
ptCars=(Cars *)popStack(ptStack);
pushStack(stack, ptCars);
ptCars->location=stackCount(stack);
}
printParkingCars(stack);
system("pause");
system("cls");
destroyStack(ptStack);
destroyStack(ptStDep)
return true;
}
return true;
}
7 Dequeue.h
/* ================= dequeue ================
This algorithm deletes a node from the queue.
Pre queue has been created
Post Data pointer to queue front returned and
front element deleted and recycled.
Return true if successful; false if underflow
*/
bool dequeue (QUEUE* queue, void** itemPtr)
{
// Local Definitions
QUEUE_NODE* deleteLoc;
// Statements
if (!queue->count)
return false;
*itemPtr = queue->front->dataPtr;
deleteLoc = queue->front;
if (queue->count == 1)
// Deleting only item in queue
queue->rear = queue->front = NULL;
else
queue->front = queue->front->next;
(queue->count)--;
free (deleteLoc);
return true;
} // dequeue
8 DestroyQueue.h
QUEUE * destroyQueue(QUEUE* queue)
{
QUEUE_NODE * deletePtr;
if(queue)
{
while(queue->front != NULL)
{
free(queue->front->dataPtr);
deletePtr = queue->front;
queue->front = queue->front->next;
free(deletePtr);
}
free(queue);
}
return NULL;
}
9 destroyStack.h
/* ================== destroyStack =================
This function releases all nodes to the heap.
Pre A stack
Post returns null pointer
*/
STACK* destroyStack (STACK* stack)
{
// Local Definitions
STACK_NODE* temp;
// Statements
if (stack)
{
// Delete all nodes in stack
while (stack->top != NULL)
{
// Delete data entry
free (stack->top->dataPtr);
temp = stack->top;
stack->top = stack->top->link;
free (temp);
} // while
// Stack now empty. Destroy stack head node.
free (stack);
} // if stack
return NULL;
} // destroyStack
10 EmptyQueue.h
/* ================== emptyQueue =================
This algorithm checks to see if queue is empty
Pre queue is a pointer to a queue head node
Return true if empty; false if queue has data
*/
bool emptyQueue (QUEUE* queue)
{
// Statements
return (queue->count == 0);
} // emptyQueue
11 emptyStack.h
/* ================= emptyStack ================
This function determines if a stack is empty
Pre stack is pointer to a stack
Post returns 1 if empty; 0 if data in stack
*/
bool emptyStack (STACK* stack)
{
// Statements
return (stack->count == 0);
} // emptyStack
12 Enqueue.h
/* ================= enqueue ================
This algorithm inserts data into a queue.
Pre queue has been created
Post data have been inserted
Return true if successful, false if overflow
*/
bool enqueue (QUEUE* queue, void* itemPtr)
{
// Local Definitions
QUEUE_NODE* newPtr;
// Statements
if (!(newPtr =
(QUEUE_NODE*)ma
展开阅读全文