(高分悬赏)C++停车场管理系统

设停车场是一个可停放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)。
[实现提示]
需另设一个栈,临时停放为给要离去的汽车让路而从停车场退出来的汽车,也用顺序存储结构实现。输入数据按到达或离去的时刻有序。栈中每个元素表示一辆汽车,包含两个数据项:汽车的牌照号码和进入停车场的时刻。
!!!请务必按照提示做!!!,网上有很多答案,但没一个符合要求的。如果回答符合要求,再加分
如果不用栈,我也会做,就不用在网上提问了

#include <stdio.h>/*包含了与标准I/O库有关的变量定义和宏定义*/
#include <stdlib.h>/*文件包含所用的文件*/
#include<conio.h>
#include<io.h>

int cars[12][4]={{1234,1,1,20},{2345,1,2,15},{3456,1,3,10},
{4567,1,4,5},{0,1,5,0},{0,1,6,0},{0,2,1,0},{0,2,2,0},{0,2,3,0},
{0,2,4,0},{0,2,5,0},{0,2,6,0}};/*二维数组代表停车信息*/

void save()
{FILE *fp;
int i,j;
if((fp=fopen("car.dat","w"))==NULL)
{printf("cannot open file\n");
return;
}
for(i=0;i<12;i++)
for(j=0;j<4;j++)
if(fwrite(cars,2,1,fp)!=1)
printf("file write error\n");
fclose(fp);
getchar();
}

void car_park(void)/*停车操作*/
{int x,i,j;
printf("\n ^-^ Welcome To Our Stop! ^-^\n ");
printf(" \n\n Please,input your car number:\n\n");
printf("\n NOTICE:car number is a digit between 1000 and 9999\n Input wrong number may back to menu\n\n");
scanf("%d",&x);/*输入要停车的车牌号*/
for (i=0;i<12;i++)
if(cars[i][0]==x||x<1000||x>9999)break;
if(i!=12)
{printf("\nWrong number or it's parked !!!\n");
getchar();}/*如果此车号以在,打印此车已停*/
else if(i==12&&x>=1000&&x<=9999)
{for (i=0;i<12;i++)
if(cars[i][0]==0) {cars[i][0]=x;save();
printf("\n\nSUCCESS\n\n");
printf("Floor=%d,position=%d\n",cars[i][1],cars[i][2]);
printf("\n\n\nTwo times 'Enter' to end...");break;
}/*如果此车号不在,则进行停车操作*/
for (i=0;i<12;i++)
if(cars[i][0]!=0) cars[i][3]+=5;/*所有停车时间+5*/
save();/*保存以上信息到文件*/

}
}

void car_get(void)/*取车操作*/
{
int i,y;float paid;int a;
printf("\n Get Car\n\n\n Input your car number:\n\n\n\n");
printf("\n NOTICE:car number is a digit between 1000 and 9999\n Wrong load would have no cue\n\n");
scanf("%d",&y);/*输入要取车的车牌号*/

for(i=0;i<12;i++)
{
for(i=0;i<12;i++)
if(cars[i][0]==y)
{
cars[i][0]=0;/*取车后车牌号清零*/
paid=0.2*cars[i][3]/5;/*计算停车费用*/
printf("\n Printf out the paid?(1--YES 2 or any key--NO)\n\n\n");
scanf("%d",&a);
{
switch(a)
{
case 1:
printf("\n\n\nThe paid is %8.2fyuan\n",paid);/*打印停车费用*/
cars[i][3]=0;/*时间清零*/
save();
break;
case 2:
printf("Good bye");
cars[i][3]=0;/*时间清零*/
save();
break;
default: break;
}
}
}else;break;
}
if(i==12)printf("\nThe number is not in the park!!!\n");/*如果此车不在,打印号码不在*/
}

void printfdata()/*停车信息*/
{int i,j;
FILE *fp;
fp=fopen("car.dat","r");/*打开文件"car.dat"*/
printf(" \n Number Floor Position Time\n");
for(i=0;i<12;i++)
{for(j=0;j<4;j++)
{fread(cars,2,1,fp);/*读文件*/
printf(" %6d",cars[i][j]);
}printf("\n");
}
fclose(fp);/*关闭文件"car.dat"*/
}

