停车场管理系统 程序设计
时间:2026-01-24
时间:2026-01-24
数据结构程序设计
一、 停车场管理系统
1.1设计要求
1.1.1问题描述
设计一个停车场管理系统,模拟停车场的运作,此程序具有以下功能: ① 汽车到达,则显示汽车在停车场内或便道上的停车位置。
② 若车离去,则显示汽车在停车场内停留的时间和应缴纳的费用(在便道上停留的时间不
收费)。 1.1.2基本要求
①要求以栈模拟停车场,以队列模拟车场外地便道,按照从终端读入的输入数据序列进行模拟管理。
② 求处理的数据元素包括三个数据项:汽车“到达”或“离去”信息。汽车牌照号码以及
离去的时刻。
③ 要求栈以顺序结构实现,队列以链表实现。 1.1.3测试数据
自行设计一组在停车场上停车的数据和便道上停车的数据。 1.1.4实现提示
该停车场能容纳车辆的数量,便道上的停车数量。车辆到达对应栈的入栈操作,车辆离开对应栈的出栈操作。
1.2设计代码及注释
#include<iostream> #include<time.h> #include<ctime> #include<dos.h> #include<windows.h> using namespace std; #define PASS 20 #define POT 20
struct passLot//便道队列数据结构 {
int num;//车位号 time_t timep;//停车时间 int carNum;//停车的车牌号码 };
struct potLot//停车场栈数据结构
数据结构程序设计
int num; time_t timep; int carNum; };
void printLine()//打印下划线(作为主界面图表的框架) {
cout<<"\t\t\t___________________________________"<<endl; return; }
void printStar()//打印星号 {
cout<<endl<<"\t\t******************************************************"<<endl; }
class erroFull//停车位满时异常类 {public: };
class erroEmp//停车位空时异常类 {public: };
erroEmp() {
system("color 3c"); } void ex() {
cout<<"!!!停车场位为空!"<<endl; _sleep(2000); }
~erroEmp(){} erroFull() {
system("color 3c"); } void ex() {
cout<<endl<<"\t\t\t!!!停车场位已满!"<<endl; _sleep(2000); }
~erroFull(){}
数据结构程序设计
class parkingLot//停车场类 { public:
void passLG()//便道管理函数 {
try {
if(flag==20) throw erroFull();//如果停车位已满,则抛出车位慢得异常情况 system("cls"); printStar();
cout<<"\t\t\t\t您进入了便道停车界面"<<endl;
cout<<endl<<"\t\t\t便道停车场共有20个车位,现共停"<<flag<<"个车位。
~parkingLot() {
cout<<"\t\t停车场数据已清空。"<<endl; }
parkingLot() { }
passLot* pa;//便道停车位指针 potLot* po;//停车场停车位指针
flag=0;//用来记忆队列(便道)中停车的数量 rear=front=0;//初始化队列头尾 base=0;
top=base;//初始化栈头尾
int i=0;//初始化停车场和便道空间以及车位号 for(;i<POT;i++) { }
pa=(passLot*)malloc(sizeof(passLot)); a[i]=pa; a[i]->num=i+1; a[i]->carNum=0;
po=(potLot*)malloc(sizeof(potLot)); b[i]=po; b[i]->num=i+1; b[i]->carNum=0;
"<<endl<<endl;
cout<<"\t\t\t请输入将要停车的号码:";
数据结构程序设计
}
}
catch(erroFull &err) {
err.ex(); }
a[rear]->timep=time(NULL);
cout<<endl<<"\t\t\t!!汽车停放在"<<a[rear]->num<<"车位成功,系统将在一秒后返回rear=(rear+1)%PASS; flag++; _sleep(1000);
上层界面!!"<<endl;
void potLG()//停车场管理函数 { }
try {
if(top==20) throw erroFull(); system("cls"); printStar();
cout<<"\t\t\t\t您进入了停车场停车界面"<<endl;
cout<<endl<<"\t\t\t停车场共有20个车位,现共停"<<top<<"个车位。"<<endl<<endl;
cout<<"\t\t\t请输入将要停车的号码:";
cin>>b[top]->carNum; }
catch(erroFull &err) {
err.ex(); }
b[top]->timep=time(NULL);
cout<<endl<<"\t\t\t!!汽车停放在"<<b[top]->num<<"车位成功,系统将在一秒后返回上top++; _sleep(1000);
层界面!!"<<endl;
void arrive()//汽车到达 {
int choice=-1; for(;;)
if(top==20&&flag==20) throw erroFull();
数据结构程序设计
system("cls");
printStar();
cout<<"\t\t\t\t欢迎进入停车场"<<endl<<endl;
cout<<"\t\t请输入你的选项:"; }
int feep(time_t* tmp)//费用计算 {
int gap=0,m=0,hour=0,min=0,sec=0;//设置数据用来计算时间间隔,停车时、分、秒。
local=localtime(tmp);//将存储的时间转化为当地时间日历
<<local->tm_sec<<endl;//显示停车时刻
cout<<local->tm_hour<<":"<<local->tm_min<<":" hour=local->tm_hour;//保存停车时刻
min=local->tm_min; sec=local->tm_sec; now=time(NULL);
cout<<"\t当前时间为:"<<nowp->tm_hour<<":"<<nowp->tm_min<<":"
<<nowp->tm_sec<<endl;
cin>>choice; {
case 1:potLG();break; case 2:passLG();break; case 3:break;
default:syste …… 此处隐藏:5820字,全部文档内容请下载后查看。喜欢就下载吧 ……
下一篇:中央空调机组保养合同