车辆管理系统

  • 格式:docx
  • 大小:73.18 KB
  • 文档页数:24

C++项目:车辆管理系统目标:写一个小程序,要求到用标准模板库中的list容器和迭代器,可以使用到多继承来进行实验。

1.1 General(概述)1.在写代码之前要仔细阅读作业要求2.要求对不正确的输入做检查3.在你写完一个类之后,要紧接着写这个类的测试函数,因此,当你调试你写的代码的时候,你能够很容易的对你的代码做重复检查。

这样才能够保证你当前写的代码能够准确无误的执行。

可能出于某些原因你要对你写过的代码作一此些修改,这样你重新测试你修改的代码就相对比较容易。

4.添加完成你的任务所需要的函数。

1.2 Introduction(简介):渥太华这个城市正在创建一个有关交通工具的“数据库”,来为它的议会(委员会)做预算提供较好的参考。

这个城市有许多不同种类的机动车辆:客车,货车,卡车,紧急车辆(救护,消防等),在对这个城市了解之后,要求你设计一个有下图要求的层次的系统。

2 Implement the following functions for each class:为每个类实现以下函数2.1 (Vehicle类) (属性:所有的属性要求为私有的)char licensePlate[]属性:车的车牌(执照)作为它的id,一个车牌最多可由8组成。

char *type属性:车辆类型(例如:汽车,卡车,消防车)char *make属性:车辆的制造商double gasTankSize属性:总油量double fuelConsumption属性:单位路程耗油量函数:R1. 构造函数vehicle(char *type, char* licensePlate, double gasTankSize, double fuelConsumption)Tppe的默认值为:carlicensePlate的默认值为: ottawa01gasTankSize的默认值为: 100fuelConsumption的默认值为: 10所有其他不在构造函数中的参数要求置0或置空R2. voidsetMake(char *make);设置制造商的值R3. setFuelData(double gasTankSize, double fuelConsumption) –设置燃料的有关信息(总油量,单位路程耗油量)R4. setType(char *type) –设置车辆类型R5. setLicensePlate(char *license) –设置车辆的车牌R6. virtual printSpecifications() - 打印车辆的具体信息,例如:制造商、类型,车牌,燃油量和油箱容积R7. virtual double computeTravelDistance() –这个函数计算车辆可能行使的距离,计算公式为:gasTankSize * fuelConsumption(总油量*单位路程耗油量)2.2Class LoadVehicle:( LoadVehicle类)Attributes(属性)intnumberOfWheels– contains the number of wheels that the vehicle has. intnumberOfWheels属性:车辆的车轮个数double 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:车辆能够拖曳的重量FunctionsR8. loadVehicle(char *type, intnumberOfWheels, double loadCapacity, doubletowingCapacity, double gasTankSize, double fuelConsumption).A constructor for the class. The default values for numberOfWheels, loadCapacity andtowingCapacity are 6, 500kg and 5000kg respectively. The default values for gasTankSize and fuelConsumption are 200 and 6 respectively. The constructor willinitialize all the fields of the class as required. All other member variables that are notinitialized should be set to the default values of the base class(es), or, if no defaultvalues exist, to 0 or NULL.这个类的构造函数,各个属性的默认值:loadCapacity的默认值:6, 500kgtowingCapacity的默认值:5000kggasTankSize的默认值:200fuelConsumption的默认值: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 thenumber of wheels).打印出车辆的具体信息,包括从基类继承的和它自身的。

R11. doublecomputeTravelDistance– every pair of wheels above four reduces thetravel distance by 5% (travelDistance = gasTankSize*fuelConsumption*(100- (numberOfWheels-4)/2*5)/100). For example: if the gasTankSize if 100 litres, thefuelConsumption 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 passengerVehicle: (passengerVehicle类)AttributesintnumberOfPassengers– contains the number of passengers that the vehicle canCarryintnumberOfPassengers属性:车辆可搭乘的乘客的数量Functions(函数)R12. passengerVehicle(char *type, intnumPassengers, double gasTankSize, doublefuelConsumption)– The default values for numPassengersis 5. The default values forgasTankSize and fuelConsumption are 100 and 11 respectively. The constructorwill 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.该类的构造函数,成员变量的默认值:numPassengers的默认值:5gasTankSize的默认值:100fuelConsumption的默认值:11要用基类的构造函数对要求有默认值的属性进行初始化,没其他没有初始化的成员要置0或置空R13. setNumPassengers(intnumPassengers)设置可搭乘的乘客人数R14. printSpecifications() – print the specification of the vehicle (the vehicle specification from the vehicle class, and the number of passengers).打印车辆的具体信息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(属性)intnumWorkers属性:为每辆车分配的工作人员char *driver属性:为车辆分配的驾驶员char *station属性:车辆停靠的车站FunctionsR16. emergencyVehicle(char *type, char*driver, char *station, intnumPassengers,doublegasTankSize, double fuelConsumption)–构造函数,部分属性平的默认值:fornumPassengers的默认值:5gasTankSize的默认值:100fuelConsumption的默认值:11wheels 的默认值:6其他没有给初始值的属性要求置0或置空.R17. setAssignment(char *driver, char *station)设置分配(司机,停靠站)R18. printSpecifications() –打印的车辆(车辆规范规格从车辆类,该loadvehcile,客运车辆和emergencyequipment类)。