2022年车辆管理系统

上传人:公**** 文档编号:567312120 上传时间:2024-07-19 格式:PDF 页数:24 大小:196.69KB
返回 下载 相关 举报
2022年车辆管理系统_第1页
第1页 / 共24页
2022年车辆管理系统_第2页
第2页 / 共24页
2022年车辆管理系统_第3页
第3页 / 共24页
2022年车辆管理系统_第4页
第4页 / 共24页
2022年车辆管理系统_第5页
第5页 / 共24页
点击查看更多>>
资源描述

《2022年车辆管理系统》由会员分享,可在线阅读,更多相关《2022年车辆管理系统(24页珍藏版)》请在金锄头文库上搜索。

1、C+ 项目:车辆管理系统目标:写一个小程序,要求到用标准模板库中的list容器和迭代器,可以使用到多继承来进行实验。1.1 General(概述) 1.在写代码之前要仔细阅读作业要求2.要求对不正确的输入做检查3.在你写完一个类之后,要紧接着写这个类的测试函数,因此,当你调试你写的代码的时候,你能够很容易的对你的代码做重复检查。这样才能够保证你当前写的代码能够准确无误的执行。 可能出于某些原因你要对你写过的代码作一此些修改,这样你重新测试你修改的代码就相比照较容易。4.添加完成你的任务所需要的函数。1.2 Introduction(简介): 渥太华这个城市正在创建一个有关交通工具的“数据库”

2、,来为它的议会 (委员会 )做预算提供较好的参考。 这个城市有许多不同种类的机动车辆:客车,货车,卡车,紧急车辆 (救护,消防等 ),在对这个城市了解之后,要求你设计一个有下列图要求的层次的系统。2 Implement the following functions for each class: 为每个类实现以下函数精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 1 页,共 24 页2.1 (Vehicle类) (属性:所有的属性要求为私有的)char licensePlate属性:车的车牌 (执照)作为它的id, 一个车牌最多可由8组成。cha

3、r *type 属性:车辆类型 (例如:汽车,卡车,消防车)char *make 属性:车辆的制造商double gasTankSize属性:总油量double fuelConsumption属性:单位路程耗油量函数: R1. 构造函数 vehicle (char *type, char* licensePlate, double gasTankSize, double fuelConsumption) Tppe 的默认值为: car licensePlate 的默认值为: ottawa01 gasTankSize 的默认值为: 100 fuelConsumption的默认值为: 10 所有其

4、他不在构造函数中的参数要求置0或置空R2. void setMake(char *make); 设置制造商 的值R3. setFuelData (double gasTankSize, double fuelConsumption) 设置燃料的有关信息 (总油量,单位路程耗油量) R4. setType (char *type) 设置车辆类型R5. setLicensePlate (char *license) 设置车辆的车牌R6. virtual printSpecifications() - 打印车辆的具体信息 ,例如:制造商、类型,车牌,燃油量和油箱容积R7. virtual doubl

5、e computeTravelDistance() 这个函数计算车辆可能行使的距离,计算公式为: gasTankSize * fuelConsumption(总油量 *单位路程耗油量 ) Class LoadVehicle:( LoadVehicle类) 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 2 页,共 24 页Attributes(属性) int numberOfWheels contains the number of wheels that the vehicle has. int numberOfWheels属性:车辆的车轮个数d

6、ouble loadCapacity the load weight that the vehicle can carry (in kg) double loadCapacity:车辆的负荷double towingCapacity the total weight that the vehicle can tow (in kg) double towingCapacity:车辆能够拖曳的重量Functions R8. loadVehicle (char *type, int numberOfWheels, double loadCapacity, double towingCapacity,

7、 double gasTankSize, double fuelConsumption). A constructor for the class. The default values for numberOfWheels, loadCapacity and towingCapacity are 6, 500kg and 5000kg respectively. The default values for gasTankSize and fuelConsumption are 200 and 6 respectively. The constructor will initialize a

8、ll the fields of the class as required. All other member variables that are not initialized should be set to the default values of the base class(es), or, if no default values exist, to 0 or NULL. 这个类的构造函数,各个属性的默认值:loadCapacity 的默认值: 6, 500kg towingCapacity 的默认值: 5000kg gasTankSize 的默认值: 200 fuelCon

