您的当前位置:易达范文网 > 专题范文 > 公文范文 >

车辆管理系统实验报告课程设计

时间:2023-06-16 08:15:10 浏览次数:
导读: 成绩:《C++程序设计实践》报告专业:软件工程班级:学号:姓名:日期:2016年X月X日目录一、设计

成绩: 《C++程序设计实践》报告 专 业:
软件工程 班 级:
学 号:
姓 名:
日期:2016年 X月 X日 目录 一、设计目的 1 二、总体设计 2 三、 详细设计(以car类为例)
5 car.cpp: 5 车辆信息管理系统.cpp 5 四、 测试与调试 6 1)在调试过程中遇到的问题:
6 2)解决办法:
6 五、源程序清单和执行结果 6 A.车辆信息管理系统.cpp:
6 B.car.h:
6 C.car.cpp:
25 D.truck.h:
28 E.truck.cpp:
29 F.bus.h:
32 G.bus.cpp:
33 H.base.h 35 I.base.cpp 36 J.执行结果(以轿车管理为例):
37 六、 课程设计总结 45 一、设计目的 (1)
要求学生能够熟练掌握C++语言的基本知识和技能。

(2)
基本掌握面向对象程序设计的基本思路和方法。

(3)
能够利用所学的基本知识和技能,解决简单的面向对象程序设计问题。

所做题目:4题:
车辆管理系统主要负责各种车辆的常规信息管理工作。

系统中的车辆主要有大客车、小轿车和卡车。每种车辆有车辆编号、车牌号、车辆制造公司、车辆购买时间、车辆型号(大客车、小轿车和卡车)、总公里数、耗油量/公里、基本维护费用、养路费、累计总费用等信息。大客车还有载客量信息,小轿车还有厢数信息,卡车还有载重量信息。

每台车辆当月总费用=油价*耗油量/公里+基本维护费用。

基本维护费用:客车:2000元/月;
小轿车:1000元/月;
卡车:1500元/月 功能要求:
A.添加车辆 B.查询车辆 C.显示车辆信息库 D.修改车辆 E.删除车辆 F.统计功能 G.保存车辆 H.读取车辆 二、总体设计 (1)定义基类base,设计出函数框架;

(2)派生car类、truck类、bus类,在其中具体实现函数功能;

(3)分别设计轿车、卡车、客车管理子菜单,主函数中设计添加总菜单,解决问题。

模块图1:
base public car truck bus read() show() add() modify(int) del(int) save() car_manage() truck_manage () bus_manage() search() search_number() main 模块图2:
车辆信息管理系统 轿车管理 卡车管理 客车管理 相关信息查询 车辆信息查看 数量统计 单类车辆数量统计 车辆信息删除 车辆信息修改 车辆信息添加 按车辆型号查询 按车辆编号查询 按车辆制造公司查询 类图:
base +count_mun:int=0 +base():void +~base():void +read() +add() +modify():int +del():int +save() +show() +js() public public public car truck bus +a:string +a:string +a:string +b:string +b:string +b:string +c:string +c:string +c:string +d:string +d:string +d:string +e:string +e:string +e:string +f:double +f:double +f:double +g:double +g:double +g:double +h:double +h:double +h:double +i:double +i:double +i:double +zfy:double +zfy:double +zfy:double +l:int +l:int +j:int +count_carmun:int +count_truckmun:int +count_busmun:int +car() +truck() +bus() +~car() +~truck() +~bus() +car(string, string, string,string,string,double,double,double, double, int) +truck(string, string, string, string, string, double, double, double, double, int) +bus(string, string, string, string, string, double, double, double, double, int) +read():void +read():void +read():void +add():void +add():void +add():void +modify():int +modify():int +modify():int +del():int +del():int +del():int +save():void +save():void +save():void +show():void +show():void +show():void +js():void +js():void +js():void 三、 详细设计(以car类为例)
car.cpp: 1.构造函数car():
功能:用于定义一个空的对象方便操作。

2. 重载构造函数car(string,string,string,string,string,double,double,double, double, int):
参数:string编号,string车牌号,string制造公司,string购买时间,string型号,double总公里数,double油价,double耗油量/公里,double养路费,int厢数。

功能:用于初始化对象,在文件中直接提取数据形成对象。

3. 析构函数~car():
功能:释放对象内存。

4. read()函数:
功能:从预设的文本文件中提取数据,初始化成car类对象并一一存入vector容器中。

5.add()函数:
功能:通过新建car对象存入vector容器中,便于在后续操作中写入文件。

6.modify()函数:
参数:int index。

功能:通过index确定要操作的vector数据位置,进行修改。

7.del()函数:
参数:int index。

功能:通过index确定要操作的vector数据位置,进行删除。

8.save()函数:
功能:打开文本文件进行写入,完成后关闭文件。

9.show()函数:
功能:输出vector容器中的所有对象。

10.js()函数:
功能:计算车辆的当月总费用(车辆总费用=油价*耗油量/公里+基本维护费用)
车辆信息管理系统.cpp 1.main()函数 功能:输出总菜单。

2.car_manage()函数 功能:输出轿车管理子菜单。

3.truck_manage()函数 功能:输出卡车管理子菜单。

4.bus_manage()函数 功能:输出客车管理子菜单。

5.search()函数 功能:输出车辆查询子菜单。

