#include <iostream>#include <iomanip>#include<conio.h>#include <string>#include <fstream>//输入/输出文件流类using namespace std;const int Maxr=100;//最多的客户const int Maxc=100;//最多的汽车const int Maxcar=5;//每位客户最多租五辆汽车class biaozhi{public:int tag;//删除标记 1:已删 0:未删int no;//编号};//客户类,实现对客户的信息的描述class Customer :public biaozhi {public:char name[20];//客户姓名int borcar[Maxcar];//所租汽车Customer() {}//构造函数char *getname(){return name;}//获取姓名int gettag(){return tag;}//获取删除标记int getno(){return no;}//获取客户编号void setname(char na[]){strcpy(name,na);}//设置姓名void delcar(){tag=1;}//设置删除标记void addcustomer(int n,char *na);//增加客户void borrowcar(int carid);//出租操作int retcar(int carid);//归还操作void disp();//输出客户信息virtual void print();//输出原客户信息};void Customer::addcustomer(int n,char *na) {tag=0;no=n;strcpy(name,na);for (int i=0;i<Maxcar;i++){borcar[i]=0;}}//增加客户void Customer::borrowcar(int carid) {for (int i=0;i<Maxcar;i++){if (borcar[i]==0){borcar[i]=carid;return;}}}//出租操作int Customer::retcar(int carid){for(int i=0;i<Maxcar;i++){if(borcar[i]==carid){borcar[i]=0;return 1;}elsecontinue;}return 0;}//归还操作void Customer::disp() {cout << setw(5);cout<< no;cout<< setw(10) ;cout<< name ;cout<< " 出租汽车编号:[";for (int i=0;i<Maxcar;i++){if (borcar[i]!=0){cout <<borcar[i] <<"|";}}cout<<"]"<<endl;}//输出客户信息void Customer::print() {cout <<"原客户编号:";cout<<setw(5);cout<< no;cout<<"\t原客户姓名:";cout<< setw(10);cout<< name;cout<< " \t租租汽车编号:[";for (int i=0;i<Maxcar;i++){if (borcar[i]!=0){cout <<borcar[i] <<"|";}}cout<<"]"<<endl;}//输出原客户信息//客户类库,实现建立客户的个人资料class CDatabase{public:int top;//客户记录指针Customer custom[Maxc];//客户记录CDatabase();//构造函数,将customer.txt读到custom[]中void clear(){top=-1;}//删除所有客户信息int addcustomer(int n,char *na);//增添客户信息Customer *query(int customerid){for (int i=0;i<=top;i++){if(custom[i].getno()==customerid&&custom[i].gettag()==0){return &custom[i];}}return NULL;}//按编号查找void disp();//输出所有客户信息void print(int customerid){for (int i=0;i<=top;i++){if(custom[i].getno()==customerid&&custom[i].gettag()==0){custom[i].print();}}}//输出客户原有信息int customernum();//得到客户编号void customerdata();//客户库管理~CDatabase();// 析构函数,将custom[]写入customer.txt文件中};CDatabase::CDatabase(){Customer s;top=-1;fstream file("customer.txt",ios::in);while (1){file.read((char *)&s,sizeof(s));if (!file) break;top++;custom[top]=s;}file.close();}//构造函数,将customer.txt读到custom[]中CDatabase::~CDatabase(){fstream file("customer.txt",ios::out);for (int i=0;i<=top;i++)if(custom[i].gettag()==0)file.write((char *)&custom[i],sizeof(custom[i]));elsefile.close();ofstream f("c:\\kehu.txt");for (int j=0;j<=top;j++){if(custom[j].gettag()==0)f<<"编号"<<custom[j].no;f<<"\t\t\t";f<<"姓名";f<<custom[j].name;f<<"\t\t\t";f<<"所租汽车编号(没有就写0)";f<<custom[j].borcar[j];f<<endl;}}// 析构函数,将custom[]写入customer.txt文件中int CDatabase::addcustomer(int n,char *na) {Customer *p=query(n);if (p==NULL){top++;custom[top].addcustomer(n,na);cout<<"客户添加成功"<<endl;return 1;}return 0;}//增添客户信息void CDatabase::disp(){for (int i=0;i<=top;i++){custom[i].disp();}}//输出所有客户信息int CDatabase::customernum(){return top;}//客户库管理void CDatabase::customerdata(){char choice;char cname[20];//客户姓名int customerid;Customer *r;do{cout <<"\n\n\n\t\t\t欢迎进入汽车管理界面 "<<endl<<endl;cout<<"\t\t----------------------------"<<endl;cout<<"\t\t| 1增加客户 |"<<endl;cout<<"\t\t| 2更改客户 |"<<endl;cout<<"\t\t| 3删除客户 |"<<endl;cout<<"\t\t| 4查找客户 |"<<endl;cout<<"\t\t| 5查看全部 |"<<endl;cout<<"\t\t| 6删除全部 |"<<endl;cout<<"\t\t| 0返回上一层 |"<<endl;cout<<"\t\t----------------------------"<<endl;cin >> choice;switch (choice){case '1':cout << "新增\n输入客户编号:";cin >> customerid;try{if(customerid<=0)throw 1;}catch(...){cout<<"输入有误,请重新输入";break;}cout << "输入客户姓名:";cin >> cname;addcustomer (customerid,cname);break;case '2':cout << "更改\n输入客户编号:";cin >> customerid;try{if(customerid<=0)throw 1;}catch(...){cout<<"输入有误,请重新输入";break;}r=query(customerid);if (r==NULL){cout << " 该客户不存在 "<<endl;break;}print(customerid);cout<<"输入新的客户编号:";cin>>customerid;try{if(customerid<=0)throw 1;}catch(...){cout<<"输入有误,请重新输入";break;}cout<<"输入新的客户姓名:";cin >> cname;r->addcustomer(customerid,cname);cout<<"修改成功!"<<endl;break;case '3':cout << " 删除\n输入客户编号:";cin >> customerid;try{if(customerid<=0)throw 1;}catch(...){cout<<"输入有误,请重新输入";break;}r=query(customerid);if (r==NULL){cout <<" 该客户不存在" << endl;break;}r->delcar();break;case '4':cout << "查找\n读入客户编号:";cin >> customerid;try{if(customerid<=0)throw 1;}catch(...){cout<<"输入有误,请重新输入";break;}r=query(customerid);if (r==NULL){cout <<"该客户不存在"<< endl;break;}r->disp();break;case '5':cout<<"显示:"<<endl;disp();break;case '6':clear();cout<<"已删除!"<<endl;break;default:if (choice!='0') cout<<"输入错误,请从新输入:";break;}}while (choice!='0');}//汽车类,实现对汽车的描述,汽车的编号,名称,租出,归还等class Car:public biaozhi{public:char name[20];//名称int onshelf;//是否在车库 1:在车库 0:已租Car(){}char *getname() { return name; }//获取姓名int getno(){ return no; }//获取汽车编号int gettag(){ return tag; }//获取删除标记void setname(char na[]){strcpy(name,na);}//设置名称void delcar(){ tag=1;}//删除汽车void addcar(int n,char *na){tag=0;no=n;strcpy(name,na);onshelf=1;}//增加汽车int borrowcar(){if (onshelf==1){onshelf=0;return 1;}return 0;}//出租操作void retcar(){onshelf=1;}//归还操作void print(){cout <<"汽车原编号:"<< setw(6) << no <<"\t汽车原名称:" <<setw(18) << name <<"\t"<< setw(10) <<(onshelf==1? "在车库":"已租") <<endl;}//输出汽车void disp(){cout << setw(6) << no << setw(18) << name << setw(10)<<(onshelf==1? "在车库":"已租") <<endl;}//显示void disp(int k){cout<<"编号为"<<no<<endl;}};template<class T>class biaozhiq{public:T abaso;};//汽车库类,实现对汽车的管理,查找,删除等class CarDatabase{public:int top;//汽车记录指针Car che[Maxc];//汽车记录CarDatabase(){Car b;top=-1;fstream file("che.txt",ios::in);while (1){file.read((char *)&b,sizeof(b));if (!file)break;top++;che[top]=b;}file.close();}//构造函数,将che.txt读到che[]中void clear()//全删{top=-1;}int addcar(int n,char *na);//增加汽车Car *query(int carid){for (int i=0;i<=top;i++)if (che[i].getno()==carid &&che[i].gettag()==0){return &che[i];}return NULL;}//查找汽车void cardata();//汽车库管理virtual void print(int n){for(int i=0;i<=top;i++)if(che[i].getno()==n)che[i].print();}//输出原汽车void disp(){for (int i=0;i<=top;i++)if (che[i].gettag()==0)che[i].disp();}//显示~CarDatabase();//析构函数,将che[]写到che.txt文件中};int CarDatabase::addcar(int n,char *na){Car *p=query(n);if (NULL==p){top++;che[top].addcar(n,na);return 1;}return 0;}//增加汽车CarDatabase::~CarDatabase(){fstream file("che.txt",ios::out);for (int i=0;i<=top;i++)if (che[i].gettag()==0)file.write((char *)&che[i],sizeof(che[i]));file.close();ofstream f("c:\\qiche.txt");for (int j=0;j<=top;j++){if(che[j].gettag()==0)f<<"编号";f<<che[j].no;f<<"\t\t\t";f<<"汽车";f<<che[j].name;f<<"\t\t\t";if(che[j].onshelf==1)f<<"在车库"<<endl;elsef<<"已出租"<<endl;}}//析构函数,将che[]写到che.txt文件中//汽车管理void CarDatabase::cardata(){char choice;char cname[20];int carid;Car *b;do{cout <<"\n\n\n\t\t\t欢迎进入汽车管理界面 "<<endl<<endl;cout<<"\t\t----------------------------"<<endl;cout<<"\t\t| 1增加汽车 |"<<endl;cout<<"\t\t| 2更改汽车 |"<<endl;cout<<"\t\t| 3删除汽车 |"<<endl;cout<<"\t\t| 4查找汽车 |"<<endl;cout<<"\t\t| 5查看全部 |"<<endl;cout<<"\t\t| 6删除全部 |"<<endl;cout<<"\t\t| 0返回上一层 |"<<endl;cout<<"\t\t----------------------------"<<endl;cin >> choice;switch (choice){case '1':cout << "新增\n输入汽车编号:"<<endl;cin >> carid;try{if(carid<=0)throw 1;}catch(...){cout<<"输入有误,请重新输入";break;}cout << "输入汽车名称:"<<endl;cin >> cname;addcar(carid,cname);break;case '2':cout << "更改\n输入汽车编号:"<<endl;cin >> carid;try{if(carid<=0)throw 1;}catch(...){cout<<"输入有误,请重新输入";break;}b=query(carid);if (b==NULL){cout << " 该汽车不存在 ";cout<<endl;break;}print(carid);cout << "输入新的汽车编号:";cout<<endl;cin>>carid;try{if(carid<=0)throw 1;}catch(...){cout<<"输入有误,请重新输入";break;}cout << "输入新的汽车名称:"<<endl;cin >> cname;b->addcar(carid,cname);cout<<"修改成功!"<<endl;break;case '3':cout <<" 删除\n读入汽车编号:"<<endl; cin >> carid;try{if(carid<=0)throw 1;}catch(...){cout<<"输入有误,请重新输入";break;}b=query(carid);if (b==NULL){cout <<" 该汽车不存在" ;cout<< endl;break;}b->delcar();break;case '4':cout << " 查找\n读入汽车编号:";cout<<endl;cin >> carid;try{if(carid<=0)throw 1;}catch(...){cout<<"输入有误,请重新输入";break;}b=query(carid);if (b==NULL){cout <<" 该汽车不存在";cout<< endl;break;}b->disp();break;case '5':cout<<"显示:"<<endl;disp();break;case '6':clear();cout<<"已删除!"<<endl;break;default:if(choice!='0')cout<<"输入错误,请从新输入:";}}while (choice!='0');}void showmenu(){cout<<" ------------------*****-------------------------------*****------------------"<<endl;cout<<" 1.***** 出租汽车 *****"<<endl;cout<<" ------------------*****-------------------------------*****------------------"<<endl;cout<<" 2.***** 归还汽车 *****"<<endl;cout<<" ------------------*****-------------------------------*****------------------"<<endl;cout<<" 3.***** 汽车管理 *****"<<endl;cout<<" ------------------*****-------------------------------*****------------------"<<endl;cout<<" 4.***** 客户管理 *****"<<endl;cout<<" ------------------*****-------------------------------*****------------------"<<endl;cout<<" 0.***** 退出并保存 *****"<<endl;cout<<" ------------------*****-------------------------------*****------------------"<<endl; }void showtip(){cout<<"\n\t\t----------------操作完成!-----------------"<<endl;cout<<"\t\t----------------选择0-5继续------------------"<<endl;cout<<" ------------------*****-------------------------------*****------------------"<<endl;cout<<" 1.***** 出租汽车 *****"<<endl;cout<<" ------------------*****-------------------------------*****------------------"<<endl;cout<<" 2.***** 归还汽车 *****"<<endl;cout<<" ------------------*****-------------------------------*****------------------"<<endl;cout<<" 3.***** 汽车管理 *****"<<endl;cout<<" ------------------*****-------------------------------*****------------------"<<endl;cout<<" 4.***** 客户管理 *****"<<endl;cout<<" ------------------*****-------------------------------*****------------------"<<endl;cout<<" 0.***** 退出并保存 *****"<<endl;cout<<" ------------------*****-------------------------------*****------------------"<<endl; }//main() 函数的实现,程序的主界面的引导int main(){cout<<" "<<endl;cout<<" "<<endl;cout<<" "<<endl;cout<<" "<<endl;cout<<" "<<endl;cout<<" * * * * * * * * "<<endl;cout<<" * * * * * * * * "<<endl;cout<<" * * * * * * "<<endl;cout<<" * * * * "<<endl;cout<<" * * * * "<<endl;cout<<" * * 欢迎使用 * * "<<endl;cout<<" * * 汽车租赁 * * "<<endl;cout<<" * * 管理系统 * * "<<endl;cout<<" * * "<<endl;cout<<" welcome to the Car rental management system "<<endl;cout<<" "<<endl;cout<<" "<<endl;cout<<" "<<endl;cout<<" "<<endl;cout<<" "<<endl;cout<<" "<<endl;getch();//为了停顿一下,按任意键才继续往下运行system("cls");//系统清屏char k[20];int t=3;p3:cout<<"欢迎使用汽车租赁管理系统,请输入登陆密码(只可输入3次):";cout<<endl;cin>>k;//输入密码if(strcmp("111",k)==0)cout<<"密码正确"<<endl;else{cout<<"密码错误!剩余"<<--t<<"次。