9、sumption 的默认值: 6 其他没有初始化的成员变量应该设置为基类的默认值一致,如果没有默认值, 则应置0或置空R9. setLoadData (double towingCapacity, double loadCapacity) 设置负荷 ,拖曳量R10. printSpecifications() print the specification of the vehicle (the vehicle specification from the vehicle class, the towing capacity, the load capacity and the number

10、of wheels). 打印出车辆的具体信息,包括从基类继承的和它自身的。R11. double computeTravelDistance every pair of wheels above four reduces the travel distance by 5% (travelDistance = gasTankSize*fuelConsumption*(100- (numberOfWheels-4)/2*5)/100). For example: if the gasTankSize if 100 litres, the 精选学习资料 - - - - - - - - - 名师归纳总

11、结 - - - - - - -第 3 页,共 24 页fuelConsumption is 10 km/l and there are 10 wheels then the travelDistance= 100*10*(100-(10-4)/2*5)/100 = 1000*85/100 = 850km. 超过4个车轮,每增加两个车轮,车辆可行使的车程以5%减少. 例如:总油量为 100公升,耗油量为 10km/公升,该车车辆有 10个车轮,它可行使的车程为:100 * 10 * (100-(10-4)/2 * 5)/100 = 1000*85/100 = 850km. 2.3 Class p

12、assengerVehicle: (passengerVehicle类) Attributes int numberOfPassengers contains the number of passengers that the vehicle can Carry int numberOfPassengers属性:车辆可搭乘的乘客的数量Functions(函数) R12. passengerVehicle(char *type, int numPassengers, double gasTankSize, double fuelConsumption) The default values fo

13、r numPassengers is 5. The default values for gasTankSize and fuelConsumption are 100 and 11 respectively. The constructor will initialize all the fields of the class as required using default values of base classes. All other variables that are not initialized are set to 0 or NULL. 该类的构造函数,成员变量的默认值:

14、numPassengers 的默认值:5 gasTankSize 的默认值: 100 fuelConsumption 的默认值: 11 要用基类的构造函数对要求有默认值的属性进行初始化,没其他没有初始化的成员要置0或置空R13. setNumPassengers(int numPassengers) 设置可搭乘的乘客人数R14. printSpecifications() print the specification of the vehicle (the vehicle specification from the vehicle class, and the number of pass

15、engers). 打印车辆的具体信息R15. computeTravelDistance()超过5个人每多搭乘 1个人行程将以 2.5%减少例如:总油量为 100公升,燃油量为 10km/公升,有 7个乘客 ,则可行使的路程为:100*10*(100-(7-5)*2.5)/100 = 1000*95/100 = 950km. 2.4 Class emergencyVehicle(emergencyVehicle类) Attributes(属性) 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 4 页,共 24 页int numWorkers属性:为

16、每辆车分配的工作人员char *driver属性:为车辆分配的驾驶员char *station属性:车辆停靠的车站Functions R16. emergencyVehicle(char *type, char*driver, char *station, int numPassengers,double gasTankSize, double fuelConsumption) 构造函数,部分属性平的默认值:fornumPassengers 的默认值: 5 gasTankSize 的默认值: 100 fuelConsumption 的默认值: 11 wheels 的默认值: 6 其他没有给初始

17、值的属性要求置0或置空 . R17. setAssignment(char *driver, char *station)设置分配 (司机,停靠站 ) R18. printSpecifications() 打印的车辆车辆标准规格从车辆类,该loadvehcile ,客运车辆和emergencyequipment 类。打印车辆的具体信息R19. computeTravelDistance() 行程是 loadVehicle 和passengerVehicle 中较小的行程2.5 Class EmgergencyEquipmen(紧急设备类) Attributes 属性int sirenNoise

18、Distance 汽笛能够被听到的距离 ,默认为 500m int numBeds 可以同时供应病人的床位,默认值为2 Functions R20. emergencyEquipment(int sirenNoiseDistance, int numBeds) 构造函数给汽笛的可听见距离,床位初始化R21. getBedsNum() 返回床位数R22. printSpecifications() 打印汽笛的可听见距离,床位数2.6 Container class(容器类) 要求使用标准模板库中的list容器,list容器要求可以存储指向对象的指针,这样所有不同类型的车辆可以在同一个容器中(it

19、erator-迭代器 的使用) 2.7 Decision class(决策类) 使用相应的迭代器对容器遍历,使用dynamic casting运行时类型信息进行不同类之间的类型转型(如将指向不同派生类对象的基类指针转为派生类对象指针),可以对相应不同类的精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 5 页,共 24 页成员函数的调用,这个类由城市的议会用来做决定Attributes 属性list& vehicleList:各类车辆的指针Functions方法R23. decision(list&) 构造函数:接收存储各类车辆信息的容器R24. p