6.search_number()函数 功能:输出预先统计的各类车辆总数。

四、 测试与调试 调试成功,各功能均可实现。

1)在调试过程中遇到的问题:
1.将数据写入文件。在设计文件的输入输出时遇到了较大的阻力,不明白怎么将输入到内存里的数据怎么再输入到文件里,而且还可以继续用。

2.添加和修改菜单的报错问题。总是无法完美的实现输入错误编号时的错误提醒输出。

3.文件的再读取。运行完一遍程序后再运行就报错。

2)解决办法:
1.查看老师的程序,同时借鉴别人输入输出的方法,完美的解决了自己的问题。

2.通过对bool值的死循环套用,令函数在bool为真时才能跳出,bool为假时可以提醒使用者输入正确的编号,解决了这一问题,实现了良好的输出。

3.改save()函数中的分隔符” ”为”\t”后解决问题。

五、源程序清单和执行结果 A.车辆信息管理系统.cpp:
#include “stdafx.h“ #include <vector> #include <iostream> #include “base.h“ #include “car.h“ #include “truck.h“ #include “bus.h“ #include“iostream“ using namespace std; int base::count_num = 0; int car::count_carnum = 0; int truck::count_trucknum = 0; int bus::count_busnum = 0; vector<car> vec_car; vector<truck>vec_truck; vector<bus>vec_bus; //字符串分割函数 vector<string> split(string str, string pattern) { string::size_type pos; vector<string> result; str += pattern;//扩展字符串以方便操作 unsigned int size = str.size(); for (unsigned int i = 0; i<size; i++) { pos = str.find(pattern, i); if (pos<size) { string s = str.substr(i, pos - i); result.push_back(s); i = pos + pattern.size() - 1; } } return result; } base *p = NULL; char out; //轿车管理子菜单 void car_manage() { system(“title 轿车管理子菜单“);//设置窗口标题 system(“color 3F“);//设置子菜单背景色:湖蓝色,字体颜色:亮白色 int choice, i = 0; bool quit = false; while (1) { system(“cls“); cout << “**********轿车管理子菜单**********“ << endl; cout << “ 1.查看车辆信息“ << endl; cout << “ 2.添加车辆信息“ << endl; cout << “ 3.修改车辆信息“ << endl; cout << “ 4.删除车辆信息“ << endl; cout << “ 5.统计车辆数“ << endl; cout << “ 0.退出“ << endl; cout << “**********************************“ << endl; cout << “请输入所要操作的编号:“; cin >> choice; switch (choice) { case 1: { car c1; p = &c1; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “厢数 “ << “总费用“ << endl; p->show(); system(“pause“); break; } case 2: { string a, b, c, d, e, j; double f, g, h, i;int l; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “厢数 “ << “总费用“ << endl; vector <car>::iterator it; for (it = vec_car.begin();it != vec_car.end();++it) cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->l << “ “ << it->zfy << endl; while (1) { cout << “\n请依次输入要添加的信息:\n“; cin >> a >> b >> c >> d >> e >> f >> g >> h >> i >> l; car c2(a, b, c, d, e, f, g, h, i, l); p = &c2; bool flag = true; for (it = vec_car.begin();it != vec_car.end();++it) { if (!it->a.compare(a)) { cout << “\n此车辆的编号已存在,需重新输入!“ << endl; flag = false; break; } } if (flag) { cout << “\n是否保存此次修改?(y/n)\n“; cin >> j; if (j == “y“) { p->add(); p->save(); } } if (j == “y“) break; } system(“pause“); break; } case 3: { car c3; p = &c3; int index = 0, l; double f, g, h, k; string b, c, d, e, j; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “厢数 “ << “总费用“ << endl; vector <car>::iterator it; for (it = vec_car.begin();it != vec_car.end();++it) cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->l << “ “ << it->zfy << endl; cout << “\n请填写要修改的车辆编号:\n“; cin >> c3.a; unsigned int iq = 0; for (bool flag = false;!flag;) { for (it = vec_car.begin();it != vec_car.end();++it) { iq++; if (!it->a.compare(c3.a)) { index = iq; flag = true; break; } if (it->a.compare(c3.a)&&iq == vec_car.size()) { cout << “您输入的编号不存在,请重新操作!\n“;iq = 0; system(“pause“);break; } } if (flag) { cout << “请依次输入要修改的信息:\n“; cin >> b >> c >> d >> e >> f >> g >> h >> k >> l; car c(c3.a, b, c, d, e, f, g, h, k, l); p = &c; cout << “是否保存此次修改?(y/n)\n“; cin >> j; if (j == “y“) { p->modify(index); p->save(); system(“pause“); } else { system(“pause“);break; } }break; }break; } case 4: { car c4; p = &c4; int index = 0; string id; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “厢数 “ << “总费用“ << endl; vector <car>::iterator it; for (it = vec_car.begin();it != vec_car.end();++it) cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->l << “ “ << it->zfy << endl; cout << “\n请选择要删除的车辆编号:\n“; cin >> id; unsigned int i = 0; for (bool flag = false;!flag;) { for (it = vec_car.begin();it != vec_car.end();++it) { i++; if (!it->a.compare(id)) { flag = true; index = i; } if (it->a.compare(id) && i == vec_car.size()) { cout << “您输入的编号不存在,请重新操作!\n“; system(“pause“);i = 0;break; } } if (flag) { cout << “\n是否保存此次修改?(y/n)\n“; cin >> out; if (out == 'y') { p->del(index); p->save(); system(“pause“); } else { system(“pause“);break; } }break; }break; } case 5: { cout << “\n所有车辆总数为:“ << base::count_num << “ 其中:“ << endl; cout << “轿车总数为:“ << car::count_carnum << “\n“ << endl; system(“pause“); break; } case 0:quit = true;system(“color 8F“);break; default:cout << “\n请输入0~5之间的数字!\n“ << endl;system(“pause“);break; } if (quit == true) break; } system(“cls“); return; } //卡车管理子菜单 void truck_manage() { system(“title 卡车管理子菜单“);//设置窗口标题 system(“color 3F“);//设置子菜单背景色:湖蓝色,字体颜色:亮白色 int choice, i = 0; bool quit = false; while (1) { system(“cls“); cout << “**********卡车管理子菜单**********“ << endl; cout << “ 1.查看车辆信息“ << endl; cout << “ 2.添加车辆信息“ << endl; cout << “ 3.修改车辆信息“ << endl; cout << “ 4.删除车辆信息“ << endl; cout << “ 5.统计车辆数“ << endl; cout << “ 0.退出“ << endl; cout << “**********************************“ << endl; cout << “请输入所要操作的编号:“; cin >> choice; switch (choice) { case 1: { truck c1; p = &c1; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “载重量 “ << “总费用“ << endl; p->show(); system(“pause“); break; } case 2: { string a, b, c, d, e, j; double f, g, h, i;int l; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “载重量 “ << “总费用“ << endl; vector <truck>::iterator it; for (it = vec_truck.begin();it != vec_truck.end();++it) cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->l << “ “ << it->zfy << endl; while (1) { cout << “\n请依次输入要添加的信息:\n“; cin >> a >> b >> c >> d >> e >> f >> g >> h >> i >> l; truck c2(a, b, c, d, e, f, g, h, i, l); p = &c2; bool flag = true; for (it = vec_truck.begin();it != vec_truck.end();++it) { if (!it->a.compare(a)) { cout << “\n此车辆的编号已存在,需重新输入!“ << endl; flag = false; break; } } if (flag) { cout << “\n是否保存此次修改?(y/n)\n“; cin >> j; if (j == “y“) { p->add(); p->save(); } } if (j == “y“) break; } system(“pause“); break; } case 3: { truck c3; p = &c3; int index = 0, l; double f, g, h, k; string b, c, d, e, j; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “载重量 “ << “总费用“ << endl; vector <truck>::iterator it; for (it = vec_truck.begin();it != vec_truck.end();++it) cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->l << “ “ << it->zfy << endl; cout << “\n请填写要修改的车辆编号:\n“; cin >> c3.a; unsigned int iq = 0; for (bool flag = false;!flag;) { for (it = vec_truck.begin();it != vec_truck.end();++it) { iq++; if (!it->a.compare(c3.a)) { index = iq; flag = true; break; } if (it->a.compare(c3.a) && iq == vec_truck.size()) { cout << “您输入的编号不存在,请重新操作!\n“; system(“pause“);iq = 0;break; } } if (flag) { cout << “请依次输入要修改的信息:\n“; cin >> b >> c >> d >> e >> f >> g >> h >> k >> l; truck c(c3.a, b, c, d, e, f, g, h, k, l); p = &c; cout << “是否保存此次修改?(y/n)\n“; cin >> j; if (j == “y“) { p->modify(index); p->save(); system(“pause“); } else { system(“pause“);break; } }break; }break; } case 4: { truck c4; p = &c4; int index = 0; string id; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “载重量 “ << “总费用“ << endl; vector <truck>::iterator it; for (it = vec_truck.begin();it != vec_truck.end();++it) cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->l << “ “ << it->zfy << endl; cout << “\n请选择要删除的车辆编号:\n“; cin >> id; unsigned int i = 0; for (bool flag = false;!flag;) { for (it = vec_truck.begin();it != vec_truck.end();++it) { i++; if (!it->a.compare(id)) { flag = true; index = i; } if (it->a.compare(id) && i == vec_truck.size()) { cout << “您输入的编号不存在,请重新操作!\n“; system(“pause“);i = 0;break; } } if (flag) { cout << “\n是否保存此次修改?(y/n)\n“; cin >> out; if (out == 'y') { p->del(index); p->save(); system(“pause“); } else { system(“pause“);break; } }break; }break; } case 5: { cout << “\n所有车辆总数为:“ << base::count_num << “ 其中:“ << endl; cout << “卡车总数为:“ << truck::count_trucknum << “\n“ << endl; system(“pause“); break; } case 0:quit = true;system(“color 8F“);break; default:cout << “\n请输入0~5之间的数字!\n“ << endl;system(“pause“);break; } if (quit == true) break; } system(“cls“); return; } //客车管理子菜单 void bus_manage() { system(“title 客车管理子菜单“);//设置窗口标题 system(“color 3F“);//设置子菜单背景色:湖蓝色,字体颜色:亮白色 int choice, i = 0; bool quit = false; while (1) { system(“cls“); cout << “**********客车管理子菜单**********“ << endl; cout << “ 1.查看车辆信息“ << endl; cout << “ 2.添加车辆信息“ << endl; cout << “ 3.修改车辆信息“ << endl; cout << “ 4.删除车辆信息“ << endl; cout << “ 5.统计车辆数“ << endl; cout << “ 0.退出“ << endl; cout << “**********************************“ << endl; cout << “请输入所要操作的编号:“; cin >> choice; switch (choice) { case 1: { bus c1; p = &c1; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “载客量 “ << “总费用“ << endl; p->show(); system(“pause“); break; } case 2: { string a, b, c, d, e, j; double f, g, h, i;int k; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “载客量 “ << “总费用“ << endl; vector <bus>::iterator it; for (it = vec_bus.begin();it != vec_bus.end();++it) cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->j << “ “ << it->zfy << endl; while (1) { cout << “\n请依次输入要添加的信息:\n“; cin >> a >> b >> c >> d >> e >> f >> g >> h >> i >> k; bus c2(a, b, c, d, e, f, g, h, i, k); p = &c2; bool flag = true; for (it = vec_bus.begin();it != vec_bus.end();++it) { if (!it->a.compare(a)) { cout << “\n此车辆的编号已存在,需重新输入!“ << endl; flag = false; break; } } if (flag) { cout << “\n是否保存此次修改?(y/n)\n“; cin >> j; if (j == “y“) { p->add(); p->save(); } } if (j == “y“) break; } system(“pause“); break; } case 3: { bus c3; p = &c3; int index = 0, l; double f, g, h, k; string b, c, d, e, j; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “载客量 “ << “总费用“ << endl; vector <bus>::iterator it; for (it = vec_bus.begin();it != vec_bus.end();++it) cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->j << “ “ << it->zfy << endl; cout << “\n请填写要修改的车辆编号:\n“; cin >> c3.a; unsigned int iq = 0; for (bool flag = false;!flag;) { for (it = vec_bus.begin();it != vec_bus.end();++it) { iq++; if (!it->a.compare(c3.a)) { index = iq; flag = true; break; } if (it->a.compare(c3.a) && iq == vec_bus.size()) { cout << “您输入的编号不存在,请重新操作!\n“; system(“pause“);iq = 0;break; } } if (flag) { cout << “请依次输入要修改的信息:\n“; cin >> b >> c >> d >> e >> f >> g >> h >> k >> l; bus c(c3.a, b, c, d, e, f, g, h, k, l); p = &c; cout << “是否保存此次修改?(y/n)\n“; cin >> j; if (j == “y“) { p->modify(index); p->save(); system(“pause“); } else { system(“pause“);break; } }break; }break; } case 4: { bus c4; p = &c4; int index = 0; string id; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “载客量 “ << “总费用“ << endl; vector <bus>::iterator it; for (it = vec_bus.begin();it != vec_bus.end();++it) cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->j << “ “ << it->zfy << endl; cout << “\n请选择要删除的车辆编号:\n“; cin >> id; unsigned int i = 0; for (bool flag = false;!flag;) { for (it = vec_bus.begin();it != vec_bus.end();++it) { i++; if (!it->a.compare(id)) { flag = true; index = i; } if (it->a.compare(id) && i == vec_bus.size()) { cout << “您输入的编号不存在,请重新操作!\n“; system(“pause“);i = 0;break; } } if (flag) { cout << “\n是否保存此次修改?(y/n)\n“; cin >> out; if (out == 'y') { p->del(index); p->save(); system(“pause“); } else { system(“pause“);break; } }break; }break; } case 5: { cout << “\n所有车辆总数为:“ << base::count_num << “ 其中:“ << endl; cout << “客车总数为:“ << bus::count_busnum << “\n“ << endl; system(“pause“); break; } case 0:quit = true;system(“color 8F“);break; default:cout << “\n请输入0~5之间的数字!\n“ << endl;system(“pause“);break; } if (quit == true) break; } system(“cls“); return; } //相关汽车查询子菜单 void search() { system(“title 相关汽车查询子菜单“);//设置窗口标题 system(“color 3F“);//设置子菜单背景色:湖蓝色,字体颜色:亮白色 int choice, i = 0; bool quit = false; while (1) { system(“cls“); cout << “**********相关汽车查询子菜单**********“ << endl; cout << “ 1.按车辆制造公司查询“ << endl; cout << “ 2.按车辆编号查询“ << endl; cout << “ 3.按车辆类别查询“ << endl; cout << “ 0.退出“ << endl; cout << “**************************************“ << endl; cout << “请输入所要操作的编号:“; cin >> choice; switch (choice) { case 1: { string a; cout << “\n请输入要查询的制造公司:“ << endl; cin >> a; cout << “\n查询结果:“ << endl; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “厢数/载客量/载重量 “ << “总费用“ << endl; vector <car>::iterator it1; for (it1 = vec_car.begin();it1 != vec_car.end();++it1) { if(!it1->c.compare(a)) cout << it1->a << “ “ << it1->b << “ “ << it1->c << “ “ << it1->d << “ “ << it1->e << “ “ << it1->f << “ “ << it1->g << “ “ << it1->h << “ “ << it1->i << “ “ << it1->l << “\t\t\t“ << it1->zfy << endl; } vector <truck>::iterator it2; for (it2 = vec_truck.begin();it2 != vec_truck.end();++it2) { if (!it2->c.compare(a)) cout << it2->a << “ “ << it2->b << “ “ << it2->c << “ “ << it2->d << “ “ << it2->e << “ “ << it2->f << “ “ << it2->g << “ “ << it2->h << “ “ << it2->i << “ “ << it2->l << “\t\t\t“ << it2->zfy << endl; } vector <bus>::iterator it3; for (it3 = vec_bus.begin();it3 != vec_bus.end();++it3) { if (!it3->c.compare(a)) cout << it3->a << “ “ << it3->b << “ “ << it3->c << “ “ << it3->d << “ “ << it3->e << “ “ << it3->f << “ “ << it3->g << “ “ << it3->h << “ “ << it3->i << “ “ << it3->j << “\t\t\t“ << it3->zfy << endl; }cout << endl;system(“pause“); break; } case 2: { string a; cout << “\n请输入要查询的编号:“ << endl; cin >> a; cout << “\n查询结果:“ << endl; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “厢数/载客量/载重量 “ << “总费用“ << endl; vector <car>::iterator it1; for (it1 = vec_car.begin();it1 != vec_car.end();++it1) { if (!it1->a.compare(a)) cout << it1->a << “ “ << it1->b << “ “ << it1->c << “ “ << it1->d << “ “ << it1->e << “ “ << it1->f << “ “ << it1->g << “ “ << it1->h << “ “ << it1->i << “ “ << it1->l << “\t\t\t“ << it1->zfy << endl; } vector <truck>::iterator it2; for (it2 = vec_truck.begin();it2 != vec_truck.end();++it2) { if (!it2->a.compare(a)) cout << it2->a << “ “ << it2->b << “ “ << it2->c << “ “ << it2->d << “ “ << it2->e << “ “ << it2->f << “ “ << it2->g << “ “ << it2->h << “ “ << it2->i << “ “ << it2->l << “\t\t\t“ << it2->zfy << endl; } vector <bus>::iterator it3; for (it3 = vec_bus.begin();it3 != vec_bus.end();++it3) { if (!it3->a.compare(a)) cout << it3->a << “ “ << it3->b << “ “ << it3->c << “ “ << it3->d << “ “ << it3->e << “ “ << it3->f << “ “ << it3->g << “ “ << it3->h << “ “ << it3->i << “ “ << it3->j << “\t\t\t“ << it3->zfy << endl; }cout << endl;system(“pause“); break; } case 3: { string a; cout << “\n请输入要查询的类别:“ << endl; cin >> a; cout << “\n查询结果:“ << endl; cout << “\n编号 “ << “车牌号 “ << “制造商“ << “ 购买时间“ << “ 型号 “ << “公里数 “ << “油价 “ << “耗油量 “ << “养路费 “ << “厢数/载客量/载重量 “ << “总费用“ << endl; vector <car>::iterator it1; for (it1 = vec_car.begin();it1 != vec_car.end();++it1) { if (!it1->e.compare(a)) cout << it1->a << “ “ << it1->b << “ “ << it1->c << “ “ << it1->d << “ “ << it1->e << “ “ << it1->f << “ “ << it1->g << “ “ << it1->h << “ “ << it1->i << “ “ << it1->l << “\t\t\t“ << it1->zfy << endl; } vector <truck>::iterator it2; for (it2 = vec_truck.begin();it2 != vec_truck.end();++it2) { if (!it2->e.compare(a)) cout << it2->a << “ “ << it2->b << “ “ << it2->c << “ “ << it2->d << “ “ << it2->e << “ “ << it2->f << “ “ << it2->g << “ “ << it2->h << “ “ << it2->i << “ “ << it2->l << “\t\t\t“ << it2->zfy << endl; } vector <bus>::iterator it3; for (it3 = vec_bus.begin();it3 != vec_bus.end();++it3) { if (!it3->e.compare(a)) cout << it3->a << “ “ << it3->b << “ “ << it3->c << “ “ << it3->d << “ “ << it3->e << “ “ << it3->f << “ “ << it3->g << “ “ << it3->h << “ “ << it3->i << “ “ << it3->j << “\t\t\t“ << it3->zfy << endl; }cout << endl;system(“pause“); break; } case 0:quit = true;system(“color 8F“);break; default:cout << “\n请输入0~5之间的数字!\n“ << endl;system(“pause“);break; } if (quit == true) break; } system(“cls“); } //车辆数量子菜单 void search_number() { system(“title 车辆数量统计情况“);//设置窗口标题 cout << “\n所有车辆总数为:“ << base::count_num << “ 其中:“ << endl; cout << “轿车数量为:“ << car::count_carnum << endl; cout << “卡车数量为:“ << truck::count_trucknum << endl; cout << “客车数量为:“ << bus::count_busnum << “\n“ << endl; system(“pause“); } int main() { system(“title 文件提取情况“);//设置窗口标题 system(“color 8F“);//设置窗口背景色为灰色,字体为亮白色 system(“mode con cols=102 lines=30 “);//设置窗口大小以确保一组数据可以显示在一行上 truck a; a.read(); bus b; b.read(); car c; c.read(); int choice;//将各个文件中的数据依次读入内存 //显示主菜单 while (1) { system(“title 主菜单“);//设置窗口标题 system(“cls“); cout << “**************主菜单**************“ << endl; cout << “ 1.轿车信息管理“ << endl; cout << “ 2.卡车信息管理“ << endl; cout << “ 3.客车信息管理“ << endl; cout << “ 4.查询相关汽车“ << endl; cout << “ 5.查询汽车数量“ << endl; cout << “ 0.退出“ << endl; cout << “**********************************“ << endl; cout << “请输入所要操作的编号:“; cin >> choice; switch (choice) { case 1: car_manage();break; case 2: truck_manage();break; case 3: bus_manage();break; case 4: search();break; case 5: search_number();break; case 0: { system(“cls“); cout << “\n\n\n\n\n/********************************************/“ << endl; cout << “\n/************** 感谢您的使用!***************/\n“ << endl; cout << “/********************************************/\n\n\n\n\n“ << endl; }break; default:cout << “\n请输入0~5之间的数字!\n“ << endl;system(“pause“);break; } if (choice == 0) break; system(“cls“); } return 0; } B.car.h:
#pragma once #include “base.h“ #include <string> using namespace std; class car : public base { public: car(); car(string, string, string, string, string, double, double, double, double, int);//编号,车牌号,制造公司,购买时间,型号,总公里数,油价,耗油量/公里,养路费,厢数。

