汽车租借公司的管理系统-数据结构课程设计报告(共25页).doc
精选优质文档-倾情为你奉上算 法 与 数 据 结 构课 程 设 计 报 告请尊重我的劳动成果不要复制! 题 目: 汽车租借公司的管理 班 级: 学 号: 姓 名: 成 绩:2014年 1月 1日一、题目汽车租借公司的管理(1)问题描述设计数据结构及算法完成某个汽车租借公司日常工作的组织与管理。该管理系统的基本管理对象为汽车,每台汽车用一个license number进行唯一标识。每个汽车存在三种可能状态: 可以租借(available for rent) 已借(rented) 修理中(in repair) 其中在available队列中汽车应该依据汽车行驶过的路程进行排序,行驶路程最少的汽车排在最前面。在rented队列中的汽车应依据其预期返回时间进行排序,排在最前的应是预期最早返回的汽车。(2)课程设计目的应用线性数据结构存储信息,并能够应用上面的基本操作实现事务管理。(3)基本要求 用三个链表组织三种状态的汽车。 能够实现租借的日常事务:引入新车,租借,收费,修理等。 租借收费应根据汽车行驶的路程及借去的时间综合计算得出,路程收费标准如下: 低于100km收费20.00元 100km以外的路程每km收费0.15元 汽车根据行驶的路程定期进行维护。 还需实现辅助操作:汽车查询,打印全部信息,计算并打印收入、成本及收益。 管理系统应有完整地界面(最好是图形化界面)。(4) 实现提示主要集中在链表的基本操作上。二、设计思想1、问题分析该公司的所有车辆只有以下三种状态: 可以租借(available for rent) 已借(rented) 修理中(repairing) 一.每种状态的都有要能够实现车辆的添加、删除、显示的最最基本的功能,他们里面又都有多辆车需要统一管理,而这些车辆无疑都是属性相同的车辆,所以可以建立一个cars结构体,包含他们共同的属性。公司日常业务有添加新车,租借汽车,归还收费、修理汽车,修理完毕,配置信息,汽车查询,打印全部信息,计算收益。其所有功能如下: 1.添加新车,2.租借汽车,3.归还收费、4.修理汽车,5.修理完毕,6.配置信息,7.汽车查询,8.打印信息,9.计算收益,10.退出二.基本实现:采用的链式结构,即对链表的操作。另外有两个配置文件:1.data.dat:储存的信息有汽车编号、汽车状态(0表示未借出,1表示借出,2表示维修中)、已行驶的路程、预期归还的时间、借出的次数、该车的获得的收益。2.data.ini:每辆车的成本、每次修理费、油费/km、租费(100km以下)、租费(超过100km)。三.结构关系struct cars包含了一辆车的的基本信息: 1.汽车编号license_number(int); 2.汽车状态0-可以租借,1-已借出,2-修理中stutes(int); 3.汽车行驶过的路程car_runned(float); 4.汽车预期返回的时间return_time(int); 5.汽车修理的次数repaired_time(int); 6.汽车收入income(float); 7.next指针struct cars *next; 四.相关函数 1.读取data.ini配置信息的数据:void ReadDataIni(); 2.设置data.ini配置信息的数据:void setDataIni(); 3.将数据存档到data.dat中:void save_data(struct cars *carData);4.追加数据存档到data.dat中:void add_data(struct cars *carData);5.根据汽车所行驶的距离排序:struct cars *rank_Distance(struct cars *carDistance);6.根据预期返回时间排序:struct cars *rank_Time(struct cars *carTime);7.建立可以租借的链表:struct cars *create_available(void);8.建立已借出的链表:struct cars *create_rented(void);9.建立修理中的链表:struct cars *create_repairing(void);10.打印汽车的信息:void printThreeOfCars(struct cars *ThreeOfCar);11.计算链表数据个数:int calculateCars(struct cars *ThreeOfCar);12.删除链表中的汽车:void deleteThreeOfCar(struct cars *ThreeOfCar, int xuhao);13.插入到可以租借的车链表中:struct insertThreeOfCars(struct cars *ThreeOfCar,int LicenseNumber,int Stu,float CarRunned,int ReturnTime,int RepairedTime,float Ico);14.增加新车:void AddNewCar(struct cars *available,struct cars *rented,struct cars *repairing);15.出租汽车:void RentCar(struct cars *available,struct cars *rented, struct cars *repairing);16.归还收费:void ReturnCar(struct cars *available,struct cars *rented,struct cars *repairing);17.修理汽车:void RepairCar(struct cars *available,struct cars *rented,struct cars *repairing);18.查看修理状况:void BackCar(struct cars *available,struct cars *rented,struct cars *repairing);19.汽车查询:void research(struct cars *ThreeOfCar, int id);20.汽车查询结果:void ReasearchCar(struct cars *available,struct cars *rented,struct cars *repairing);21.打印所有车的信息:void PrintAllCar();22.计算收益:void Calculation(struct cars *ThreeOfCar);23.计算收益:void CalculateProfit();24.配置信息:void displaySeting();25.设置配置信息:void setInformation();三、软件结构图及流程图软件结构图即函数调用图(图中用五号宋体)如下图添加新车AddNewCar()创建3个链表主函数出租汽车RentCar()void RentCar归还收费ReutrnCar()修理汽车RepairCar()修理完毕BackCar()操作选择配置信息SetInformation()汽车查询ReasearchCar()打印全部PrintAllCar()计算收益CalculateProfit()退出开始建立三张链表(可借汽车、已借汽车、修理汽车)主菜单(选择操作)添加新车操作1租借汽车操作2归还收费操作3修理汽车操作4操作5修理完毕操作6配置信息操作7汽车查询打印全部操作8计算收益操作9退出操作0结束四、测试使用Visual C+ 6.0。其中,程序使用到的信息在data.dat和data.ini文件中。本程序运行后的界面如下图所示:主界面:1.添加新车2.租借汽车3.归还收费4.修理汽车5.修理完毕6.配置信息7.汽车查询8.打印全部9.计算收益10.退出五、源程序#include<iostream>using namespace std;#include<malloc.h>#include<stdlib.h>#include<vector>#define LEN sizeof(struct cars)struct carsint license_number;/汽车编号int stutes;/汽车状态0-可以租借,1-已借出,2-修理中float car_runned;/汽车行驶过的路程int return_time;/汽车预期返回的时间int repaired_time;/汽车修理的次数float income;/汽车收入struct cars *next;/next指针;struct cars *p1,*p2,*available,*rented,*repairing,*p,*g,*f;FILE *fp1, *fp2;/文件指针int n1 = 0, n2 = 0, n3 = 0, n4, n5;/将data.ini中的配置信息读出来储存在四个变量中float car_cost,repair_cost,oil_cost,rent_cost,rentkm_cost;struct cars *rank_Time(struct cars *carTime);struct cars *rank_Distance(struct cars *carDistance);/读取data.ini配置信息的数据void ReadDataIni() fp2 = fopen("data.ini","r");fscanf(fp2,"%f %f %f %f %f",&car_cost,&repair_cost,&oil_cost,&rent_cost,&rentkm_cost);fclose(fp2);/设置data.ini配置信息的数据void setDataIni()fp2 = fopen("data.ini","w"); /以写的模式打开文件fprintf(fp2,"%.2f %.2f %.2f %.2f %.2f %.2f",car_cost,repair_cost,oil_cost,rent_cost,rentkm_cost);fclose(fp2);cout<<"设置成功!"<<endl;/将数据存档到data.datvoid save_data(struct cars *carData)p = carData;fp1 = fopen("data.dat","w"); /以写的模式打开文件while(p!=NULL)fprintf(fp1,"%d %d %.2f %d %d %.2fn",p->license_number,p->stutes,p->car_runned,p->return_time,p->repaired_time,p->income);p = p->next;fclose(fp1);/追加数据存档到data.datvoid add_data(struct cars *carData)p = carData;fp1 = fopen("data.dat","a"); /以追加写入的模式打开文件while(p!=NULL)fprintf(fp1,"%d %d %.2f %d %d %.2fn",p->license_number,p->stutes,p->car_runned,p->return_time,p->repaired_time,p->income);p = p->next;fclose(fp1);/根据汽车所行驶的距离排序struct cars *rank_Distance(struct cars *carDistance)p=carDistance;vector<struct cars> sc(n1);struct cars t;int i = -1,j;while(p!=NULL)i+;sci.license_number = p->license_number;sci.stutes = p->stutes;sci.car_runned = p->car_runned;sci.income = p->income;sci.repaired_time = p->repaired_time;sci.return_time = p->return_time;p = p->next;for(i=0;i<n1;i+)for(j=0;j<n1-i-2;j+)if(scj.car_runned>scj+1.car_runned)t = scj;scj = scj+1;scj+1 = t;p = carDistance;i = -1;while(p!=NULL)i+;p->license_number = sci.license_number;p->stutes = sci.stutes;p->car_runned = sci.car_runned;p->income = sci.income;p->repaired_time = sci.repaired_time;p->return_time = sci.return_time;p = p->next;return(carDistance);/根据预期返回时间排序struct cars *rank_Time(struct cars *carTime)p = carTime;vector<struct cars> sc(n2);struct cars t;int i=-1;while (p!=NULL)i+;sci.license_number = p->license_number;sci.stutes = p->stutes;sci.car_runned = p->car_runned;sci.income = p->income;sci.repaired_time = p->repaired_time;sci.return_time = p->return_time;p = p->next;for (i=0;i<n2;i+)for (int j=0;j<n2-i-2;j+)if (scj.return_time>scj+1.return_time)t = scj;scj = scj+1;scj+1 = t;p = carTime;i = -1;while (p!=NULL)i+;p->license_number = sci.license_number;p->stutes = sci.stutes;p->car_runned = sci.car_runned;p->income = sci.income;p->repaired_time = sci.repaired_time;p->return_time = sci.return_time;p = p->next;return (carTime);/1.建立可以租借的链表struct cars *create_available(void)fp1 = fopen("data.dat","r");p1 = p2 = (struct cars *)malloc(LEN);available = NULL;while(!feof(fp1)n1 = n1 + 1;fscanf(fp1,"%d %d %f %d %d %f",&p1->license_number,&p1->stutes,&p1->car_runned,&p1->return_time,&p1->repaired_time,&p1->income);if(p1->stutes = 0)if(n1 = 1)available = p1;elsep2->next = p1;p2 = p1;p1 = (struct cars *)malloc(LEN);elsen1-;p2->next = NULL;fclose(fp1);/根据行驶过的路程进行排序rank_Distance(available);return(available);/2.建立已借出的链表struct cars *create_rented(void)fp1 = fopen("data.dat","r");p1 = p2 = (struct cars *)malloc(LEN);rented = NULL;while(!feof(fp1)n2 = n2 + 1;fscanf(fp1,"%d %d %f %d %d %f",&p1->license_number,&p1->stutes,&p1->car_runned,&p1->return_time,&p1->repaired_time,&p1->income);if(p1->stutes = 1)if(n2 = 1)rented = p1;elsep2->next = p1;p2 = p1;p1 = (struct cars *)malloc(LEN);elsen2-;p2->next = NULL;fclose(fp1);/根据行驶过的路程进行排序rank_Time(rented);return(rented);/3.建立修理中的链表struct cars *create_repairing(void)fp1 = fopen("data.dat","r");p1 = p2 = (struct cars *)malloc(LEN);repairing = NULL;while(!feof(fp1)n3 = n3 + 1;fscanf(fp1,"%d %d %f %d %d %f",&p1->license_number,&p1->stutes,&p1->car_runned,&p1->return_time,&p1->repaired_time,&p1->income);if(p1->stutes = 2)if(n3 = 1)repairing = p1;elsep2->next = p1;p2 = p1;p1 = (struct cars *)malloc(LEN);elsen3-;p2->next = NULL;fclose(fp1);return (repairing);/打印汽车的信息void printThreeOfCars(struct cars *ThreeOfCar)p = ThreeOfCar;cout<<"编号t状态t行驶路程t借出天数t维修次数t收益n"while(p != NULL)cout<<p->license_number<<"t"<<p->stutes<<"t"<<p->car_runned<<"t"<<p->return_time<<"t"<<p->repaired_time<<"t"<<p->income<<endl;p=p->next;/计算链表数据个数int calculateCars(struct cars *ThreeOfCar)int k = 0;p = ThreeOfCar;while(p != NULL)k+;p = p->next;return (k);/删除汽车void deleteThreeOfCar(struct cars *ThreeOfCar, int xuhao)p = ThreeOfCar;if(xuhao = p->next->license_number)g = p->next;p->next = p->next->next;g->next = NULL;free (g);elsecout<<"错误deleteThreeOfCar()!"<<endl;/插入到可以租借的车链表中struct insertThreeOfCars(struct cars *ThreeOfCar,int LicenseNumber,int Stu,float CarRunned,int ReturnTime,int RepairedTime,float Ico)p = ThreeOfCar;n4+;while(p->next != NULL)p = p->next;p->next=(struct cars *)malloc(LEN);p->next->license_number = LicenseNumber;p->next->stutes = Stu;p->next->car_runned = CarRunned;p->next->return_time = ReturnTime;p->next->repaired_time = RepairedTime;p->next->income = Ico;p->next->next = NULL;cout<<"添加完成!"<<endl;cout<<"添加的信息是:"<<endl;cout<<"编号t汽车状态t行驶路程t预期归还时间t借出天数t收益"<<endl;cout<<LicenseNumber<<"t"<<Stu<<"t"<<CarRunned<<"t"<<ReturnTime<<"t"<<ReturnTime<<"t"<<Ico<<endl;return 0;/增加新车void AddNewCar(struct cars *available,struct cars *rented,struct cars *repairing)int ava,ren,rep,l;ava = calculateCars(available);ren = calculateCars(rented);rep = calculateCars(repairing);l = ava + ren + rep;insertThreeOfCars(available,l,0,0,0,0,0);/插入到未借出的链表中save_data(available);add_data(rented);add_data(repairing);/出租汽车void RentCar(struct cars *available,struct cars *rented, struct cars *repairing)int score,day = 1,i = 0;printThreeOfCars(available);cout<<"请选择所要租的序号!"<<endl;cin>>score;cout<<"请选择所租汽车的天数!"<<endl;cin>>day;p = f = available;cout<<"可以借的汽车的信息"<<endl;doif(score = p->license_number)insertThreeOfCars(rented,p->license_number,1,p->car_runned,day,p->repaired_time,p->income);deleteThreeOfCar(f, score);save_data(available); add_data(rented); add_data(repairing);break;f = p;p = p->next;while(p != NULL);cout<<"n租借完成!"<<endl;/归还收费void ReturnCar(struct cars *available,struct cars *rented,struct cars *repairing)int score,i = 0;float run,money;printThreeOfCars(rented);cout<<"请选择所要归还的车的序号!"<<endl;cin>>score;cout<<"请输入汽车在租借时所跑的路程!"<<endl;cin>>run;p = f = rented;cout<<"要归还的车的信息"<<endl;doif(score = p->license_number)insertThreeOfCars(available,p->license_number,0,run + p->car_runned,0,p->repaired_time,p->income);deleteThreeOfCar(f, score);save_data(available); add_data(rented); add_data(repairing);break;f = p;p = p->next;while(p != NULL);cout<<"n已归还!"<<endl;/修理汽车void RepairCar(struct cars *available,struct cars *rented,struct cars *repairing)int score,i = 0;printThreeOfCars(available);cout<<"请选择所要修理的车的序号!"<<endl;cin>>score;p = f = available;cout<<"要修理的汽车的信息"<<endl;doif(score = p->license_number)insertThreeOfCars(repairing,p->license_number,2,p->car_runned,0,p->repaired_time,p->income);deleteThreeOfCar(f, score);save_data(available); add_data(rented); add_data(repairing);break;f = p;p = p->next;while(p != NULL);cout<<"n已送去修理!"<<endl;/查看修理状况void BackCar(struct cars *available,struct cars *rented,struct cars *repairing)int score,i = 0;printThreeOfCars(repairing);cout<<"请选择可以出租的修理中的汽车的序号!"<<endl;cin>>score;p = f = repairing;doif(score = p->license_number)insertThreeOfCars(available,p->license_number,0,p->car_runned,0,p->repaired_time + 1,p->income);deleteThreeOfCar(f, score);save_data(available); add_data(rented); add_data(repairing);break;f = p;p = p->next;while(p != NULL);cout<<"n可以租借了!"<<endl;/汽车查询void research(struct cars *ThreeOfCar, int id)int i = 0;p = ThreeOfCar;doif(id = p->license_number)i =1;break;p = p->next;while(p != NULL);if(i = 1)cout<<"序号为t状态为t已行驶的路程t预期归还时间t借出的次数t收益n"cout<<p->license_number<<"t"<<p->stutes<<"t"<<p->car_runned<<"t"<<p->return_time<<"t"<<p->repaired_time<<"t"<<p->income<<endl;/汽车查询结果void ReasearchCar(struct cars *available,struct cars *rented,struct cars *repairing)int id;cout<<"请输入查询汽车的编码:"<<endl;cin>>id;research(available,id);research(rented,id);research(repairing,id);/打印所有车的信息void PrintAllCar()cout<<"可以租借的汽车:"<<endl;printThreeOfCars(available);cout<<"租借出去的汽车:"<<endl;printThreeOfCars(rented);cout<<"正在维修的车:"<<endl;printThreeOfCars(repairing);/计算收益void Calculation(struct cars *ThreeOfCar)float AllCost = 0,GetMoney = 0,GetFree = 0;p = ThreeOfCar;ReadDataIni();doGetMoney += p->income;if(p->car_runned <=100 && p->car_runned >=0)AllCost =AllCost + car_cost + repair_cost*p->repaired_time + oil_cost*p->car_runned + rent_cost*p->car_runned;if(p->car_runned >100)AllCost =AllCost + car_cost + repair_cost*p->repaired_time + oil_cost*p->car_runned + rent_cost*100 + rentkm_cost*(p->car_runned - 100);p = p->next;while(p != NULL);GetFree = GetMoney - AllCost;cout<<"总收入t"<<"成本t"<<"收益"<<endl;cout<<GetMoney<<"t"<<AllCost<<"t"<<GetFree<<endl;/计算收益void CalculateProfit()cout<<"可以租借的汽车收入:"<<endl