20、rintVehiclesSpecifications -打印所有车辆的具体信息R25. printEmergencyVehicles() -单独打印紧急车辆的紧急数据信息R26. int numberLongDistanceEmergencyVehicles() 打印不用中途加油能够行使 800km 以上的紧急车辆的数量R30. int numBeds() - 确定以防紧急事件这个城市能够调遣的移动床位的数量R27. int numPassengers() 确定以防紧急事件这个城市可转移的乘客人数. 2.8 Testing(测试) 主函数要求能够获得供议会做决定的计算结果int main()

21、list vehicleList; LoadVehicle* lv1 = new LoadVehicle();back(lv1); PassengerVehicle* pv1 = new PassengeVehicle();back(pv1); .EmergencyVehicle* ev1 = new EmergencyVehicle();back(ev1); .Decision decision(vehicleList); (); () ; () ; () ; (); delete lv1; delete pv1; delete ev1; return 0; 11. 写一个学生类, 从 pe

22、rson 类继承, 增加的属性为成绩f 和评语 label字符串。person: name,age,print() #include 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 6 页,共 24 页class person private: char *name; int age; public: person(char *name=,int age=0) this-name=name; this-age=age; void print() cout :name 年龄: age; person()coutPerson destructorend

23、l; ; class student:public person private: double f; char *label; public: student(char *n=,int a=0,double b=0,char *c=):person(n,a),f(b),label(c) void print() person:print(); cout 成绩: f 评语: labelendl; student()coutStuent destructorendl; ; void main() person a1; student d1(张三 ,16,89.5, 优秀 ); a1=d1; a1

24、.print(); coutendl; d1.person:print(); coutendl; d1.print(); 运行结果:精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 7 页,共 24 页:张三年龄: 16 :张三年龄: 16 :张三年龄: 16 成绩: 89.5 评语:优秀Stuent destructor Person destructor Press any key to continue exercise15 12. Person 为基类:虚函数为dailywork() Person() 定义三个子类:Student Docto

25、r(char* label) Driver(char* label) 主函数:定义基类指针数组,动态创建子类对象,调用成员函数,删除创建的对象。#include class Person public: Person(char *name=,int age=0) this-name=name; this-age=age; virtual void dailywork()cout: name 年龄: age; virtual Person()couterson destructorendl; private: char *name; int age; ; class Student:public

26、 Person public: Student(char *n=,int a=0,char *c=)erson(n,a),label(c) void dailywork() Person:dailywork(); cout 学生 ; cout 评语: labelendl; Student()coutStuent destructorendl; private: char *label; ; class Doctor:public Person 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 8 页,共 24 页public: Doctor(char

27、 *n=,int a=0,char *c=)erson(n,a),label(c) void dailywork() Person:dailywork(); cout 医生 ; cout 评语: labelendl; Doctor()coutDoctor destructorendl; private: char* label; ; class Driver:public Person public: Driver(char *n=,int a=0,char *c=)erson(n,a),label(c) void dailywork() Person:dailywork(); cout 司机

