停车场管理系统设计样本_第1页
停车场管理系统设计样本_第2页
停车场管理系统设计样本_第3页
停车场管理系统设计样本_第4页
停车场管理系统设计样本_第5页
已阅读5页,还剩65页未读 继续免费阅读

下载本文档

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

文档简介

资料内容仅供您学习参考,如有不当或者侵权,请联系改正或者删除。面向对象程序设计(C++)课程大作业设计题目:停车场管理系统设计院系:计算机科学与信息工程学院专业班级:学号姓名:指导教师:年1月目录TOC\o"1-3"\u一、 成员分工 1二、需求分析 2三、总体设计 3四、详细设计 6五、系统测试 17六、总结 20七、参考文献 21一成员分工我们小组成员共有三名,分别是,为了能按时圆满的完成这次VC++课程设计,我们小组进行了详细的分工,以确保设计能按时完成。经过周密的考虑和详细的调查最终确定该停车场管理系统需要以下几个功能模块:需求分析界面的设计添加功能显示功能查询功能编辑功能删除功能统计功能保存功能读取功能经过小组成员的讨论,并根据个人的特长和具体爱好做如下具体分工:神1具体完成以下模块的设计与实现:)需求分析)界面的设计)添加功能)保存功能神2具体完成以下模块的设计与实现:显示功能查询功能显示功能神3主要具体完成以下模块的设计与实现:编辑功能删除功能读取功能二需求分析问题描述定义车辆类,属性有车牌号、颜色、车型(小汽车、小卡、中卡和大卡)、到达的时间和离开的时间等信息和相关的对属性做操作的行为。定义一个管理类,完成对停车场的管理。停车场的具体要求:设停车场是一个可停放n辆汽车的狭长通道,且只有一个大门可供汽车进出。汽车在停车场内按车辆到达时间的先后顺序,依次由北向南排列(大门在最南端,最先到达的第一辆车停放在车场的最北端),若车场内已停满n辆汽车,则后来的汽车只能在门外的便道上等待,一旦有车开走,则排在便道上的第一辆车即可开入;每辆停放在车场的车在它离开停车场时必须按它停留的时间长短交纳费用。2.基本要求(1)添加功能:程序能够添加到达停车场的车辆信息,要求车辆的车牌号要唯一,如果添加了重复编号的记录时,则提示数据添加重复并取消添加。(2)查询功能:可根据车牌号、车型等信息对已添加的停车场中的车辆信息进行查询,如果未找到,给出相应的提示信息,如果找到,则显示相应的记录信息;(3)显示功能:可显示当前系统中所有车辆的信息,每条记录占据一行。(4)编辑功能:可根据查询结果对相应的记录进行修改,修改时注意车牌号的唯一性。(5)删除功能:主要实现对已添加的车辆记录进行删除。如果当前系统中没有相应的人员记录,则提示”记录为空!”并返回操作。(6)统计功能:能统计停车场中车辆的总数、按车型、按到达时间进行统计等。(7)保存功能:可将当前系统中各类人员记录和休假记录存入文件中,存入方式任意。(8)读取功能:可将保存在文件中的信息读入到当前系统中,供用户进行使用。3.系统运行环境(1)硬件环境。联想双核处理器,2G内存,2G独立显卡,80G硬盘。(2)软件环境。MicrosoftVisualC++6.0,WindosXP系统。三总体设计设计思想本停车场n个车位,

因此能够用数组表示,每辆车用一结构体表示,包括车牌号、颜色、车型、

