C++程序设计实践报告
专 业: 软件工程
班 级:
学 号:
姓 名:
日期:2016年 X月 X日
目录
设计目 1
二总体设计 2
三 详细设计(car类例) 5
carcpp 5
车辆信息理系统cpp 5
四 测试调试 6
1)调试程中遇问题: 6
2)解决办法: 6
五源程序清单执行结果 6
A车辆信息理系统cpp: 6
Bcarh: 6
Ccarcpp: 25
Dtruckh: 28
Etruckcpp: 29
Fbush: 32
Gbuscpp: 33
Hbaseh 35
Ibasecpp 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_munint0
+base()void
+~base()void
+read()
+add()
+modify()int
+del()int
+save()
+show()
+js()
public
public
public
car
truck
bus
+astring
+astring
+astring
+b:string
+b:string
+b:string
+c:string
+c:string
+c:string
+d:string
+d:string
+d:string
+e:string
+e:string
+e:string
+fdouble
+fdouble
+fdouble
+gdouble
+gdouble
+gdouble
+hdouble
+hdouble
+hdouble
+idouble
+idouble
+idouble
+zfydouble
+zfydouble
+zfydouble
+lint
+lint
+jint
+count_carmunint
+count_truckmunint
+count_busmunint
+car()
+truck()
+bus()
+~car()
+~truck()
+~bus()
+car(string string stringstringstringdoubledoubledouble 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类例)
carcpp
1构造函数car():
功:定义空象方便操作
2 重载构造函数car(stringstringstringstringstringdoubledoubledouble double int):
参数:string编号string车牌号string制造公司string购买时间string型号double总公里数double油价double耗油量公里double养路费int厢数
功:初始化象文件中直接提取数形成象
3 析构函数~car():
功:释放象存
4 read()函数:
功:预设文文件中提取数初始化成car类象存入vector容器中
5add()函数:
功:通新建car象存入vector容器中便续操作中写入文件
6modify()函数:
参数:int index
功:通index确定操作vector数位置进行修改
7del()函数:
参数:int index
功:通index确定操作vector数位置进行删
8save()函数:
功:开文文件进行写入完成关闭文件
9show()函数:
功:输出vector容器中象
10js()函数:
功:计算车辆月总费(车辆总费油价*耗油量公里+基维护费)
车辆信息理系统cpp
1main()函数
功:输出总菜单
2car_manage()函数
功:输出轿车理子菜单
3truck_manage()函数
功:输出卡车理子菜单
4bus_manage()函数
功:输出客车理子菜单
5search()函数
功:输出车辆查询子菜单
6search_number()函数
功:输出预先统计类车辆总数
四 测试调试
调试成功功均实现
1)调试程中遇问题:
1数写入文件设计文件输入输出时遇较阻力明白输入存里数输入文件里继续
2添加修改菜单报错问题总法完美实现输入错误编号时错误提醒输出
3文件读取运行完遍程序运行报错
2)解决办法:
1查老师程序时鉴输入输出方法完美解决问题
2通bool值死循环套令函数bool真时跳出bool假时提醒者输入正确编号解决问题实现良输出
3改save()函数中分隔符 \t解决问题
五源程序清单执行结果
A车辆信息理系统cpp:
#include stdafxh
#include
#include
#include baseh
#include carh
#include truckh
#include bush
#includeiostream
using namespace std
int basecount_num 0
int carcount_carnum 0
int truckcount_trucknum 0
int buscount_busnum 0
vector
vector
vector
字符串分割函数
vector
{
stringsize_type pos
vector
str + pattern扩展字符串方便操作
unsigned int size strsize()
for (unsigned int i 0 i
pos strfind(pattern i)
if (pos
string s strsubstr(i pos i)
resultpush_back(s)
i pos + patternsize() 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 iint l
cout << \n编号 << 车牌号 << 制造商 << 购买时间 << 型号 << 公里数 << 油价 << 耗油量 << 养路费 << 厢数 << 总费 << endl
vector
for (it vec_carbegin()it vec_carend()++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_carbegin()it vec_carend()++it)
{
if (it>acompare(a))
{
cout << \n车辆编号已存需重新输入 << endl
flag false
break
}
}
if (flag)
{
cout << \n否保存次修改?(yn)\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
for (it vec_carbegin()it vec_carend()++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 >> c3a
unsigned int iq 0
for (bool flag falseflag)
{
for (it vec_carbegin()it vec_carend()++it)
{
iq++
if (it>acompare(c3a))
{
index iq
flag true
break
}
if (it>acompare(c3a)&&iq vec_carsize())
{
cout << 您输入编号存请重新操作\niq 0
system(pause)break
}
}
if (flag)
{
cout << 请次输入修改信息:\n
cin >> b >> c >> d >> e >> f >> g >> h >> k >> l
car c(c3a b c d e f g h k l)
p &c
cout << 否保存次修改?(yn)\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
for (it vec_carbegin()it vec_carend()++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 falseflag)
{
for (it vec_carbegin()it vec_carend()++it)
{
i++
if (it>acompare(id))
{
flag true
index i
}
if (it>acompare(id) && i vec_carsize())
{
cout << 您输入编号存请重新操作\n
system(pause)i 0break
}
}
if (flag)
{
cout << \n否保存次修改?(yn)\n
cin >> out
if (out 'y')
{
p>del(index)
p>save()
system(pause)
}
else
{
system(pause)break
}
}break
}break
}
case 5
{
cout << \n车辆总数: << basecount_num << 中: << endl
cout << 轿车总数: << carcount_carnum << \n << endl
system(pause)
break
}
case 0quit truesystem(color 8F)break
defaultcout << \n请输入0~5间数字\n << endlsystem(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 iint l
cout << \n编号 << 车牌号 << 制造商 << 购买时间 << 型号 << 公里数 << 油价 << 耗油量 << 养路费 << 载重量 << 总费 << endl
vector
for (it vec_truckbegin()it vec_truckend()++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_truckbegin()it vec_truckend()++it)
{
if (it>acompare(a))
{
cout << \n车辆编号已存需重新输入 << endl
flag false
break
}
}
if (flag)
{
cout << \n否保存次修改?(yn)\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
for (it vec_truckbegin()it vec_truckend()++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 >> c3a
unsigned int iq 0
for (bool flag falseflag)
{
for (it vec_truckbegin()it vec_truckend()++it)
{
iq++
if (it>acompare(c3a))
{
index iq
flag true
break
}
if (it>acompare(c3a) && iq vec_trucksize())
{
cout << 您输入编号存请重新操作\n
system(pause)iq 0break
}
}
if (flag)
{
cout << 请次输入修改信息:\n
cin >> b >> c >> d >> e >> f >> g >> h >> k >> l
truck c(c3a b c d e f g h k l)
p &c
cout << 否保存次修改?(yn)\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
for (it vec_truckbegin()it vec_truckend()++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 falseflag)
{
for (it vec_truckbegin()it vec_truckend()++it)
{
i++
if (it>acompare(id))
{
flag true
index i
}
if (it>acompare(id) && i vec_trucksize())
{
cout << 您输入编号存请重新操作\n
system(pause)i 0break
}
}
if (flag)
{
cout << \n否保存次修改?(yn)\n
cin >> out
if (out 'y')
{
p>del(index)
p>save()
system(pause)
}
else
{
system(pause)break
}
}break
}break
}
case 5
{
cout << \n车辆总数: << basecount_num << 中: << endl
cout << 卡车总数: << truckcount_trucknum << \n << endl
system(pause)
break
}
case 0quit truesystem(color 8F)break
defaultcout << \n请输入0~5间数字\n << endlsystem(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 iint k
cout << \n编号 << 车牌号 << 制造商 << 购买时间 << 型号 << 公里数 << 油价 << 耗油量 << 养路费 << 载客量 << 总费 << endl
vector
for (it vec_busbegin()it vec_busend()++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_busbegin()it vec_busend()++it)
{
if (it>acompare(a))
{
cout << \n车辆编号已存需重新输入 << endl
flag false
break
}
}
if (flag)
{
cout << \n否保存次修改?(yn)\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
for (it vec_busbegin()it vec_busend()++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 >> c3a
unsigned int iq 0
for (bool flag falseflag)
{
for (it vec_busbegin()it vec_busend()++it)
{
iq++
if (it>acompare(c3a))
{
index iq
flag true
break
}
if (it>acompare(c3a) && iq vec_bussize())
{
cout << 您输入编号存请重新操作\n
system(pause)iq 0break
}
}
if (flag)
{
cout << 请次输入修改信息:\n
cin >> b >> c >> d >> e >> f >> g >> h >> k >> l
bus c(c3a b c d e f g h k l)
p &c
cout << 否保存次修改?(yn)\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
for (it vec_busbegin()it vec_busend()++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 falseflag)
{
for (it vec_busbegin()it vec_busend()++it)
{
i++
if (it>acompare(id))
{
flag true
index i
}
if (it>acompare(id) && i vec_bussize())
{
cout << 您输入编号存请重新操作\n
system(pause)i 0break
}
}
if (flag)
{
cout << \n否保存次修改?(yn)\n
cin >> out
if (out 'y')
{
p>del(index)
p>save()
system(pause)
}
else
{
system(pause)break
}
}break
}break
}
case 5
{
cout << \n车辆总数: << basecount_num << 中: << endl
cout << 客车总数: << buscount_busnum << \n << endl
system(pause)
break
}
case 0quit truesystem(color 8F)break
defaultcout << \n请输入0~5间数字\n << endlsystem(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
for (it1 vec_carbegin()it1 vec_carend()++it1)
{
if(it1>ccompare(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
for (it2 vec_truckbegin()it2 vec_truckend()++it2)
{
if (it2>ccompare(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
for (it3 vec_busbegin()it3 vec_busend()++it3)
{
if (it3>ccompare(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 << endlsystem(pause)
break
}
case 2
{
string a
cout << \n请输入查询编号: << endl
cin >> a
cout << \n查询结果: << endl
cout << \n编号 << 车牌号 << 制造商 << 购买时间 << 型号 << 公里数 << 油价 << 耗油量 << 养路费 << 厢数载客量载重量 << 总费 << endl
vector
for (it1 vec_carbegin()it1 vec_carend()++it1)
{
if (it1>acompare(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
for (it2 vec_truckbegin()it2 vec_truckend()++it2)
{
if (it2>acompare(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
for (it3 vec_busbegin()it3 vec_busend()++it3)
{
if (it3>acompare(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 << endlsystem(pause)
break
}
case 3
{
string a
cout << \n请输入查询类: << endl
cin >> a
cout << \n查询结果: << endl
cout << \n编号 << 车牌号 << 制造商 << 购买时间 << 型号 << 公里数 << 油价 << 耗油量 << 养路费 << 厢数载客量载重量 << 总费 << endl
vector
for (it1 vec_carbegin()it1 vec_carend()++it1)
{
if (it1>ecompare(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
for (it2 vec_truckbegin()it2 vec_truckend()++it2)
{
if (it2>ecompare(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
for (it3 vec_busbegin()it3 vec_busend()++it3)
{
if (it3>ecompare(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 << endlsystem(pause)
break
}
case 0quit truesystem(color 8F)break
defaultcout << \n请输入0~5间数字\n << endlsystem(pause)break
}
if (quit true)
break
}
system(cls)
}
车辆数量子菜单
void search_number()
{
system(title 车辆数量统计情况)设置窗口标题
cout << \n车辆总数: << basecount_num << 中: << endl
cout << 轿车数量: << carcount_carnum << endl
cout << 卡车数量: << truckcount_trucknum << endl
cout << 客车数量: << buscount_busnum << \n << endl
system(pause)
}
int main()
{
system(title 文件提取情况)设置窗口标题
system(color 8F)设置窗口背景色灰色字体亮白色
system(mode con cols102 lines30 )设置窗口确保组数显示行
truck a
aread()
bus b
bread()
car c
cread()
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
defaultcout << \n请输入0~5间数字\n << endlsystem(pause)break
}
if (choice 0)
break
system(cls)
}
return 0
}
Bcarh:
#pragma once
#include baseh
#include
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统计轿车总数
}
Ccarcpp:
#include stdafxh
#include carh
#include
#include
#include
#include
using namespace std
extern vector
extern vector
carcar()
{
}
carcar(string a string b string c string d string e double f double g double h double i int l)
{
this>a athis>b bthis>c cthis>d dthis>e ethis>f fthis>g gthis>h hthis>i ithis>l l
}
car~car()
{
}
void carread()
{
fstream carfile(轿车车辆信息txt iosin | iosout)
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 << endlsystem(pause)
while (getline(carfile str))
{
if (strcompare()) {
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_carpush_back(car(idcpgssjxh atof(glc_str()) atof(yjc_str()) atof(ylc_str()) atof(ylfc_str()) atoi(xsc_str())))
count_num++
count_carnum++
}
else
{
cout << 文件容空请添加数 << endl
}
}
}
vector
for (it vec_carbegin()it vec_carend()++it)
it>js()
carfileclose()
}
void caradd()
{
vec_carpush_back(car(a b c d e f g h i l))存入象量中
count_num++
count_carnum++
}
void carmodify(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 cardel(int index)
{
vec_carerase(vec_carbegin() + index 1)
count_num
count_carnum
}
void carsave()
{
ofstream carfile
carfileopen(轿车车辆信息txt)
vector
for (it vec_carbegin()it vec_carend()++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制表符分隔数
carfileclose()
}
void carshow() const
{
vector
for (it vec_carbegin()it vec_carend()++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 carjs()
{
zfy g*h + i + 1000
}
Dtruckh:
#pragma once
#include baseh
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统计卡车总数
}
Etruckcpp:
#include stdafxh
#include truckh
#include
#include
#include
#include
using namespace std
extern vector
extern vector
trucktruck()
{
}
trucktruck(string a string b string c string d string e double f double g double h double iint l)
{
this>a athis>b bthis>c cthis>d dthis>e ethis>f fthis>g gthis>h hthis>i ithis>l l
}
truck~truck()
{
}
void truckread()
{
fstream truckfile(卡车车辆信息txt iosin | iosout)
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 (strcompare()) {
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_truckpush_back(truck(id cp gs sj xh atof(glc_str()) atof(yjc_str()) atof(ylc_str()) atof(ylfc_str()) atoi(ylfc_str())))
count_num++
count_trucknum++
}
else
{
cout << 文件容空请添加数 << endl
}
}
}
vector
for (it vec_truckbegin()it vec_truckend()++it)
it>js()
truckfileclose()
}
void truckadd()
{
vec_truckpush_back(truck(a b c d e f g h i l))存入象量中
count_num++
count_trucknum++
}
void truckmodify(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 truckdel(int index)
{
vec_truckerase(vec_truckbegin() + index 1)
count_num
count_trucknum
}
void trucksave()
{
ofstream truckfile
truckfileopen(卡车车辆信息txt)
vector
for (it vec_truckbegin()it vec_truckend()++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制表符分隔数
truckfileclose()
}
void truckshow() const
{
vector
for (it vec_truckbegin()it vec_truckend()++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 truckjs()
{
zfy g*h + i + 1500
}
Fbush:
#pragma once
#include baseh
class bus
public base
{
public
bus()
bus(string string string string string double double double doubleint)编号车牌号制造公司购买时间型号总公里数油价耗油量公里养路费载客量
~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统计客车总数
}
Gbuscpp:
#include stdafxh
#include bush
#include
#include
#include
#include
using namespace std
extern vector
extern vector
busbus()
{
}
busbus(string a string b string c string d string e double f double g double h double iint j)
{
this>a athis>b bthis>c cthis>d dthis>e ethis>f fthis>g gthis>h hthis>i ithis>j j
}
bus~bus()
{
}
void busread()
{
fstream busfile(客车车辆信息txt iosin | iosout)
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 (strcompare()) {
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_buspush_back(bus(id cp gs sj xh atof(glc_str()) atof(yjc_str()) atof(ylc_str()) atof(ylfc_str()) atoi(zkc_str())))
count_num++
count_busnum++
}
else
{
cout << 文件容空请添加数 << endl
}
}
}
vector
for (it vec_busbegin()it vec_busend()++it)
it>js()
busfileclose()
}
void busadd()
{
vec_buspush_back(bus(a b c d e f g h i j))存入象量中
count_num++
count_busnum++
}
void busmodify(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 busdel(int index)
{
vec_buserase(vec_busbegin() + index 1)
count_num
count_busnum
}
void bussave()
{
ofstream busfile
busfileopen(客车车辆信息txt)
vector
for (it vec_busbegin()it vec_busend()++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制表符分隔数
busfileclose()
}
void busshow() const
{
vector
for (it vec_busbegin()it vec_busend()++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<
void busjs()
{
zfy g*h + i + 2000
}
Hbaseh
#pragma once
#include
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统计车辆总数
}
Ibasecpp
#include stdafxh
#include baseh
basebase()
{
}
base~base()
{
}
J执行结果(轿车理例):
开始运行开文件:
图(1)
显示菜单:
图(2)
查车辆信息:
图(3)
添加信息(输错遍正确输入):
图(4)
修改信息(输入错误时):
图(5)
修改信息(正确输入):
图(6)
删信息(输入错误时):
图(7)
删信息(正确输入):
图(8)
查系列操作车辆信息:
图(9)
查轿车车辆数:
图(10)
查询相关汽车:
图(11)
产商查:
图(11)
编号查:
图(12)
类查:
图(13)
查询车辆总数:
图(14)
六 课程设计总结
课程设计培养学生综合运学知识发现提出分析解决实际问题锻炼实际力重环节学生实际工作力具体训练考察程着科学技术发展日新月异计算机应生活中说处二十世纪学生说掌握计算机开发技术十分重
题目车辆信息理系统设计说考验样找课堂学实际应佳结合点样程序更加直观简练样程序运行更加性化课程设计中必须考虑问题
感谢学校老师够实践锻炼机会够培养学力实际操作力通次课程设计获益良题目直完成整课设容实现理实际转变设计程序程中说问题重重种错误误区检验出次课程设计时纠正前错误养成学参考书籍鉴前辈验惯
文档香网(httpswwwxiangdangnet)户传
《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
该内容是文档的文本内容,更好的格式请下载文档