用c++设计停车场系统,要求如下(急用!!)

用c++设计一个程序实现停车场管理系统,管理人员根据口令进入系统。 管理车位信息(车位编号,状态)和每小时的收费费率(货车7元/小时,客车5元/小时,轿车4元/小时,其他3元/小时,由停车时开始计时选择录入)。 停车时,建立对象,录入信息(车牌号,停泊位置,停泊开始时间);停车位第一个为空的位置,由程序查询自动给出车位号,如果车位已满要给出提示。 取车时,需要根据车辆停泊时间自动计算费用(半小时内以半价计算,超出半小时不足一小时按一小时计算)并显示在屏幕上。 可以随时根据车牌查询是否入库。可以随时根据车位查询该位置上的相关信息。

#include <iostream> #include <stdio.h> #include <string> #include <time.h> #include<fstream> using namespace std; class car { public: char no[9]; int pos; double fee; void putcar(); void takecar(); }; class Time { public: int hour; int min; void getime(); }; int i,poi; int position[100]={0};//全局变量 car carin[100]; Time catime[100]; int juge(); int comp(); void search_no(); void search_pos(); void main() { /////////////////////////////////////////////用户登录 const char ha[10]="wangbing";//管理员用户名 const char hb[10]="1427";//////管理员密码 char cn[10],cm[10]; int ci=0; while(1) { cout<<"请输入管理员用户名:"; cin>>cn; if(strcmp(ha,cn)) { cout<<"输入错误!\n"; ci++; if(ci==3) return; continue; } else { cout<<"请输入密码:"; cin>>cm; } if(!strcmp(hb,cm)) break; else { cout<<"密码错误!\n"; ci++; if(ci==3) return; continue; } } ////////////////////////////////////////////////主程序 int k; cout<<"请选择:" <<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎" <<"\n\n\t◇ 1.泊车操作 ◇" <<"\n\n\t◇ 2.取车操作 ◇" <<"\n\n\t◇ 3.查询信息 ◇" <<"\n\n\t◇ 4. 退出 ◇ " <<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎\n\n"; ofstream outfile("车辆信息.txt",ios::app); if(! outfile) {cerr<<"open error!"<<endl; exit(1); //ifstream infile("车辆信息.txt",ios::in); //if(! outfile) //{cerr<<"open error!"<<endl; //exit(1); } while(cin>>k) { if(k==1) { i=juge(); cout<<"\t车牌号:"; cin>>carin[i].no; carin[i].putcar(); cout<<"请选择:" <<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎" <<"\n\n\t◇ 1.泊车操作 ◇" <<"\n\n\t◇ 2.取车操作 ◇" <<"\n\n\t◇ 3.查询信息 ◇" <<"\n\n\t◇ 4. 退出 ◇ " <<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎\n\n"; string time1; time_t t; time(&t); time1=ctime(&t); cout<<time1;////////////////////////////////////导入系统时间 outfile<<carin[i].no<<" "<<time1<<endl;/////////保存车辆信息。 continue; } if(k==2) { poi=comp(); carin[poi].takecar(); cout<<"请选择:" <<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎" <<"\n\n\t◇ 1.泊车操作 ◇" <<"\n\n\t◇ 2.取车操作 ◇" <<"\n\n\t◇ 3.查询信息 ◇" <<"\n\n\t◇ 4. 退出 ◇ " <<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎\n\n"; continue; } if(k==3) { int x; while(1) { cout<<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇" <<"\n\n\t查询车牌号请选择1,查询车位请选择2,查询历史信息请选择3,退出请选择4: " <<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇\n\n"; cin>>x; if(x==1) { search_no();break; } else if(x==2) { search_pos();break; } else if(x==3) { string a,time1[100][5];////定义二维数组读取数据 int i,j,m,n; ifstream infile("车辆信息.txt",ios::in); if(! infile) {cerr<<"open error!"<<endl; exit(1); } infile>>a; for(i=0;i<5;i++) for(m=0;m<100;m++) infile>>time1[m][i]; cout<<" "; cout<<a<<" "; for(j=0;j<5;j++) for(n=0;n<100;n++) cout<<time1[n][j]<<" ";///////将存储的数据用数组形式输出 }////////////////////////////////查询历史信息 else if(x==4) { break; } else cout<<"\t选择错误,请重新选择:"; } cout<<"请选择:" <<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎" <<"\n\n\t◇ 1.泊车操作 ◇" <<"\n\n\t◇ 2.取车操作 ◇" <<"\n\n\t◇ 3.查询信息 ◇" <<"\n\n\t◇ 4. 退出 ◇ " <<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎\n\n"; } outfile.close(); } } int juge() ///////////////////////判断出第一个空的车位 { int j=0; while(position[j]==1&&j<100) { j++; } if(j<100) position[j]=1; return j; } int comp() { char ch[9]; cout<<"\t车牌号:"; cin>>ch; for(int k=0;k<100;k++) { if(!strcmp(ch,carin[k].no)) { if(position[carin[k].pos-1]==1) { return (carin[k].pos-1); break; } } } if(k=100) return k; } void car::putcar() { int t; while(1) { cout<<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎" <<"\n\n\t货车请输入1,客车请输入2,轿车请输入3,其他请输入4: " <<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎\n\n"; cin>>t; if(t==1) { carin[i].fee=7.0;break; } else if(t==2) { carin[i].fee=5.0;break; } else if(t==3) { carin[i].fee=4.0;break; } else if(t==4) { carin[i].fee=4.0;break; } cout<<"输入错误!请重新输入:\n"; } if(i==100) cout<<"对不起,车位已满!\n"; carin[i].pos=i+1; //自动输出车位号 cout<<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎"; cout<<"\n\n\t车位号:"<<carin[i].pos<<endl; catime[i].getime(); cout<<"\n\n\t现在时间是:"<<catime[i].hour<<":"<<catime[i].min<<endl; cout<<"\n\n\t◇◎◇◎◇◎◇◎◇◎◇◎◇◎◇◎"<<endl; } void car::takecar() { int hour1,min1; double charge; if(poi<100) { position[poi]=0;//重新设置为空位 hour1=catime[poi].hour; min1=catime[poi].min; catime[poi].getime(); hour1=catime[poi].hour-hour1; min1=catime[poi].min-min1; if(min1<30)//计算出停车时间 charge=carin[poi].fee*hour1+carin[poi].fee*0.5; else charge=carin[poi].fee*hour1+carin[poi].fee; cout<<"\t车费为:"<<charge<<"元.\n"; //计算出车费输出 } else cout<<"\t无此车!\n"; } void Time::getime() { struct tm *newtime; //获取停车时间 time_t long_time; time( &long_time ); newtime = localtime( &long_time ); hour=newtime->tm_hour; min=newtime->tm_min; } void search_no() { int poi=comp(); if(poi<100) cout<<"\t此车已入库,车位为:"<<poi+1<<endl; else cout<<"\t此车没有入库。\n"; //根据车牌号查询是否入库 } void search_pos() { int loc; cout<<"\t车位号:"; ///////////根据车位查询车位状态 cin>>loc; if(position[loc-1]==1) { cout<<"\t车牌号:"<<carin[loc-1].no<<endl; cout<<"\t停车时间:"<<catime[loc-1].hour<<":"<<catime[loc-1].min<<endl;//停车直到现在的时间 } else cout<<"\t此车位无车!"; } ///////////////////////////////////////程序结束。 - -!!搞定!!
温馨提示:答案为网友推荐,仅供参考
相似回答