资源描述
汽车租借公司的管理系统数据结构课程设计报告
算 法 与 数 据 结 构
课 程 设 计 报 告
请尊重我的劳动成果不要复制!
题 目: 汽车租借公司的管理
班 级:
学 号:
姓 名:
成 绩:
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 cars
{
int 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.dat
void save_data(struct cars *carData)
{
p = carData;
fp1 = fopen("data.dat","w"); //以写的模式打开文件
while(p!=NULL)
{
fprintf(fp1,"%d %d %.2f %d %d %.2f\n",p->license_number,p->stutes,p->car_runned,p->return_time,p->repaired_time,p->income);
p = p->next;
}
fclose(fp1);
}
//追加数据存档到data.dat
void add_data(struct cars *carData)
{
p = carData;
fp1 = fopen("data.dat","a"); //以追加写入的模式打开文件
while(p!=NULL)
{
fprintf(fp1,"%d %d %.2f %d %d %.2f\n",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++;
sc[i].license_number = p->license_number;
sc[i].stutes = p->stutes;
sc[i].car_runned = p->car_runned;
sc[i].income = p->income;
sc[i].repaired_time = p->repaired_time;
sc[i].return_time = p->return_time;
p = p->next;
}
for(i=0;i<n1;i++)
{
for(j=0;j<n1-i-2;j++)
{
if(sc[j].car_runned>sc[j+1].car_runned)
{
t = sc[j];
sc[j] = sc[j+1];
sc[j+1] = t;
}
}
}
p = carDistance;
i = -1;
while(p!=NULL)
{
i++;
p->license_number = sc[i].license_number;
p->stutes = sc[i].stutes;
p->car_runned = sc[i].car_runned;
p->income = sc[i].income;
p->repaired_time = sc[i].repaired_time;
p->return_time = sc[i].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++;
sc[i].license_number = p->license_number;
sc[i].stutes = p->stutes;
sc[i].car_runned = p->car_runned;
sc[i].income = p->income;
sc[i].repaired_time = p->repaired_time;
sc[i].return_time = p->return_time;
p = p->next;
}
for (i=0;i<n2;i++)
{
for (int j=0;j<n2-i-2;j++)
{
if (sc[j].return_time>sc[j+1].return_time)
{
t = sc[j];
sc[j] = sc[j+1];
sc[j+1] = t;
}
}
}
p = carTime;
i = -1;
while (p!=NULL)
{
i++;
p->license_number = sc[i].license_number;
p->stutes = sc[i].stutes;
p->car_runned = sc[i].car_runned;
p->income = sc[i].income;
p->repaired_time = sc[i].repaired_time;
p->return_time = sc[i].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;
else
p2->next = p1;
p2 = p1;
p1 = (struct cars *)malloc(LEN);
}
else
n1--;
}
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;
else
p2->next = p1;
p2 = p1;
p1 = (struct cars *)malloc(LEN);
}
else
n2--;
}
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;
else
p2->next = p1;
p2 = p1;
p1 = (struct cars *)malloc(LEN);
}
else
n3--;
}
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);
}
else
{
cout<<"错误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;
do
{
if(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;
do
{
if(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;
do
{
if(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;
do
{
if(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;
do
{
if(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();
do
{
GetMoney += 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"<<"
展开阅读全文