~car(); void read();//读取 void add();//添加 void modify(int);//修改 void del(int);//删除 void save();//写入文件并保存 void show() const;//输出 void js();//计算总费用 string a;//编号 string b;//车牌号 string c;//制造公司 string d;//购买时间 string e;//型号 double f;//总公里数 double g;//油价 double h;//耗油量/公里 double i;//养路费 int l;//厢数 double zfy;//总费用 = g*h + i + 1000 static int count_carnum;//统计轿车总数 }; C.car.cpp:
#include “stdafx.h“ #include “car.h“ #include <fstream> #include <iostream> #include <vector> #include <string> using namespace std; extern vector<car> vec_car; extern vector<string> split(string str, string pattern); car::car() { } car::car(string a, string b, string c, string d, string e, double f, double g, double h, double i, int l) { this->a = a;this->b = b;this->c = c;this->d = d;this->e = e;this->f = f;this->g = g;this->h = h;this->i = i;this->l = l; } car::~car() { } void car::read() { fstream carfile(“轿车车辆信息.txt“, ios::in | ios::out); string str;//获取文件中每一行的字符 string pattern = “\t“;//字符的分隔符 string id = ““; string cp = ““; string gs = ““; string sj = ““; string xh = ““; string gl = ““; string yj = ““; string yl = ““; string ylf = ““; string xs = ““; if (!carfile) { cout << “\n\n/*************** 轿车相关文件打开失败!***************/\n\n\n\n“ << endl; } { cout << “\n\n/*************** 轿车相关文件打开成功!***************/\n\n\n\n“ << endl;system(“pause“); while (getline(carfile, str)) { if (str.compare(““)) { id = split(str, pattern)[0]; cp = (split(str, pattern)[1]); gs = (split(str, pattern)[2]); sj = (split(str, pattern)[3]); xh = (split(str, pattern)[4]); gl = (split(str, pattern)[5]); yj = (split(str, pattern)[6]); yl = (split(str, pattern)[7]); ylf = (split(str, pattern)[8]); xs = (split(str, pattern)[9]); vec_car.push_back(car(id,cp,gs,sj,xh, atof(gl.c_str()), atof(yj.c_str()), atof(yl.c_str()), atof(ylf.c_str()), atoi(xs.c_str()))); count_num++; count_carnum++; } else { cout << “文件内容为空,请添加数据!“ << endl; } } } vector <car>::iterator it; for (it = vec_car.begin();it != vec_car.end();++it) it->js(); carfile.close(); } void car::add() { vec_car.push_back(car(a, b, c, d, e, f, g, h, i, l));//存入对象向量中 count_num++; count_carnum++; } void car::modify(int index) { vec_car[index - 1].b = b; vec_car[index - 1].c = c; vec_car[index - 1].d = d; vec_car[index - 1].e = e; vec_car[index - 1].f = f; vec_car[index - 1].g = g; vec_car[index - 1].h = h; vec_car[index - 1].i = i; vec_car[index - 1].l = l; } void car::del(int index) { vec_car.erase(vec_car.begin() + index - 1); count_num--; count_carnum--; } void car::save() { ofstream carfile; carfile.open(“轿车车辆信息.txt“); vector <car>::iterator it; for (it = vec_car.begin();it != vec_car.end();++it) carfile << it->a << “\t“ << it->b << “\t“ << it->c << “\t“ << it->d << “\t“ << it->e << “\t“ << it->f << “\t“ << it->g << “\t“ << it->h << “\t“ << it->i << “\t“ << it->l << endl;//以制表符分隔数据 carfile.close(); } void car::show() const { vector <car>::iterator it; for (it = vec_car.begin();it != vec_car.end();++it) { it->js(); cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->l << “ “ << it->zfy << endl;//以制表符分隔数据 }cout << endl; } void car::js() { zfy = g*h + i + 1000; } D.truck.h:
#pragma once #include “base.h“ class truck : public base { public: truck(); truck(string, string, string, string, string, double, double, double, double, int);//编号,车牌号,制造公司,购买时间,型号,总公里数,油价,耗油量/公里,养路费,载重量。