28、 ; cout 评语: labelendl; Driver()coutDriver destructorendl; private: char* label; ; void main() Student *s=new Student(张三 ,15, 好); Doctor *d1=new Doctor(李四 ,45, 认真 ); Driver *d2=new Driver(王五 ,35, 优秀 ); Person *array3; array0=s; array1=d1; array2=d2; for(int i=0;idailywork(); delete array0; delete arr

29、ay1; delete array3; 运行结果:精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 9 页,共 24 页:张三年龄: 15 学生评语:好:李四年龄: 45 医生评语:认真:王五年龄: 35 司机评语:优秀Stuent destructor Person destructor Doctor destructor Person destructor Driver destructor Person destructor Press any key to continue exercise16 13. 修改类 Figure , 将 Poin

30、t 对象指针作为属性组合进来,对 Figure 的子类也做相应的修改。#include class Point private: double x,y; public: Point(double i,double j):x(i),y(j) void print() const cout(x,y); Point()coutPoint析构 endl; ; class Figure private: Point *str; Point center; public: Figure(double i=0,double j=0):center(i,j) Point& location() str=&ce

31、nter; return *str; void move(Point p) str=¢er; str=&p; draw(); 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 10 页,共 24 页virtual void draw() =0; virtual void rotate(double)=0; virtual Figure()coutFigure析构 endl; ; class Circle:public Figure private: double radius; public: Circle(double i=0,double

32、 j=0,double r=0):Figure(i,j),radius(r) void draw() couta circle with center; location().print(); coutand radiusradiusendl; void rotate(double)coutno effectendl; Circle()coutCircle析构 endl; ; class Square:public Figure private: double side,angle; public: Square(double i=0,double j=0,double r=0,double

33、a=0):Figure(i,j),side(r),angle(a) void draw() couta square with center; location().print(); coutside lengthsideendlThe angle between one side and the X-axis isangleendl; void rotate(double a) angle+=a; coutThe angle between one side and the X-axis isangleendl; void vertices() coutThe vertices od the

34、 square are:endl; 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 11 页,共 24 页 Square()coutSquare析构 draw(); f-move(Point(2,2); (); (1); (); 运行结果:a circle with center(1,2)and radius3 a circle with center(1,2)and radius3 Point 析构Point 析构a square with center(4,5)side length6 The angle between one side an

35、d the X-axis is0 The angle between one side and the X-axis is1 The vertices od the square are: Square 析构Figure 析构Point 析构Circle 析构Figure 析构Point 析构Press any key to continue /* 在 Complex 类中实现:重载= ,!=*/ answer :#include class Complex public: Complex(int i=0)x=i; friend int operator =(Complex c1,Comple

36、x c2); 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 12 页,共 24 页friend int operator !=(Complex c1,Complex c2); void display(); private: int x; ; void Complex:display() coutx; int operator =(Complex c1,Complex c2) if(c1.x=c2.x) return 1; else return 0; int operator !=(Complex c1,Complex c2) if(c1.x!

37、=c2.x) return 1; else return 0; void main() Complex c1(6),c2(8); if(c1=c2) c1.display();coutis equal to;c2.display(); coutendl; if(c1!=c2) c1.display();coutisnt equal to;c2.display(); coutendl; run result :6isnt equal to8 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 13 页,共 24 页本帖最后由陶亮 于 2013-11-30

38、 16:31 编辑/* 1. 实现一个字符串类String ,功能包括:1、Big Three: 析构函数 Destructor 复制构造函数copy constructor复制赋值运算符copy assignment operator2、下标操作符重载 : 只能作为类的成员函数,不能作为类的友元函数。3、输入输出操作符重载4、= 操作符重载5、+ 操作符重载参考 Vector 类*/ answer :#include #include class String public: String()str=NULL; String(int m):len(m) str=new charlen; St

39、ring(char *s) str = new charstrlen(s)+1; strcpy(str,s); len=strlen(s); String& operator+(String& c); friend istream& operator(istream& is,String& c); friend ostream& operatorlen-1) cout整数下标越界endl; return ch; else return *(str+n); void Disp() coutstrendl; void print() cout(istream& is,String& c) is;

40、return is; ostream& operator(ostream& os,String& c) (); return os; 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 15 页,共 24 页 int operator =(String &c1,String &c2) if(c1.len=c2.len) return 1; else return 0; void main() String word(this is a c+ program.); (); cout位置 0:word0endl; cout 位置 15:word15endl

41、; cout 位置 25:word25endl; word0=t; (); int f =10; String word2(f); for(int i=0;i10;i+) word2=word; word2.Disp(); String s1(8),s2(5); couts1; cins2; cout你输入的两个值分别为:; couts1endl; couts2endl; if(s1=s2) s1.print(); coutis equal to; 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 16 页,共 24 页 s2.print(); co

42、utendl; (s1+s2).print(); run result :this is a c+ program. 位置 0:t 位置 15:r 整数下标越界位置 25:this is a c+ program. this is a 输入两个整数值2 2 你输入的两个值分别为:2 2 2is equal to2 4Press any key to continue 1. 在 Complex 类中实现:重载-= ,*= ,/= 操作符。answer :#include class Complex public: Complex() Complex(double r,double i) real

