C++车辆信息管理系统(共63页).docx
精选优质文档-倾情为你奉上软件学院课程设计报告设计名称: C+课程设计 选题名称: 车辆信息管理系统 姓 名: 王海洋 学 号: 专业班级 移动二班 系 (院): 软件学院 设计时间: 2016.6.132016.6.17 设计地点: 15#505 1课程设计目的(1)基本掌握面向对象程序设计的基本思路和方法; (2)达到熟练掌握C+语言的基本知识和技能;(3)能够利用所学的基本知识和技能,解决简单的程序设计问题·2课程设计任务与要求:任务设计题目从任务书所列选题表中选取,每人1题。要求:基本要求:(1) 要求利用面向对象的方法以及C+的编程思想来完成系统的设计; (2) 要求在设计的过程中,建立清晰的类层次; (3) 在系统中至少要定义三个类,每个类中要有各自的属性和方法; (4) 在系统的设计中,至少要用到面向对象的一种机制。 创新要求:在基本要求达到后,可进行创新设计,如根据查找结果进行修改的功能。3课程设计说明书一 需求分析 需要进行车辆信息的录入,然后进行查询、修改、删除、插入操作,最后要向文件中写入全部的车辆信息,完成这些基本功能后,进行一些菜单美化操作,加上一些特殊功能,例如密码登录等等。二 系统设计 利用了C+完成了这个车辆信息管理系统。在设计中采用文件的记忆功能可以对已输入的货物信息进行二次操作。系统首先是数据的录入并将数据储存在二进制文件中 基本功能:(1)添加车辆:主要完成车辆信息的添加,要求编号唯一。当添加了重复的编号时,则提示数据添加重复并取消添加;当车辆信息库已满,则提示不能再添加新的数据。(2)查询车辆:可按照三种方式来查询物品,分别为:按车辆制造公司查询:输入车辆制造公司,输出所查询的信息,若不存在该记录,则提示“该车辆制造公司不存在!”;按编号查询:输入编号,输出所查询的信息,若不存在该记录,则提示“该编号不存在!”;按类别查询:输入类别,输出所查询的信息,若不存在记录,则提示“该类别没有车辆!”;(3)显示车辆信息库:输出当前车辆信息库中所有车辆信息,每条记录占据一行(4)编辑功能:可根据查询结果对相应的记录进行修改,修改时注意编号的唯一性。(5)删除车辆:主要完成车辆信息的删除。如果当前车辆信息库为空,则提示“车辆信息库为空!”,并返回操作;否则,输入要删除的编号,根据编号删除该车辆的记录,如果该编号不在车辆信息库库中,则提示“该编号不存在”。(6)插入车辆在已有车辆信息中插入一个新车辆信息,根据编号判断插入位置,若编号不存在,提示”该车辆不存在!”;(7)统计信息输出当前车辆信息库中总物品数,以及按车辆类别,统计出当前车辆信息库中各类别的物品数并显示。有功能模块图和流程图车辆信息管理系统轿车管理卡车管理客车管理添加车辆信息插入车辆信息查找车辆信息修改车辆信息文件中读取车辆信息车辆信息写入文件显示车辆信息删除车辆信息按车牌号查找按公司查找类关系图 cho=11. 查询函数流程图。按车牌号查询YNcho=2按公司查询Y无车辆信息输出车辆信息Index<=count_*重新选择N2.插入信息。2. 删除函数。3.修改信息。 三 详细设计 1、首先写入头文件#include<iostream>#include<windows.h>#include<cstring>#include<cstdlib>/#include<iomanip>#include <fstream>using namespace std; 2、抽象类class Base public: virtual void read()=0;/从文件中读取 virtual void save()=0;/写入文件中 virtual void add()=0;/添加新信息 virtual void modify(int)=0;/修改 virtual void del(int)=0;/删除 virtual void insert(int)=0;/插入 virtual void search()=0;/查询 ;3.轿车类的实现。class Car:public Base public: void read(); void add(); void modify(int); void del(int); void insert(int); void search(); void save(); char carID20;/车牌号char car_corporation20;/公司double car_year,car_month,car_day;/购买时间double car_kilo;/总公里数double car_oil;/耗油量 double car_road;/养路费char box10;/车厢数 ;const int MAXcar=10;extern Car carMAXcar;extern int count_car;/车辆信息的最后一个,判断添加的位置void Car:read()/读取文件 ifstream carfile; carfile.open("轿车信息.txt"); carfile>>carcount_car.carID>>carcount_car.car_corporation>>carcount_car.car_year>>carcount_car.car_month; carfile>>carcount_car.car_day>>carcount_car.car_kilo>>carcount_car.car_oil>>carcount_car.car_road>>carcount_car.box; while(!carfile.eof() count_car+; carfile>>carcount_car.carID>>carcount_car.car_corporation>>carcount_car.car_year>>carcount_car.car_month; carfile>>carcount_car.car_day>>carcount_car.car_kilo>>carcount_car.car_oil>>carcount_car.car_road>>carcount_car.box; carfile.close();void Car:save()/写入文件 ofstream carfile; int i; carfile.open("轿车信息.txt"); for(i=0;i<=count_car-1;i+) carfile<<cari.carID<<" "<<cari.car_corporation<<" "<<cari.car_year<<" "<<cari.car_month<<" " carfile<<cari.car_day<<" "<<cari.car_kilo<<" "<<cari.car_oil<<" "<<cari.car_road<<" "<<cari.box<<endl; carfile.close();void Car:add()/添加新信息 strcpy(carcount_car.carID,carID); strcpy(carcount_car.car_corporation,car_corporation); strcpy(carcount_car.box,box); carcount_car.car_year=car_year; carcount_car.car_month=car_month; carcount_car.car_day=car_day; carcount_car.car_kilo=car_kilo; carcount_car.car_oil=car_oil; carcount_car.car_road=car_road; count_car+;void Car:modify(int index)/轿车修改函数 strcpy(carindex-1.carID,carID); strcpy(carindex-1.car_corporation,car_corporation); strcpy(carcount_car.box,box); carindex-1.car_year=car_year; carindex-1.car_month=car_month; carindex-1.car_day=car_day; carindex-1.car_kilo=car_kilo; carindex-1.car_oil=car_oil; carindex-1.car_road=car_road;void Car:del(int index)/删除函数 /删除车辆信息之后均前移 int i;for(i=index;i<=count_car-1;i+) strcpy(cari-1.carID,cari.carID); strcpy(cari-1.car_corporation,cari.car_corporation); strcpy(cari-1.box,cari.box); cari-1.car_year=cari.car_year; cari-1.car_month=cari.car_month; cari-1.car_day=cari.car_day; cari-1.car_kilo=cari.car_kilo; cari-1.car_oil=cari.car_oil; cari-1.car_road=cari.car_road; count_car-;void Car:insert(int index) int i; for(i=count_car-1;i>=index;i-) strcpy(cari+1.carID,cari.carID); strcpy(cari+1.car_corporation,cari.car_corporation); strcpy(cari+1.box,cari.box); cari+1.car_year=cari.car_year; cari+1.car_month=cari.car_month; cari+1.car_day=cari.car_day; cari+1.car_kilo=cari.car_kilo; cari+1.car_oil=cari.car_oil; cari+1.car_road=cari.car_road; strcpy(carindex.carID,carID); strcpy(carindex.car_corporation,car_corporation); strcpy(carindex.box,box); carindex.car_year=car_year; carindex.car_month=car_month; carindex.car_day=car_day; carindex.car_kilo=car_kilo; carindex.car_oil=car_oil; carindex.car_road=car_road; count_car+;void Car:search() int i,m=0; int cho; char corporation20,ID20; cout<<"请选择查询方式:"<<endl;cout<<"1.按公司查询" <<endl;cout<<"2.按车牌号查询"<<endl;cin>>cho; switch(cho) case 1: cout<<"请输入公司名称:"<<endl; cin>>corporation;break; case 2: cout<<"请输入车牌号 :"<<endl; cin>>ID;break; default: cout<<"选择1或2!"<<endl; for(i=0;i<count_car;i+) if(strcmp(cari.carID,ID)=0 | strcmp(cari.car_corporation,corporation)=0) cout<<"编号 车牌号 公司 购买日期 公里数 耗油量 养路费 厢数 总费用"<<endl; cout<<""<<i+1<<" "cout<<cari.carID<<" "<<cari.car_corporation<<" "<<cari.car_year<<"/"cout<<cari.car_month<<"/"<<cari.car_day<<" "<<cari.car_kilo<<" "cout<<cari.car_oil<<" "<<cari.car_road<<" "<<cari.box<<" " cout<<cari.car_oil*5+1000<<endl; m+; if(m=0) cout<<"不存在该轿车"<<endl;4、卡车类的实现class Truck:public Base public: void read(); void add(); void modify(int); void del(int); void insert(int); void search(); void save(); char truckID20;/车牌号char truck_corporation20;/公司double truck_year,truck_month,truck_day;/购买时间double truck_kilo;/总公里数double truck_oil;/耗油量 double truck_road;/养路费double load;/载重量 ;const int MAXtruck=10;extern Truck truckMAXtruck;extern int count_truck;void Truck:read() ifstream truckfile; truckfile.open("卡车信息.txt"); truckfile>>truckcount_truck.truckID>>truckcount_truck.truck_corporation; truckfile>>truckcount_truck.truck_year>>truckcount_truck.truck_month; truckfile>>truckcount_truck.truck_day>>truckcount_truck.truck_kilo; truckfile>>truckcount_truck.truck_oil>>truckcount_truck.truck_road>>truckcount_truck.load; while(!truckfile.eof() count_truck+; truckfile>>truckcount_truck.truckID>>truckcount_truck.truck_corporation; truckfile>>truckcount_truck.truck_year>>truckcount_truck.truck_month; truckfile>>truckcount_truck.truck_day>>truckcount_truck.truck_kilo; truckfile>>truckcount_truck.truck_oil>>truckcount_truck.truck_road>>truckcount_truck.load; truckfile.close();void Truck:save() ofstream truckfile; int i; truckfile.open("卡车信息.txt"); for(i=0;i<=count_truck-1;i+) truckfile<<trucki.truckID<<" "<<trucki.truck_corporation<<" " truckfile<<trucki.truck_year<<" "<<trucki.truck_month<<" " truckfile<<trucki.truck_day<<" "<<trucki.truck_kilo<<" " truckfile<<trucki.truck_oil<<" "<<trucki.truck_road<<" "<<trucki.load<<endl; truckfile.close();void Truck:add() strcpy(truckcount_truck.truckID,truckID); strcpy(truckcount_truck.truck_corporation,truck_corporation); truckcount_truck.load=load; truckcount_truck.truck_year=truck_year; truckcount_truck.truck_month=truck_month; truckcount_truck.truck_day=truck_day; truckcount_truck.truck_kilo=truck_kilo; truckcount_truck.truck_oil=truck_oil; truckcount_truck.truck_road=truck_road; count_truck+;void Truck:modify(int index) strcpy(truckindex-1.truckID,truckID); strcpy(truckindex-1.truck_corporation,truck_corporation); truckindex-1.load=load; truckindex-1.truck_year=truck_year; truckindex-1.truck_month=truck_month; truckindex-1.truck_day=truck_day; truckindex-1.truck_kilo=truck_kilo; truckindex-1.truck_oil=truck_oil; truckindex-1.truck_road=truck_road;void Truck:del(int index) int i;for(i=index;i<=count_truck-1;i+) strcpy(trucki-1.truckID,trucki.truckID); strcpy(trucki-1.truck_corporation,trucki.truck_corporation); trucki-1.load=trucki.load; trucki-1.truck_year=trucki.truck_year; trucki-1.truck_month=trucki.truck_month; trucki-1.truck_day=trucki.truck_day; trucki-1.truck_kilo=trucki.truck_kilo; trucki-1.truck_oil=trucki.truck_oil; trucki-1.truck_road=trucki.truck_road; count_truck-;void Truck:insert(int index) int i; for(i=count_truck-1;i>=index;i-) strcpy(trucki+1.truckID,trucki.truckID); strcpy(trucki+1.truck_corporation,trucki.truck_corporation); trucki+1.truck_year=trucki.truck_year; trucki+1.truck_month=trucki.truck_month; trucki+1.truck_day=trucki.truck_day; trucki+1.truck_kilo=trucki.truck_kilo; trucki+1.truck_oil=trucki.truck_oil; trucki+1.truck_road=trucki.truck_road; trucki+1.load=trucki.load; strcpy(truckindex.truckID,truckID); strcpy(truckindex.truck_corporation,truck_corporation); truckindex.truck_year=truck_year; truckindex.truck_month=truck_month; truckindex.truck_day=truck_day; truckindex.truck_kilo=truck_kilo; truckindex.truck_oil=truck_oil; truckindex.truck_road=truck_road; truckindex.load=load; count_truck+;void Truck:search() int i,m=0; int cho; char corporation20; char ID20; cout<<"请选择查询方式:"<<endl;cout<<"1.按公司查询" <<endl;cout<<"2.按车牌号查询"<<endl;cin>>cho; switch(cho) case 1: cout<<"请输入公司名称:"<<endl; cin>>corporation;break; case 2: cout<<"请输入车牌号 :"<<endl; cin>>ID;break; default: cout<<"选择1或2!"<<endl; for(i=0;i<count_truck;i+) if(strcmp(trucki.truckID,ID)=0 | strcmp(trucki.truck_corporation,corporation)=0) cout<<"编号 车牌号 公司 购买日期 公里数 耗油量 养路费 载重量 总费用"<<endl; cout<<""<<i+1<<" "cout<<trucki.truckID<<" "<<trucki.truck_corporation<<" "cout<<trucki.truck_year<<"/"<<trucki.truck_month<<"/"<<trucki.truck_day;cout<<" "<<trucki.truck_kilo<<" "<<trucki.truck_oil;cout<<" "<<trucki.truck_road<<" "<<trucki.load<<" " cout<<trucki.truck_oil*5+1500<<endl; m+; if(m=0) cout<<"不存在该卡车!"<<endl;5.客车类的实现。class Bus:public Base public: void read(); void add(); void modify(int); void del(int); void insert(int); void search(); void save(); char busID20;/车牌号char bus_corporation20;/公司double bus_year,bus_month,bus_day;/购买时间double bus_kilo;/总公里数double bus_oil;/耗油量 double bus_road;/养路费double busload;/载客量 ;const int MAXbus=10;extern Bus busMAXbus;extern int count_bus;void Bus:read() ifstream busfile; busfile.open("客车信息.txt"); busfile>>buscount_bus.busID>>buscount_bus.bus_corporation; busfile>>buscount_bus.bus_year>>buscount_bus.bus_month; busfile>>buscount_bus.bus_day>>buscount_bus.bus_kilo; busfile>>buscount_bus.bus_oil>>buscount_bus.bus_road>>buscount_bus.busload; while(!busfile.eof() count_bus+; busfile>>buscount_bus.busID>>buscount_bus.bus_corporation; busfile>>buscount_bus.bus_year>>buscount_bus.bus_month; busfile>>buscount_bus.bus_day>>buscount_bus.bus_kilo; busfile>>buscount_bus.bus_oil>>buscount_bus.bus_road>>buscount_bus.busload; busfile.close();void Bus:save() ofstream busfile; int i; busfile.open("客车信息.txt"); for(i=0;i<=count_bus-1;i+) busfile<<busi.busID<<" "<<busi.bus_corporation<<" " busfile<<busi.bus_year<<" "<<busi.bus_month<<" " busfile<<busi.bus_day<<" "<<busi.bus_kilo<<" " busfile<<busi.bus_oil<<" "<<busi.bus_road<<" "<<busi.busload<<endl; busfile.close();void Bus:add() strcpy(buscount_bus.busID,busID); strcpy(buscount_bus.bus_corporation,bus_corporation); buscount_bus.busload=busload; buscount_bus.bus_year=bus_year; buscount_bus.bus_month=bus_month; buscount_bus.bus_day=bus_day; buscount_bus.bus_kilo=bus_kilo; buscount_bus.bus_oil=bus_oil; buscount_bus.bus_road=bus_road; count_bus+;void Bus:modify(int index) strcpy(busindex-1.busID,busID); strcpy(busindex-1.bus_corporation,bus_corporation); busindex-1.busload=busload; busindex-1.bus_year=bus_year; busindex-1.bus_month=bus_month; busindex-1.bus_day=bus_day; busindex-1.bus_kilo=bus_kilo; busindex-1.bus_oil=bus_oil; busindex-1.bus_road=bus_road;void Bus:del(int index) int i;for(i=index;i<=count_bus-1;i+) strcpy(busi-1.busID,busi.busID); strcpy(busi-1.bus_corporation,busi.bus_corporation); busi-1.busload=busi.busload; busi-1.bus_year=busi.bus_year; busi-1.bus_month=busi.bus_month; busi-1.bus_day=busi.bus_day; busi-1.bus_kilo=busi.bus_kilo; busi-1.bus_oil=busi.bus_oil; busi-1.bus_road=busi.bus_