车位号、停车时间和停车标志位(标志是否停车)。当车入库时,将更改信息,当车出库时,将信息写入car.dat中。再次进入该系统时,还用这个该数组,来接受car.dat数据的读入,便于用户以后的操作,防止停车信息的流失。另外,由于需要显示所有汽车的停车信息,因此我们又加了一个顾客结构体,一个顾客链表,当存车时,新建用户节点,并使用头插法,插于链表(便于取车时查到用户,补充完整用户的信息),填写用户的相关信息(车牌号,颜色,车型,车位号,车入库时刻)。当出库时,查找相应节点,补充完整用户信息,包括(用户留言,停车时间总计,花费)。当退出系统后,将已出库的汽车的车主信息,写入历史文件list.dat中,便于管理员的查询。将还未取走车的车主的信息存入临时文件temp.dat中,防止系统关闭后数据信息的丢失,车主取车时找不到车。同时,还要将成员信息写入临时文件user.dat;数据结构结构体Car,保存每个车位的停车信息。结构体Gustomer,保存每个客户的信息。结构体User,保存管理员信息。数组Cars,保存整个停车状况。数组user;链表CustList,保存所有客户的信息,包括车已取走,和车未取走的。程序模块(1)此停车场管理系统,主要分为以下若干模块:首先定义用来模拟停车的数组,用来保存顾客信息的链表,保存管理员信息的结构以及全局变量,然后编写主函数,在此主函数中实现对其它各个模块的调用。在主函数中首先调用option()函数,出现欢迎用户使用的界面,然后提示用户进入此停车场管理系统后,再出现一个供用户选择的主界面(包括顾客界面和停车场管理员管理界面)。当用户选择顾客界面时,跳入到顾客界面,再次界面,用户能够选择存车、取车及返回主页面。在用户的选择过程中,程序又分别存车,取车函数调用以及退出程序这三个函数模块。其中,当存车时,调用了显示空闲车位状态的信息函数,并调用了保存car.dat的函数;当取车时,调用显示本次停车情况以及消费金额的函数,并调用了保存car.dat的函数。建立user.dat存放管理人员的信息。最后,在主界面选择”退出”,保存历史文件list.dat和临时文件temp.dat。当用户选择车管系统时,调用管理员身份验证函数,从而跳入车管界面,然后相应的功能函数,实现查询所有停车信息。(2)各模块之间的调用关系以及算法设计下图是个模块之间的调用关系:欢迎页面退出停车场管理员界面显示凭据客户留言返回主页输入车牌号退出退出显示车位,客户选择车牌有效输入车牌号退出返回主页存车界面取车界面客户界面进入主页面否是满欢迎页面退出停车场管理员界面显示凭据客户留言返回主页输入车牌号退出退出显示车位,客户选择车牌有效输入车牌号退出返回主页存车界面取车界面客户界面进入主页面否是满初始停车场车辆信息输入管理员信息初始停车场车辆信息输入管理员信息显示管理员信息注:注:在取、存操作后,会自动保存信息到car.dat中。在每次退出系统时,会保存list.dat和temp.dat。(3)函数设计intUsertestAdd();voidSaveUsers(Userusers[6]);voidloa(Userusers[6]);voidFourUserIn(Userusers[6]);voidLoad(Carcars[6]);voidShowusers(Userusers[6]);voidloafile(Userusers[6],charname[10],charid[10],charpassword[10], intqingjia,intempty);voidLoadfile(Carcars[6],charlicense[10],charpchexing[10],charpcolor[2],intpnumber,intptime,intempty);voidFourCarIn(CarCars[6]);voidEnterpark(Carcars[6]);voidShowcars(Carcars[6]);voidSavecars(Carcars[6]);boolIsEmpty(Carcars[6]);voidPrint(charlicense[10],charpchexing[10],charpcolor[2],intpnumber,intptime,float&cost);voidLeavepark(Carcars[6],charlicense[],charpchexing[],charpcolor[],int&pnumber,int&ptime,float&cost,charnote[100]);voidCarOutMenu(charlicense[],charpchexing[],charpcolor[],int&pnumber,int&ptime,float&cost,charnote[100]);voidManage(Carcars[6]);voidInitCustList(CustList*&cl);voidCreateCustList(CustList*&cl,char*license,char*pchexing,char*pcolor);voidGetDate(chartmp[64]);voidSearchCust(CustList*&cl,char*license,char*pchexing,char*pcolor,floatcost,intpcount);voidCustomer(Carcars[6]);voidCustomerNote(charnote[100]);voidEachGuideInfor(Carc);四详细设计实现概要设计中定义的所有数据类型,对主要操作写出实现算法,对主程序和其它模块写出算法,写出函数的调用关系。数据类型结构体Car,保存每个车位的停车信息。structCar{charlicense[8];intpnumber;charpcolor[2];charpchexing[10];intptime;intempty;//标志位,有车为1,无车为0};structCustomer{ charlicense[10];//车牌号 charpchexing[10];//车的型号charpcolor[2];//车的颜色 chardate[64];//停车的时刻 intptimecount;//本次停车总时间 floatcost; charnote[100];//顾客留言 Customer*next;};structUser{ charid[10];//编号 charname[10];//姓名 charpassword[10];//留言 intqingjia; intempty;//标志位,有车为1,无车为0};数组Cars,保存整个停车状况。数组User,保存整个管理人员的信息。CarCars[PNUMBER];链表,保存所有客户的信息,包括车已取走,和车未取走的。typedefstructSnodeCustList;主要操作存车voidEnterpark(Carcars[6]){cout<<"inputyourlicense,chexing,color"<<endl;charlicen[10],pche[10],pcolo[2];cin>>licen>>pcolo>>pche;while(!licen){cout<<"inputyourlicense,chexing,color"<<endl;cin>>licen>>pcolo>>pche;}//判断车库是否已经满了inti;for(i=0;i<6;i++){if(cars[i].empty==1){cars[i].ptime+=5;}else{cars[i].pnumber=i+1;cars[i].ptime=5;cars[i].empty=1;strcpy(cars[i].license,licen);return;//如果使用break,则只能跳出单层循环,}}取车voidLeavepark(Carcars[FLOOR][PNUMBER],charlicense[],int&floor,int&pnumber,int&ptime,charnote[100]){//判断车位是否已空if(IsEmpty(cars)==1){cout<<"停车场已没有车停放!请确定您是否停车。"<<endl;return;}//查找车位intsign=1;//标志位,车库有该车为1,没有赋值为零,初始值为0inti,j;while(sign){for(i=0;i<FLOOR;i++){for(j=0;j<PNUMBER;j++){if(strcmp(cars[i][j].license,license)==0){sign=0;floor=i;pnumber=j;ptime=cars[i][j].ptime;}}}if(sign){cout<<"您刚才输入的车牌号不存在!"<<endl;cout<<"请重新输入:";cin>>license;}}if(sign==0)cout<<"车已找到,请稍等。。。"<<endl;strcpy(note,"");floor+=1;pnumber+=1;//system("cls");for(i=0;i<;i++);cars[floor-1][pnumber-1].floor=0;cars[floor-1][pnumber-1].pnumber=0;cars[floor-1][pnumber-1].ptime=0;cars[floor-1][pnumber-1].empty=0;strcpy(cars[floor-1][pnumber-1].license,"");}3)添加管理员的信息到User.txt中voidSaveUsers(Userusers[6]){FILE*fp=fopen("user.txt","wb");if(fp==NULL){cout<<"Cannotopenthisfile"<<endl;return;}Useruser;intj=0;while(j<6){if(users[j].empty==1){strcpy(,users[j].name);strcpy(user.id,users[j].id);strcpy(user.password,users[j].password);user.qingjia=users[j].qingjia;fwrite(&user,sizeof(user),1,fp);}j++;}fclose(fp);}4)登录界面intUsertestAdd(){//simple登陆验证和注册用户功能UserUserArr[10]={"","神1",""};//默认用户intcount=0;//统计输入用户名和密码错误次数inti=0;//遍历变量或找到用户的IDintk=1;//表示已存在的用户数while(1){intn=0;//标识是否匹配,若匹配,则退出外循环cout<<"请输入您的管理账号"<<endl;charid[10];cin>>id;cout<<"请输入密码"<<endl;charpassword[10];cin>>password;for(i=0;i<10;i++){if(!strcmp(UserArr[i].id,id)&&!strcmp(UserArr[i].password,password)){n=1;break;}}if(n){break;}i=0;count++;cout<<"密码或账号错误,";if(count==2||k==2){cout<<"您今天已累计输错"<<count<<"次-";cout<<"您是否要注册用户?(否则您将自动退出系统)"<<endl;cout<<endl;cout<<"输入数字1表示同意注册,其它则表示不同意条款"<<endl;inttip=0;cin>>tip;if(tip==1){if(k==2){cout<<"很遗憾,系统管理员用户总数达到上限,无法注册,若需注册,请联系管理员"<<endl;return0;}else{cout<<"请输入要注册账号"<<endl;charid[10];cin>>id;strcpy(UserArr[k+1].id,id);cout<<"请输入您的姓名"<<endl;charname[10];cin>>name;strcpy(UserArr[k+1].name,name);cout<<"请输入您的密码"<<endl;charpassword[10];cin>>password;strcpy(UserArr[k+1].password,password);cout<<"注册成功,系统正在为您跳转到登陆界面"<<endl;intj=0;while(j<){j++;}cout<<endl;++k;}}elsereturn0;}}cout<<endl;cout<<"*******************************************"<<endl;cout<<"欢迎进"<<UserArr[i].name<<"入停车场后台管理系统"<<endl;cout<<"*******************************************"<<endl;cout<<endl;return1;}5)顾客界面voidCustomer(Carcars[6]){cout<<"**************停车场****************"<<endl;while(1){cout<<"1存车"<<endl;cout<<"2取车"<<endl;cout<<"3返回上一级"<<endl;cout<<"请选择:";inti;chara;cin>>i;if(i<1||i>3){cout<<"您的操作非法!!!"<<endl;continue;}if(i==1||i==2){switch(i){case1:system("cls");cout<<"**************停车场****************"<<endl;Enterpark(cars);Savecars(cars);cout<<"退出?(Y:是,N:不)"<<endl;cout<<"请输入:";cin>>a;Brea;case2:{system("cls");cout<<"**************停车场****************"<<endl;intpnumber,ptime;intpcount=0;floatcost;charnote[100];cout<<"请输入您的车牌号:";charlicen[10],pche[10],pcolo[2];cin>>licen>>pche>>pcolo;Leavepark(cars,licen,pche,pcolo,pnumber,ptime,cost,note);CarOutMenu(licen,pche,pcolo,pnumber,ptime,cost,note);system("cls");//SearchCust(cl,licen,cost,pcount);Savecars(cars);break;}}if(a=='Y'){system("cls");break;}}else{system("cls");break;}}}6)后台程序voidManage(Carcars[6]){cout<<"Welcome!"<<endl;while(1){cout<<"1初始停车场"<<endl;cout<<"2显示所有车辆信息"<<endl;cout<<"3输入管理员信息"<<endl;cout<<"4显示管理员信息"<<endl;cout<<"5退出"<<endl;cout<<"请选择:";inti;chara;cin>>i;if(i<1||i>4){cout<<"您的操作非法!!!"<<endl;continue;}if(i==1||i==2||i==3||i==4){switch(i){case1:{ system("cls");FourCarIn(cars);cout<<"退出?(Y:是,N:不)"<<endl;cout<<"请输入:";cin>>a;break;}case2:{system("cls");Showcars(cars);break;}case3: {system("cls");FourUserIn(users);break;} case4: { system("cls"); Showusers(users); break; } } if(a=='Y') { system("cls"); break; } } else { system("cls"); break; } }}7)主函数intmain(){UsertestAdd();Carcars[6]; intj; for(j=0;j<6;j++) { cars[j].pnumber=0; cars[j].ptime=0; cars[j].empty=0; strcpy(cars[j].license,""); } //CustList*cl; //InitCustList(cl); Load(cars); while(1) { cout<<"**************停车场****************"<<endl; cout<<"1客户界面"<<endl; cout<<"2车管界面"<<endl; cout<<"3退出"<<endl; cout<<"请选择:"; inti; cin>>i; if(i<1||i>3) { cout<<"您的操作非法!!!"<<endl; continue; } system("cls"); switch(i) { case1:Customer(cars); break; case2:Manage(cars); break; case3:exit(-1); } }}五系统测试(1)登陆界面(2)客户界面存车取车(5)车管界面六总结这次经过课程设计首先加深啦对《对C++程序设计》这一课程所学内容进一步理解和巩固,特别是对顺序进栈以及链式队列的结构还有保存程序到文件着几块,一次停车场系统的设计开发主要用的就是这几种,在进行系统开发的准备阶段,也就是进行需求分析阶段,对系统功能进行分析,并设计合理的模块化结构,提高了对问题分析和设计的能力。在进行系统开发的阶段能运用合理的控制流程编写清晰高效的程序,也训练了C++语言程序的调试能力,能将一个小型各级组织系统联调经过,基本上能够完成每一项功能。汽车进入停车场的信息、离开停车场的信息以及通道上的信息都能够在程序上一一实现。可是,该程序也有不足的地方,就是管理员账号无法修改登录密码还有一些兼容性不是很好,不过为了简便代码,因此未实现这一功能。同时我觉得这一系统也一点可改进的方面在于还应该增加时间的判断功能,即停车场内有可能有车辆停放时间超过一天。总之,在这次对于停车场管理系统的课程设计中。我的收获还是挺多的,在系统开发中,使得我将计算机课程所学知识与实际问题很好的相联接在了一起。七参考文献[1]数据结构理论与实践杨永斌主编天津科学技术出版社[2]VisualC++课程设计与系统开发案例伍俊良编著清华大学出版社[3]C++程序设计谭浩强编著清华大学出版社[4]求实科技.数据库通用模块及典型系统开发[M].人民邮电出版社,.[5]陈刚.CSS标准网页布局开发指南[M].清华大学出版社,.[6]尹堃.浅谈ASP.NET技术的应用[J].硅谷动力,,(07).[7]蔡义忠.在ASP.NET应用开发中验证码的设计[J].黄冈职业技术学院学报,,(01).[8]徐安凤,黄河涛.基于ASP.NET2.0的文件上传研究[J].福建电脑,,(03).[9]胡晓庆.多层架构在WEB程序设计中的应用[J].兵工自动化,,(03).[10]廖作斌,徐智.基于ASP.NET技术的数据库访问通用类设计[J].福建电脑,,(11).[11]程宴,徐征.ASP.NET的网站新闻管理系统的设计与开发[J].舰船电子工程,,(08).附录:#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib>#include<ctime>#definePNUMBER6usingnamespacestd;structCar{ charlicense[10]; charpchexing[10]; charpcolor[2]; intpnumber; intptime; intempty;//标志位,有车为1,无车为0};//////////////////////////////////////////////顾客信息节点structCustomer{ charlicense[10];//车牌号 charpchexing[10];//车的型号charpcolor[2];//车的颜色 chardate[64];//停车的时刻 intptimecount;//本次停车总时间 floatcost; charnote[100];//顾客留言 Customer*next;};//顾客信息链表typedefCustomerCustList;//管理员structUser{ charid[10];//编号 charname[10];//姓名 charpassword[10];//留言 intqingjia; intempty;//标志位,有车为1,无车为0};Userusers[6];intUsertestAdd();voidSaveUsers(Userusers[6]);voidloa(Userusers[6]);voidFourUserIn(Userusers[6]);voidLoad(Carcars[6]);voidShowusers(Userusers[6]);voidloafile(Userusers[6],charname[10],charid[10],charpassword[10], intqingjia,intempty);voidLoadfile(Carcars[6],charlicense[10],charpchexing[10],charpcolor[2],intpnumber,intptime,intempty);voidFourCarIn(CarCars[6]);voidEnterpark(Carcars[6]);voidShowcars(Carcars[6]);voidSavecars(Carcars[6]);boolIsEmpty(Carcars[6]);voidPrint(charlicense[10],charpchexing[10],charpcolor[2],intpnumber,intptime,float&cost);voidLeavepark(Carcars[6],charlicense[],charpchexing[],charpcolor[],int&pnumber,int&ptime,float&cost,charnote[100]);voidCarOutMenu(charlicense[],charpchexing[],charpcolor[],int&pnumber,int&ptime,float&cost,charnote[100]);voidManage(Carcars[6]);voidInitCustList(CustList*&cl);voidCreateCustList(CustList*&cl,char*license,char*pchexing,char*pcolor);voidGetDate(chartmp[64]);voidSearchCust(CustList*&cl,char*license,char*pchexing,char*pcolor,floatcost,intpcount);voidCustomer(Carcars[6]);voidCustomerNote(charnote[100]);voidEachGuideInfor(Carc);//游客个人信息的自我查询voidEachGuideInfor(Carc){ cout.setf(ios::left); cout.width(10); cout<<"车牌号"; cout.width(8); cout<<"颜色"; cout.width(8); cout<<"车型"; cout.width(8); cout<<"车位号"; cout.width(8); cout<<"停车开始时间"<<endl; cout.setf(ios::left); cout.width(10); cout<<c.license; cout.width(2); cout<<c.pcolor; cout.width(10); cout<<c.pchexing; cout.width(8); cout<<c.pnumber; cout.width(8); cout<<c.ptime<<endl;}//顾客留言voidCustomerNote(charnote[100]){ cout<<"请留言:"; cin>>note;}//存车voidEnterpark(Carcars[6]){ charlicen[10],pche[10],pcolo[2]; cout<<"请输入你的车牌号:"; cin>>licen; cout<<"请输入你的车型:"; cin>>pche; cout<<"请输入你的车的颜色:"; cin>>pcolo; while(!licen) { cout<<"请输入你的车牌号:"; cin>>licen; cout<<"请输入你的车型:"; cin>>pche; cout<<"请输入你的车的颜色:"; cin>>pcolo; } //判断车库是否已经满了 inti; for(i=0;i<6;i++) { if(cars[i].empty==1) { cars[i].ptime+=5; } else { cars[i].pnumber=i+1; cars[i].ptime=5; cars[i].empty=1; strcpy(cars[i].license,licen); return;//如果使用break,则只能跳出单层循环, } } }//取车voidLeavepark(Carcars[6],charlicense[],charpchexing[10],charpcolor[2],int&pnumber,int&ptime,float&cost,charnote[100]){ //判断车位是否已空 if(IsEmpty(cars)==1) { cout<<"停车场已没有车停放!请确定您是否停车。"<<endl; return; } //查找车位 intsign=1;//标志位,车库有该车为1,没有赋值为零,初始值为0 intj; while(sign) { for(j=0;j<6;j++) { if(strcmp(cars[j].license,license)==0) { sign=0; pnumber=j; ptime=cars[j].ptime; } } if(sign) { cout<<"您刚才输入的车牌号不存在!"<<endl; cout<<"请重新输入:"; cin>>license; } } if(sign==0) cout<<"车已找到,请稍等。。。"<<endl; pnumber+=1; //system("cls"); //延时 for(j=0;j<;j++); //车出库,将车位空出 cars[pnumber-1].pnumber=0; cars[pnumber-1].ptime=0; cars[pnumber-1].empty=0; strcpy(cars[pnumber-1].license,""); //由于floor,pnumber与实际的二位数组有区别,加1}//取车的菜单项voidCarOutMenu(charlicense[],charpchexing[10],charpcolor[2],int&pnumber,int&ptime,float&cost,charnote[100]){ cout<<"1输出凭据"<<endl; cout<<"2留言"<<endl; cout<<"3直接退出"<<endl; while(1) { cout<<"请选择:"; inti; cin>>i; if(i<1||i>3) { cout<<"您的操作非法!!!"<<endl; continue; } switch(i) { case1: cout<<"--------现有汽车停车信息--------"<<endl; Print(license,pchexing,pcolor,pnumber,ptime,cost);break; case2:CustomerNote(note);break; case3:break; } if(i==1||i==2)continue; elsebreak; }}//得到当前时间voidGetDate(chartmp[64]){ time_tt=time(0);strftime(tmp,sizeof(tmp),"%Y/%m/%d%X%A",localtime(&t));}boolIsEmpty(Carcars[6]){intj; for(j=1;j<6;j++) if(cars[j].empty==1)returnfalse;returntrue;}//逐条添加记录到car.dat中voidSavecars(Carcars[6]){ FILE*fp=fopen("car.txt","wb"); if(fp==NULL) { cout<<"Cannotopenthisfile"<<endl; return; } //tofile Carcar; intj=0; while(j<6) { if(cars[j].empty==1) { strcpy(car.license,cars[j].license); car.pnumber=cars[j].pnumber; car.ptime=cars[j].ptime; car.empty=cars[j].empty; // fwrite(&cars,sizeof(car),1,fp);//如果写成这样,每次都从car[0][0]地址开始写入,回报原来的内容覆盖掉,加深了我对fwrite()的理解 fwrite(&car,sizeof(car),1,fp); } j++; } fclose(fp);}voidSaveUsers(Userusers[6]){ FILE*fp=fopen("user.txt","wb"); if(fp==NULL) { cout<<"Cannotopenthisfile"<<endl; return; } //tofile Useruser; intj=0; while(j<6) { if(users[j].empty==1) { strcpy(,users[j].name); strcpy(user.id,users[j].id); strcpy(user.password,users[j].password); user.qingjia=users[j].qingjia; // fwrite(&cars,sizeof(car),1,fp);//如果写成这样,每次都从car[0][0]地址开始写入,回报原来的内容覆盖掉,加深了我对fwrite()的理解 fwrite(&user,sizeof(user),1,fp); } j++; } fclose(fp);}voidLoad(Carcars[6]){ FILE*fp=fopen("car.txt","rb"); if(fp==NULL) { cout<<"cannotopenthisfile"<<endl; return; } Carcar; intn; while(!feof(fp)) { //readonecarinformation n=fread(&car,sizeof(car),1,fp); if(n!=1) break; // cout<<car.license<<""<<car.flo<<""<<car.pnumber<<""<<car.ptime<<endl; Loadfile(cars,car.license,car.pchexing,car.pcolor,car.pnumber,car.ptime,car.empty); } fclose(fp);}voidLoa(Userusers[6]){ FILE*fp=fopen("user.txt","rb"); if(fp==NULL) { cout<<"cannotopenthisfile"<<endl; return; }Useruser; intn; while(!feof(fp)) { //readonecarinformation n=fwrite(&user,sizeof(user),1,fp); if(n!=1) break;loafile(users,user.id,,user.password,user.qingjia,user.empty); // cout<<car.license<<""<<car.flo<<""<<car.pnumber<<""<<car.ptime<<endl; } fclose(fp);}//输出 收费后个人凭据voidPrint(charlicense[],charpchexing[10],charpcolor[2],intpnumber,intptime,float&cost){ //计算费用 cost=ptime*float(0.2); //输出 cout.setf(ios::left); cout.width(10); cout<<"车牌号"; cout.width(10); cout<<"车型"; cout.width(2); cout<<"车的颜色"; cout.width(8); cout<<"车位号"; cout.width(8); cout<<"消费"<<endl; cout.setf(ios::left); cout.width(10); cout<<license; cout.width(10); cout<<pchexing; cout.width(10); cout<<pcolor; cout.width(10); cout<<pnumber; cout.width(10); cout<<cost<<endl;}voidFourUserIn(Userusers[6]){ Usera; inti; cout<<"请输入四位管理人员的信息:"<<endl; for(i=0;i<4;i++) {cout<<"第"<<i+1<<"管理员姓名:"; cin>>; cout<<"第"<<i+1<<"管理编号:"; cin>>a.id; cout<<"第"<<i+1<<"密码:"; cin>>a.password; cout<<"第"<<i+1<<"请假次数:"; cin>>a.qingjia; a.empty=1;voidloafile(Userusers[6],charname[10],charid[10],charpassword[10], intqingjia,intempty); } SaveUsers(users);}voidFourCarIn(Carcars[6]){ //4车进库 Carc; inti; cout<<"请输入四辆车的信息:"<<endl; for(i=0;i<4;i++) { cout<<"第"<<i+1<<"辆车的车牌号:\n"; cin>>c.license; cout<<"第"<<i+1<<"辆车的车型:\n"; cin>>c.pchexing; cout<<"第"<<i+1<<"辆车的车色:\n"; cin>>c.pcolor; cout<<"第"<<i+1<<"辆车的车位号:\n"; cin>>c.pnumber; cout<<"第"<<i+1<<"辆车的停车时间:\n"; cin>>c.ptime; c.empty=1;voidLoadfile(Carcars[6],charlicense[10],charpchexing[10],charpcolor[2],intpnumber,intptime,intempty); } //写入文件car.dat Savecars(cars);}//记录一个停车位的状态voidLoadfile(Carcars[6],charlicense[10],charpchexing[10],charpcolor[2],intpnumber,intptime,intempty){ if(!license) return; strcpy(cars[pnumber-1].license,license); cars[pnumber-1].pnumber=pnumber; cars[pnumber-1].ptime=ptime; cars[pnumber-1].empty=empty;}voidloafile(Userusers[6],charname[10],charid[10],charpassword[10], intqingjia,intempty){ strcpy(users[qingjia-1].name,name); strcpy(users[qingjia-1].id,id); strcpy(users[qingjia-1].password,password); users[qingjia-1].empty=empty;}voidShowcars(Carcars[6]){ cout<<"--------现有汽车停车信息--------"<<endl; intj; cout.setf(ios::left); cout.width(10); cout<<"车牌号"; cout.width(10); cout<<"车型"; cout.width(2); cout<<"车色"; cout.width(8); cout<<"车位号"; cout.width(8); cout<<"停车时间"<<endl; for(j=0;j<6;j++) { if(cars[j].empty==1) { cout.setf(ios::left); cout.width(10); cout<<cars[j].license; cout.width(10); cout<<cars[j].pchexing; cout.width(2); cout<<cars[j].pcolor; cout.width(8); cout<<cars[j].pnumber; cout.width(8); cout<<cars[j].ptime<<endl; }}}voidShowusers(Userusers[6]){ cout<<"--------现有管理员信息--------"<<endl; intj; cout.setf(ios::left); cout.width(10); cout<<"姓名"; cout.width(10); cout<<"管理号"; cout.width(2); cout<<"密码"; cout.width(8); cout<<"请假次数"; cout<<endl; for(j=0;j<6;j++) { if(users[j].empty==1) { cout.setf(ios::left); cout.width(10); cout<<users[j].name; cout.width(10); cout<<users[j].id; cout.width(2); cout<<users[j].password; cout.width(8); cout<<users[j].qingjia; cout<<endl; }}}intUsertestAdd(){//simple登陆验证和注册用户功能 UserUserArr[10]={"","神1",""};//默认用户intcount=0;//统计输入用户名和密码错误次数inti=0;//遍历变量或找到用户的ID intk=1;//表示已存在的用户数 while(1) { intn=0;//标识是否匹配,若匹配,则退出外循环 cout<<"请输入您的管理账号"<<endl; charid[10]; cin>>id; cout<<"请输入密码"<<endl; charpassword[10]; cin>>password; for(i=0;i<10;i++) { if(!strcmp(UserArr[i].id,id)&&!strcmp(UserArr[i].password,password)) { n=1; break; } } if(n) { break; } i=0; count++; cout<<"密码或账号错误,"; if(count==2||k==2) { cout<<"您今天已累计输错"<<count<<"次-"; cout<<"您是否要注册用户?(否则您将自动退出系统)"<<endl; cout<<endl; cout<<"输入数字1表示同意注册,其它则表示不同意条款"<<endl; inttip=0; cin>>tip; if(tip==1) { if(k==2) { cout<<"很遗憾,系统管理员用户总数达到上限,无法注册,若需注册,请联系管理员"<<endl; return0; } else{ cout<<"请输入要注册账号"<<endl; charid[10]; cin>>id; strcpy(UserArr[k+1].id,id); cout<<"请输入您的姓名"<<endl; charname[10]; cin>>name; strcpy(UserArr[k+1].name,name); cout<<"请输入您的密码"<<endl; charpassword[10]; cin>>password; strcpy(UserArr[k+1].password,password); cout<<"注册成功,系统正在为您跳转到登陆界面"<<endl; intj=0; while(j<){j++;} cout<<endl; ++k; } }elsereturn0; } } cout<<endl; cout<<"*******************************************"<<endl; cout<<"欢迎进"<<UserArr[i].name<<"入停车场后台管理系统"<<endl; cout<<"*******************************************"<<endl;cout<<endl; return1;}//顾客界面voidCustomer(Carcars[6]){ cout<<"************

温馨提示

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

评论

0/150

提交评论