~truck(); void read();//读取 void add();//添加 void modify(int);//修改 void del(int);//删除 void save();//写入文件并保存 void show() const;//输出 void js();//计算总费用 string a;//编号 string b;//车牌号 string c;//制造公司 string d;//购买时间 string e;//型号 double f;//总公里数 double g;//油价 double h;//耗油量/公里 double i;//养路费 int l;//载重量 double zfy;//总费用 = g*h + i + 1500 static int count_trucknum;//统计卡车总数 }; E.truck.cpp:
#include “stdafx.h“ #include “truck.h“ #include <fstream> #include <iostream> #include <vector> #include <string> using namespace std; extern vector<truck> vec_truck; extern vector<string> split(string str, string pattern); truck::truck() { } truck::truck(string a, string b, string c, string d, string e, double f, double g, double h, double i,int l) { this->a = a;this->b = b;this->c = c;this->d = d;this->e = e;this->f = f;this->g = g;this->h = h;this->i = i;this->l = l; } truck::~truck() { } void truck::read() { fstream truckfile(“卡车车辆信息.txt“, ios::in | ios::out); string str;//获取文件中每一行的字符 string pattern = “\t“;//字符的分隔符 string id = ““; string cp = ““; string gs = ““; string sj = ““; string xh = ““; string gl = ““; string yj = ““; string yl = ““; string ylf = ““; string zz = ““; if (!truckfile) { cout << “\n\n\n\n/*************** 卡车相关文件打开失败!***************/\n\n“ << endl; } { cout << “\n\n\n\n/*************** 卡车相关文件打开成功!***************/\n\n“ << endl; while (getline(truckfile, str)) { if (str.compare(““)) { id = split(str, pattern)[0]; cp = (split(str, pattern)[1]); gs = (split(str, pattern)[2]); sj = (split(str, pattern)[3]); xh = (split(str, pattern)[4]); gl = (split(str, pattern)[5]); yj = (split(str, pattern)[6]); yl = (split(str, pattern)[7]); ylf = (split(str, pattern)[8]); zz = (split(str, pattern)[9]); vec_truck.push_back(truck(id, cp, gs, sj, xh, atof(gl.c_str()), atof(yj.c_str()), atof(yl.c_str()), atof(ylf.c_str()), atoi(ylf.c_str()))); count_num++; count_trucknum++; } else { cout << “文件内容为空,请添加数据!“ << endl; } } } vector <truck>::iterator it; for (it = vec_truck.begin();it != vec_truck.end();++it) it->js(); truckfile.close(); } void truck::add() { vec_truck.push_back(truck(a, b, c, d, e, f, g, h, i, l));//存入对象向量中 count_num++; count_trucknum++; } void truck::modify(int index) { vec_truck[index - 1].b = b; vec_truck[index - 1].c = c; vec_truck[index - 1].d = d; vec_truck[index - 1].e = e; vec_truck[index - 1].f = f; vec_truck[index - 1].g = g; vec_truck[index - 1].h = h; vec_truck[index - 1].i = i; vec_truck[index - 1].l = l; } void truck::del(int index) { vec_truck.erase(vec_truck.begin() + index - 1); count_num--; count_trucknum--; } void truck::save() { ofstream truckfile; truckfile.open(“卡车车辆信息.txt“); vector <truck>::iterator it; for (it = vec_truck.begin();it != vec_truck.end();++it) truckfile << it->a << “\t“ << it->b << “\t“ << it->c << “\t“ << it->d << “\t“ << it->e << “\t“ << it->f << “\t“ << it->g << “\t“ << it->h << “\t“ << it->i << “\t“ << it->l << endl;//以制表符分隔数据 truckfile.close(); } void truck::show() const { vector <truck>::iterator it; for (it = vec_truck.begin();it != vec_truck.end();++it) { it->js(); cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->l << “ “ << it->zfy << endl;//以制表符分隔数据 }cout << endl; } void truck::js() { zfy = g*h + i + 1500; } F.bus.h:
#pragma once #include “base.h“ class bus : public base { public: bus(); bus(string, string, string, string, string, double, double, double, double,int);//编号,车牌号,制造公司,购买时间,型号,总公里数,油价,耗油量/公里,养路费,最大载客量。

