Hot Search : Source embeded web remote control p2p game More...
Location : Home Search - car
Search - car - List
有一个汽车类vehicle,它具有一个需传递参数的构造函数,类中的数据成员——车轮个数wheels和车重weight放在保护段protected中;它有一个返回车轮个数的公有函数get_wheels,有一个返回车重的公有函数get_weight,有一个计算每个车轮的承载重量(车重除以车轮数)的公有函数wheel_load,一个公有的打印函数print,它将输出vehicle的车轮数和重量。 小车类car是它的私有派生类,包含一个私有数据成员载客量passenger_load,定义小车类的构造函数,一个获得载客量数目的公有成员函数get_passengers,一个公有的打印函数,它将输出小车的车轮数、重量和载客量。 卡车类truck也是它的私有派生类,包含两个私有数据成员载客量passenger_load和载重量payload,定义卡车类的构造函数,一个获得卡车载客量的公有函数get_passengers,一个获得卡车载重效率的公有函数efficiency(计算方法为载重量/(载重量+卡车本身的重量),一个公有的打印函数print,它将输出卡车的车轮数、重量、载客量和卡车载重效率)。 在car类和truck类中均可以直接访问vehicle类中的wheels和weight。 主函数中定义小车类对象car1(4,1000,5),卡车类对象tru1(10,5000,3,34000),然后调用car1和tru1的print函数。-There is a car class vehicle, it has a need to pass parameters to the constructor, the class data members- the number of wheels and vehicle wheels, heavy weight on the protection of the protected segment it has a number of public functions to return the wheel get_wheels, there is a return to the public function of vehicle weight get_weight, there is a calculation of the weight of each wheel load (vehicle weight divided by the number of wheels) in the public function of wheel_load, a public print function of print, it will output the number and weight of vehicle wheels. Car class car is its private derived class that contains a private data member patronage passenger_load, the definition of small car class constructor, a number of public access to patronage member functions get_passengers, a public print function, it will output trolley wheel number, weight and capacity. Pickup truck is also its private derived class contains two private data members of the load carrying capacity p
Date : 2025-12-17 Size : 1kb User : zengzeng
CodeBus is one of the largest source code repositories on the Internet!
Contact us :
1999-2046 CodeBus All Rights Reserved.