void save();
void car_park(void);
void car_get(void);
void printfdata();
char readcommand();
void initialization();
void main()
{
char c;
while(1)
{
initialization(); /*初始化界面*/
c=readcommand(); /*读取停车场状况*/
clrscr();
switch(c)
{
case 'p': car_park(); break;/*停车操作*/
case 'P': car_park(); break;/*停车操作*/
case 'g': car_get(); break;/*取车操作*/
case 'G': car_get(); break;/*取车操作*/
case 'd': printfdata();
printf("\n\n please press 'Enter' to continue....\n");
scanf("%c",&c); break;/*停车信息*/
case 'D': printfdata(); /*停车信息*/
printf("\n\n rreupklfdkplease press 'Enter' to continue....\n");
scanf("%c",&c); break;
case 'e': printf("\n\n\n\n Press 'Enter' to continue...");exit(0); break;
case 'E': printf("\n\n\n\n Press 'Enter' to continue...");exit(0); break;
default : printf("ERROR! Press 'Enter' to continue..."); getchar(); break;
}
}
}
/********************************************************************************/

void initialization() /*初始函数*/
{
int i;
getchar();
clrscr();
gotoxy(0,0);
for(i=1;i<=80;i++) printf("\1\3");
for(i=1;i<=80;i++) printf("\2");
gotoxy(15,6);
printf("THIS IS OUR CAR PART MANAGE SYSTEM!");
gotoxy(15,9);
printf("NAME: GuanYoufu");
gotoxy(15,10);
printf("NUM: 1111111327");
gotoxy(15,11);
printf("GRADE: 2006");
gotoxy(15,12);
printf("CLASS: caiyan0603");
gotoxy(1,14);
printf("\n********************************************************************************\n");
printf(" 1. Park car--p 2. Get car--g 3. Date of parking--d 4.Exit--E");
printf("\n\n********************************************************************************\n");

}

char readcommand() /*选择函数*/
{
char c;
while((c!='p')&&(c!='P')&&(c!='g')&&(c!='G')&&(c!='d')&&(c!='D')&&(c!='e')&&(c!='E'))
{
printf("Input p,g,d,e choose!!\n");
c=getchar();
printf("\n");break;
}
return c;
}

根据自己得需要修改一下吧
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-08-12
呵呵,找到了,应该就是你要的了
http://www.pudn.com/downloads116/sourcecode/math/detail489511.html
这个,下载地址是
http://www.pudn.com/downloads116/sourcecode/math/21840280tingchechang.rar
如果不行的话
http://www.pudn.com/search_db.asp?keyword=%CD%A3%B3%B5%B3%A1+%D5%BB&p=C%2B%2B
这里还有几个,我再帮你下载。本回答被提问者采纳
第2个回答  2008-08-10
楼上的没看到人家要C++的

要是n值不定,必须用链表了(栈也可以)
首先要建立一个停车位的结点(我这样写便于理解,但不是最优的方法):
struct point {
int no(车号),time(进入时刻),n(停车位),key(该位是否有车0为无,1有);
No *next,*top;
}a,*p;
然后读入n=i;建立链表:
a.next=NULL;
p=&a;
for(k=2;k<=n;k++){
p->next=new point;
p->next->next=NULL;
p->next->n=k;
p->next->key=0;
p->next->top=p;
p=p->next;}
然后让p指向表头,进一辆车将数据写入p指向,并将p指向p->next;
初一辆车搜索链表,找到位置,计算时间并cout,再将后面的车辆数据向前挪1位.

具体的还是你自己写吧,思路其实也不难
第3个回答  2008-08-11
栈以顺序结构实现,队列以链表结构实现 如果把这个要求取消 会简单和直观很多
第4个回答  2008-08-11
如果能接受C 的话,我倒能试试. ryw12403
用C的话是不是要用上指向指针的指针和结构体才可以?
我的思路是要两个都用上才行.
相似回答