-->
当前位置:首页 > 题库

PROGRAMMING:Vehicle selection (inheritance)

Luz5年前 (2021-05-10)题库377
There is an automobile class vehicle, which has a constructor that needs to pass parameters. The data members in the automobile class vehicle are:
The number of wheels and vehicle weight are put in the protection section, and the public member function of vehicle is: get_ Wheels (), get_ Weight (), wheel_ Load () (return the value of load capacity of each tire: weight / wheels), print () (output the number of wheels and the number of kilos of vehicle weight);
Car class is a derivative of vehicle class, which has a constructor that needs to pass parameters. The private data member in car class is passenger_ Load, the public member function in car class is: get_ Passengers () (returns the number of people on board), print () (outputs the number of wheels, the number of kilos of vehicle weight and the number of people on board);
Truck class truck is a derivative of vehicle class. It has a constructor that needs to pass parameters. The private data member of truck class truck is passenger_ Load and payload. The public member function of truck class is: get_ Passengers (), efficiency (), and print (), respectively.
Generate the above class and write the main function, according to the basic information of the input vehicle, establish the vehicle object, and can calculate and output the basic information of the vehicle.
Input format: the test input contains a test case, and each line gives the basic information of a vehicle. The first character of each line is the type of the current vehicle, and the second number is the number of the current vehicle. If the vehicle is a vehicle, the following two numbers are wheels and weight. If the vehicle is a car, the following three numbers are wheels, weight and number of people on board, If the vehicle is a truck, the following four numbers are wheels, weight, number of people on board and carrying capacity( The above figures are all integers)- 1 indicates the end of input, and the corresponding result should not be output. Please pay attention to the output format and number them in the order of input
Note: in this question, if the tire load capacity and load efficiency need to be output, two decimal places will be reserved.
Input example:
vehicle 101 4 1900
car 201 4 2000 5
truck 301 6 3000 2 9000
car 202 4 1800 4
-1
Output example:
The 1st object is Vehicle No. 101: weight 1900 Kg and wheels 4
The 2nd object is Car No. 201: passenger_ load 5 weight 2000 Kg and wheels 4
The 3rd object is Truck No. 301: passenger_ load 2 weight 3000 Kg wheels 6 and efficiency 0.75
The 4th object is Car No. 202: passenger_ load 4 weight 1800 Kg and wheels 4






answer:If there is no answer, please comment