~bus(); void read();//读取 void add();//添加 void modify(int);//修改 void del(int);//删除 void save();//写入文件并保存 void show() const;//输出 void js();//计算总费用 string a;//编号 string b;//车牌号 string c;//制造公司 string d;//购买时间 string e;//型号 double f;//总公里数 double g;//油价 double h;//耗油量/公里 double i;//养路费 int j;//载客量 double zfy = g*h + i + 2000;//总费用 = g*h + i + 2000 static int count_busnum;//统计客车总数 }; G.bus.cpp:
#include “stdafx.h“ #include “bus.h“ #include <fstream> #include <iostream> #include <vector> #include <string> using namespace std; extern vector<bus> vec_bus; extern vector<string> split(string str, string pattern); bus::bus() { } bus::bus(string a, string b, string c, string d, string e, double f, double g, double h, double i,int j) { this->a = a;this->b = b;this->c = c;this->d = d;this->e = e;this->f = f;this->g = g;this->h = h;this->i = i;this->j = j; } bus::~bus() { } void bus::read() { fstream busfile(“客车车辆信息.txt“, ios::in | ios::out); string str;//获取文件中每一行的字符 string pattern = “\t“;//字符的分隔符 string id = ““; string cp = ““; string gs = ““; string sj = ““; string xh = ““; string gl = ““; string yj = ““; string yl = ““; string ylf = ““; string zk = ““; if (!busfile) { cout << “\n\n/*************** 客车相关文件打开失败!***************/\n\n“ << endl; } { cout << “\n\n/*************** 客车相关文件打开成功!***************/\n\n“ << endl; while (getline(busfile, str)) { if (str.compare(““)) { id = split(str, pattern)[0]; cp = (split(str, pattern)[1]); gs = (split(str, pattern)[2]); sj = (split(str, pattern)[3]); xh = (split(str, pattern)[4]); gl = (split(str, pattern)[5]); yj = (split(str, pattern)[6]); yl = (split(str, pattern)[7]); ylf = (split(str, pattern)[8]); zk = (split(str, pattern)[9]); vec_bus.push_back(bus(id, cp, gs, sj, xh, atof(gl.c_str()), atof(yj.c_str()), atof(yl.c_str()), atof(ylf.c_str()), atoi(zk.c_str()))); count_num++; count_busnum++; } else { cout << “文件内容为空,请添加数据!“ << endl; } } } vector <bus>::iterator it; for (it = vec_bus.begin();it != vec_bus.end();++it) it->js(); busfile.close(); } void bus::add() { vec_bus.push_back(bus(a, b, c, d, e, f, g, h, i, j));//存入对象向量中 count_num++; count_busnum++; } void bus::modify(int index) { vec_bus[index - 1].b = b; vec_bus[index - 1].c = c; vec_bus[index - 1].d = d; vec_bus[index - 1].e = e; vec_bus[index - 1].f = f; vec_bus[index - 1].g = g; vec_bus[index - 1].h = h; vec_bus[index - 1].i = i; vec_bus[index - 1].j = j; } void bus::del(int index) { vec_bus.erase(vec_bus.begin() + index - 1); count_num--; count_busnum--; } void bus::save() { ofstream busfile; busfile.open(“客车车辆信息.txt“); vector <bus>::iterator it; for (it = vec_bus.begin();it != vec_bus.end();++it) busfile << it->a << “\t“ << it->b << “\t“ << it->c << “\t“ << it->d << “\t“ << it->e << “\t“ << it->f << “\t“ << it->g << “\t“ << it->h << “\t“ << it->i << “\t“ << it->l << endl;//以制表符分隔数据 busfile.close(); } void bus::show() const { vector <bus>::iterator it; for (it = vec_bus.begin();it != vec_bus.end();++it) { it->js(); cout << it->a << “ “ << it->b << “ “ << it->c << “ “ << it->d << “ “ << it->e << “ “ << it->f << “ “ << it->g << “ “ << it->h << “ “ << it->i << “ “ << it->j << “ “ << it->zfy << endl;//以制表符分隔数据 }cout<<endl; } void bus::js() { zfy = g*h + i + 2000; } H.base.h #pragma once #include <string> using namespace std; class base { public: base(void); virtual ~base(void); virtual void read() = 0; virtual void add() = 0; virtual void modify(int) = 0; virtual void del(int) = 0; virtual void save() = 0; virtual void show() const = 0; virtual void js() = 0; static int count_num;//统计车辆总数 }; I.base.cpp #include “stdafx.h“ #include “base.h“ base::base() { } base::~base() { } J.执行结果(以轿车管理为例):
开始运行,打开文件:
图(1)
显示主菜单:
图(2)
查看车辆信息:
图(3)
添加信息(输错一遍后正确输入):
图(4)
修改信息(输入错误时):
图(5)
修改信息(正确输入):
图(6)
删除信息(输入错误时):
图(7)
删除信息(正确输入):
图(8)
查看一系列操作后的车辆信息:
图(9)
查看轿车车辆数:
图(10)
查询相关汽车:
图(11)
按产商查:
图(11)
按编号查:
图(12)
按类别查:
图(13)
查询车辆总数:
图(14)
六、 课程设计总结 课程设计是培养学生综合运用所学知识,发现、提出、分析和解决实际问题,锻炼实际能力的重要环节。是对学生实际工作能力的具体训练和考察过程。随着科学技术发展的日新月异,当今计算机应用在生活中可以说无处不在。因此对于二十一世纪的大学生来说,掌握计算机开发技术十分重要。

我的题目是车辆信息管理系统的设计,对于我来说,这是很大的考验,所以怎样才能找到课堂所学与实际应用的最佳结合点,怎样才能让自己的程序更加直观简练,怎样才能让程序的运行更加人性化,这都是在课程设计中必须考虑的问题。

很感谢学校和老师给了我一个能够自主实践的锻炼自己的机会,让我能够培养自己的自学能力以及实际操作能力。通过这次课程设计,我获益良多。从拿到题目直到完成整个课设的内容,实现了从理论到实际的转变。在设计程序的过程中可以说是问题重重,各种错误以及误区都被检验出来,而这次课程设计则使我及时的纠正从前的错误,养成了自主学习与参考书籍,借鉴前辈经验的好习惯。

本文链接:https://www.gxcjt.com/zhuantifanwen/gongwenfanwen/49716.html(转载请注明文章来源)
Copyright © 2024 易达范文网 版权所有 备案号:桂ICP备20004951号-1
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
Top