完整word版基于C++的车信息管理系统.docx
- 文档编号:23030654
- 上传时间:2023-04-30
- 格式:DOCX
- 页数:22
- 大小:97.69KB
完整word版基于C++的车信息管理系统.docx
《完整word版基于C++的车信息管理系统.docx》由会员分享,可在线阅读,更多相关《完整word版基于C++的车信息管理系统.docx(22页珍藏版)》请在冰豆网上搜索。
完整word版基于C++的车信息管理系统
皖西学院信息工程学院
SchoolofInformationandEngineering,WestAnhuiUniversity
《C++面向对象课内程序设计》
实验报告
2014~2015学年第二学期
计算机科学与技术专业业专
计科1301
班级
名姓
学号
任课教师
《C++面向对象课内程序设计》实验报告
学号:
姓名班级:
计科1301成绩:
实验名称:
小型车信息管理系统
实验地点:
PC
所使用的工具软件及环境:
个人计算机,Windows7,VC++6.0
一、实验目的:
进一步了解面对对象编程的优点,学会如何使用面向对象的方法来编写一个较大的应用程序。
总结本书所学的内容,编写一个综合性的程序。
二、实验任务:
设计一个程序,用来查询不同种类车的价格,性能等。
自行车包含车的名称,价格,最大速度,高度。
摩托车包含车的名称,价格,最大速度,最大里程。
汽车包含车的名称,价格,最大速度,车载人数。
可以实现录入车的信息,查询车的信息,实现名称查找并在屏幕显示车的信息。
查找不存在时提示不存在。
三、实验说明:
本次实验是体现了,类和对象,对象数组、静态成员、类的组合,继承。
文件的输入,输出等综合使用。
本系统中的3种不同种类的对象:
自行车、摩托车和小汽车,抽取共性特征,形成一个基类:
基本信息类vehicyle,然后在这个基类的基础上,分别派生出3个类:
自行车类bicycle、摩托车类motorcycle和小汽车类car。
系统管理类实现界面的输出,信息的查询。
共同构成小型车信息管理系统。
本系统的实用性在于,可以用于4s店或车辆专卖,二手车交易市场使用,用于录入商品信息并在客人问询时查询相对应的信息。
四、实验分析:
(一)基本信息类的属性和操作
1、基本类的信息类的属性
汽车类的编号、名称、价格、最大速度。
为了方便信息的读取,程序给每类车设置了一个车类别编号,以便区分各类车型。
2、基本信息类的操作
数据输入输入各车对象的信息:
车名,车的价格,车的最大车速;
数据输出输出各车对象的信息:
车名,车的价格,车的最大车速。
(二)各种车类的属性和操作
各类车型继承了基本信息类的共性特征,并增加了自己特有的属性。
1、自行车类的属性和操作
自行车类的属性有:
(1)继承了基本信息类的属性:
车型编号、车名、价格和车的最大速度;
)增加了自行车类区别与其他类的特殊属性:
高度。
2(.
自行车类的操作有:
(3)数据输入:
除了继承基本信息类的数据输入功能外,增加了输入自行车类特殊属性“高度”信息的功能;
(4)数据输出:
除了继承基本信息类的数据输入功能外,增加了输入自行车类特殊属性“高度”信息的功能。
2、摩托车类的属性和操作
摩托车类的属性有:
(1)继承了基本信息类的属性:
车型编号、车名、价格和车的最大速度;
(2)增加了摩托车类区别与其他类的特殊属性:
最大里程。
自行车类的操作有:
(3)数据输入:
除了继承基本信息类的数据输入功能外,增加了输入摩托车类特殊属性“最大里程”信息的功能;
(4)数据输出:
除了继承基本信息类的数据输入功能外,增加了输入摩托车类特殊属性“最大里程”信息的功能。
3、小汽车类的属性和操作
小汽车类的属性有:
(1)继承了基本信息类的属性:
车型编号、车名、价格和车的最大速度;
(2)增加了小汽车车类区别与其他类的特殊属性:
车载人数。
自行车类的操作有:
(3)数据输入:
除了继承基本信息类的数据输入功能外,增加了输入小汽车类特殊属性“车载人数”信息的功能;
(4)数据输出:
除了继承基本信息类的数据输入功能外,增加了输入小汽车类特殊属性“车载人数”信息的功能。
(三)系统管理类的操作
系统的管理功能自成一个类:
系统管理类。
类的操作:
(1)输入车的基本信息;
(2)根据车名查询某车的信息。
(四)基类和派生类的设计
根据上面的分析,需要设计一个基类vehicyle(基本信息类)和它的三个派生类bicycle(自行车类),motorcycle(摩托车类)和car(小汽车类)。
基本信息类vehicyle中的数据成员是num(车型类别编号)、name(车名)、price(车的价格)和maxspeed(最大速度)。
3个车类除了继承基类vehicyle的数据外,类bicycle增加了数据成员height()高度,类motorcycle增加了数据成员maxmile(最大里程),类car增加了数据成员seat(车载人数)。
在基类中定义了构造函数和对所有类型车的相同操作,成员函数Get_num负责取出车型类别编号,成员函数Getname负责取出车名,Get_price负责取出车的价格,成员函数Get_maxspeed负责取出车的最大车速,成员函数Input负责输入,Output负责输出。
.
系统管理类(System)的主要操作是:
成员函数In_formation负责输入车信息,成员函数search负责查询车信息,成员函数Interface负责界面的输出
(五)系统管理类的设计
(1)信息的输入
信息的输入功能由成员函数In_formation来完成,它根据要输入车的类别分别调用相对应的车信息输入功能函数完成本类车的输入。
有三个类别的车信息输入函数:
voidinfor1();//输入类对象数据
voidinfor2();
voidinfor3();
以infor1说明一条车信息的输入实现过程:
voidSystem:
:
infor1()//输入自行车类对象数据
{
bicycleA;
fstreamdatafile(fileName,ios:
:
in|ios:
:
out|ios:
:
binary);
datafile.seekp(0,ios:
:
end);
A.Input();
datafile.write((char*)&A,sizeof(classbicycle));
B[i1]=A;
datafile.close();
}
(2)信息的查询
信息查询功能由成员函数search来完成。
它接收从键盘输入车类别编号和车名,在对应的对象数组中查找,找到后通过调用对象的数据输出成员函数Outout来显示车信息。
五、参考答案:
实验代码:
#include
#include
#include
usingnamespacestd;
#defineN9//各类车的最大数
charfileName[]=super.dat;//存放车信息的数据文件
classvehicle{
protected:
intnum;//车类编号
charname[20];//车名
intprice;//车的价格
intmaxspeed;//车的最大车速
public:
vehicle(char*R_name=,intprice=0,intmaxspeed=0);//构造函数初始化
~vehicle(){}
取值函数//
intGet_num();
intGet_peice();
intGet_maxpeed();
char*Getname();
voidInput();
voidOutput();
};
classbicycle:
publicvehicle//自行车类
{
public:
bicycle(char*R_name=,intprice=0,intmaxspeed=0,intheight=0);
~bicycle(){}
voidInput();
voidOutput();
private:
intheight;//高度
};
classmotorcycle:
publicvehicle
{
public:
motorcycle(char*R_name=,intprice=0,intmaxspeed=0,intmaxmile=0);
~motorcycle(){}
voidInput();
voidOutput();
private:
intmaxmile;//最大里程
};
classcar:
publicvehicle
{
public:
car(char*R_name=,intprice=0,intmaxspeed=0,intseat=0);
~car(){}
voidInput();
voidOutput();
private:
intseat;//车载人数
};
classSystem{//系统管理类
private:
vehicleA;
bicycleB[3];
motorcycleC[3];
carD[3];
staticinti1,i2,i3;
voidinfor1();//输入类对象数据
voidinfor2();
voidinfor3();
voidsave();//将文件输出到了内存
voidsearch1(inth,charch[20]);//查找函数
voidinterface1();//界面输出
public:
System(){}
voidIn_information();
voidsearch();
voidInterface();
};
vehicle:
:
vehicle(char*R_name,intprice,intmaxspeed)
{
strcpy(name,R_name);
}
intvehicle:
:
Get_num()
{returnnum;}
intvehicle:
:
Get_peice()
{returnprice;}
intvehicle:
:
Get_maxpeed()
{returnmaxspeed;}
char*vehicle:
:
Getname()
{returnname;}
voidvehicle:
:
Input()
{
cout<<\\t车名:
;
cin>>name;
cout<<\\t车的价格:
;
cin>>price;
cout<<\\t车的最大速度:
;
cin>>maxspeed;
}
voidvehicle:
:
Output()
{
cout< cout<<\\t所要查看车信息: < cout<<\\t类别号: < < 车名: cout<<\\t cout<<\\t价格: < cout<<\\t最大车速: < } bicycle: : bicycle(char*R_name,intprice,intmaxspeed,int hegiht): vehicle(R_name,price,maxspeed) { num=1; } voidbicycle: : Input() { vehicle: : Input(); cout<<\\t高度: ; cin>>height; } voidbicycle: : Output() { vehicle: : Output(); cout<<\\t高度: < } motorcycle: : motorcycle(char*R_name,intprice,intmaxspeed,int maxmile): vehicle(R_name,price,maxspeed) { num=2; } voidmotorcycle: : Input() { vehicle: : Input(); cout<<\\t最大里程: ; cin>>maxmile; } voidmotorcycle: : Output() { vehicle: : Output(); cout<<\\t高度: < } car: : car(char*R_name,intprice,intmaxspeed,int seat): vehicle(R_name,price,maxspeed) { num=3; } voidcar: : Input() { vehicle: : Input(); cout<<\\t车载人数: ; cin>>seat; } voidcar: : Output() { vehicle: : Output(); cout<<\\t车载人数: < } intSystem: : i1=0; intSystem: : i2=0; intSystem: : i3=0; voidSystem: : interface1()//界面输出 { cout<<\ \n; cout<<\\t***********按车类别进行管理*************< cout<<\\t***********车类别选择*************< cout<<\\t1.自行车类< cout<<\\t2.摩托车类< cout<<\\t3.小汽车类< cout<<\\t4.退出< cout<<\\t请您选择车类别< } voidSystem: : In_information() { intrev1; intagain=1; chart; while(again) { interface1(); cin>>rev1; switch(rev1) { case1: infor1(); break; case2: infor2(); break; case3: infor3(); break; case4: Interface(); break; default: cout<<\\t\t没有此类车< continue; } cout<<\\t\t信息储存成功! < cout<<\\t\t是否继续输入(y/n)? ; cin>>t; cout< if(! (t=='Y'||t=='y')) again=0; } Interface(); } voidSystem: : infor1()//输入自行车类对象数据 { bicycleA; fstreamdatafile(fileName,ios: : in|ios: : out|ios: : binary); datafile.seekp(0,ios: : end); A.Input(); datafile.write((char*)&A,sizeof(classbicycle)); B[i1]=A; datafile.close(); } voidSystem: : infor2()//输入自行车类对象数据 { motorcycleA; fstreamdatafile(fileName,ios: : in|ios: : out|ios: : binary); datafile.seekp(0,ios: : end); A.Input(); datafile.write((char*)&A,sizeof(classmotorcycle)); C[i2]=A; datafile.close(); } voidSystem: : infor3()//输入自行车类对象数据 { carA; fstreamdatafile(fileName,ios: : in|ios: : out|ios: : binary); datafile.seekp(0,ios: : end);//写指针到文件尾部 A.Input(); datafile.write((char*)&A,sizeof(classcar)); D[i3]=A; datafile.close(); } voidSystem: : save() { inta; fstreamdatafile(fileName,ios: : out|ios: : in|ios: : binary); datafile.read((char*)&A,sizeof(vehicle)); while(! datafile.eof()) { a=A.Get_num(); switch(a) { case1: { datafile.seekp(-1*sizeof(classvehicle),ios: : cur); datafile.read((char*)&B[i1],sizeof(bicycle)); i1++; break; } case2: { datafile.seekp(-1*sizeof(classvehicle),ios: : cur); datafile.read((char*)&C[i2],sizeof(motorcycle)); i2++; break; } case3: { datafile.seekp(-1*sizeof(classvehicle),ios: : cur); datafile.read((char*)&D[i3],sizeof(car)); i3++; break; } default: break; } datafile.read((char*)&A,sizeof(vehicle)); } datafile.close(); } voidSystem: : search1(inth,charch[20]) { ints=0,found=0; switch(h) { case1: while(s { if(strcmp(ch,B[s].Getname())==0) { B[s].Output(); cout<<\\t\t****************************< found=1; } s++; } break; case2: while(s { if(strcmp(ch,C[s].Getname())==0) { C[s].Output(); cout<<\\t\t****************************< found=1; } s++; } break; case3: while(s { if(strcmp(ch,D[s].Getname())==0) { D[s].Output(); cout<<\\t\t****************************< found=1; } s++; } break; default: break; } if(found==0) cout<<\ \n\t\t对不起,该类别中没有您所要查询的车! < } voidSystem: : search() { intrev; charname[20]; intagain=1; chart; while(again) { interface1(); cin>>rev; cout<<\\t\t请输入要查询车名: ; cin>>name; search1(rev,name); cout<<\\t\t是否继续查询(y/n)? ; cin>>t; cout< if(! (t=='Y'||t=='y')) again=0; } Interface(); } voidSystem: : Interface() { intrev; cout<<\ \n; cout<<\\t**************欢迎使用******************< cout<<\\t****************************************< cout<<\\t*********小型车信息管理系统*************< cout<<\\t****************************************< cout<<\\t1.输入信息< cout<<\\t2.查询信息并显示< cout<<\\t3.退出< c
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 完整 word 基于 C+ 信息管理 系统
![提示](https://static.bdocx.com/images/bang_tan.gif)