43、 = r; image = i; Complex operator -=(Complex& t); Complex operator *=(Complex& t); Complex operator /=(Complex& t); Print(); private: double real; 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 17 页,共 24 页 double image; ; Complex Complex: operator -=(Complex& t) real-=; image-=; return *this; Comple

44、x Complex: operator *=(Complex& t) real*=; image*=; return *this; Complex Complex: operator /=(Complex& t) real/=; image/=; return *this; Complex: Print() if(image0) coutrealimageiendl; else coutreal+imageiendl; coutendl; void main() Complex c1(10.0,20.0),c2(5.0,4.0),c3(5.1,4.5); c1-=c2; c1.Print();

45、 c2*=c3; c2.Print(); c3/=c1; c3.Print(); run result :5+16i 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 18 页,共 24 页25.5+18i Press any key to continue 8. 实现一个字符串类String ,功能包括:1。Big Three 2。下标操作符重载3。输入输出操作符重载4。= 操作符重载5。+ 操作符重载参考 Vector 类#include #include class MyString public: MyString(char *s) str=

46、new charstrlen(s)+1; strcpy(str ,s); len=strlen(s); MyString(int m) len=m; str=new charlen; MyString() delete str; char & operator(int n) static char ch=0; if(nlen-1) cout整数下标越界; return ch; else return *(str+n); 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 19 页,共 24 页friend ostream& operator (istr

47、eam& in,MyString& x); MyString operator+ (MyString& x); friend bool operator=(MyString& a,MyString& b); private: int len; char *str; ; istream& operator (istream& in,MyString& x) in; return in; ostream& operator (ostream& out,MyString& a) outtstr); return strcat(str1,x.str); delete str1; *str1=NULL;

48、 bool operator=(MyString& a,MyString& b) bool yes=true; if(strlen()!=strlen()yes=false; else int index=0; int s=strlen(); while(indexs&aindex=bindex) +index; 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 20 页,共 24 页if(indexs) yes=false; return yes; void main() MyString a(100),b(heleo),c(heleo); cou

49、ta; couta: aendl; coutb: bendl; coutc: cendl; cout:位置 9b9endl; coutb+c: b+cendl; if(b=c)coutb等于 cendl 运行结果:输入字符串: ujgyj a: 100 ujgyj b: 5 heleo c: 5 heleo 整数下标越界 :位置 9 b+c: 10 heleoheleo b 等于 c /* 在 Complex 类中实现:重载-*/ answer :#include class Complex public: Complex(int i=0)x=i; Complex operator -();

50、/ 前置单目运算符 Complex operator -(int); / 后置单目运算符 void Display() coutxendl; private: 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 21 页,共 24 页 int x; ; Complex Complex: operator -() / 前置单目运算符 -x; return *this; Complex Complex: operator -(int) /后置单目运算符 Complex c; = x-; return c; void main() Complex c1(5)

51、,c2(5),c3,c4; int i; c3 = c1-; / 后置单目运算符 coutc3=; c3.Display(); c4 =-c2; / 前置单目运算符 coutc4=; c4.Display(); run result :c3=5 c4=4 Press any key to continue * 在 Complex 类中实现:以 -重载为基础,去重载-= ,-*/ answer :#include class Complex public: Complex(int i=0)x=i; 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 22

52、 页,共 24 页Complex operator -(Complex complex); Complex operator -=(Complex c); Complex operator -(); Complex operator -(int); void Print(); private: int x; ; Complex Complex: operator -(Complex complex) Complex c; = x-; return c; Complex Complex: operator -=(Complex c) x=x-; return x; Complex Complex

53、: operator -() -x; return *this; Complex Complex: operator -(int) Complex c2; c2=x-; return c2; void Complex: Print() coutxendl; void main() Complex c1(20),c2(5),c3,c4,c5; c1.Print(); c3=c1-c2; c3.Print(); 精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 23 页,共 24 页 c1-=c3; c1.Print(); c4=c1-; c4.Print(); c5 =-c4; c5.Print(); run result :20 15 5 5 4 Press any key to continue精选学习资料 - - - - - - - - - 名师归纳总结 - - - - - - -第 24 页,共 24 页

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号