PROGRAMMING:Car charges
Now we need to develop a system to manage the charging work for a variety of cars.
The following basic class framework is given
class Vehicle
{
protected:
string NO;// number
public:
virtual void display()=0;// Export receivable expenses
}
Car, truck and bus are constructed based on vehicle.
The charging formula of car is: carrying capacity * 8 + weight * 2
The charging formula of truck is: weight * 5
The charging formula of bus is: passenger capacity * 3
To generate the above class and write the main function, the main function should have a base class vehicle pointer array with no more than 10 elements.
Vehicle *pv[10];
The main function establishes car, truck or bus class objects according to the input information. For car, it gives the number of passengers and weight, truck gives the weight, and bus gives the number of passengers. Assume that the number of passengers and weight are integers
Input format: each test case occupies one line, each line gives the basic information of the car, each is the type of the current car, 1 is car, 2 is truck, 3 is bus. Next, number it. Next, car is the number of passengers and weight. Truck gives the weight and bus gives the number of passengers. The last line, 0, indicates the end of the input.
It is required to output the number and charge of each vehicle.
Hint: using virtual function to realize polymorphism
sample input
1 002 20 5
3 009 30
2 003 50
1 010 17 6
0
sample output
002 170
009 90
003 250
010 148
answer:If there is no answer, please comment
The following basic class framework is given
class Vehicle
{
protected:
string NO;// number
public:
virtual void display()=0;// Export receivable expenses
}
Car, truck and bus are constructed based on vehicle.
The charging formula of car is: carrying capacity * 8 + weight * 2
The charging formula of truck is: weight * 5
The charging formula of bus is: passenger capacity * 3
To generate the above class and write the main function, the main function should have a base class vehicle pointer array with no more than 10 elements.
Vehicle *pv[10];
The main function establishes car, truck or bus class objects according to the input information. For car, it gives the number of passengers and weight, truck gives the weight, and bus gives the number of passengers. Assume that the number of passengers and weight are integers
Input format: each test case occupies one line, each line gives the basic information of the car, each is the type of the current car, 1 is car, 2 is truck, 3 is bus. Next, number it. Next, car is the number of passengers and weight. Truck gives the weight and bus gives the number of passengers. The last line, 0, indicates the end of the input.
It is required to output the number and charge of each vehicle.
Hint: using virtual function to realize polymorphism
sample input
1 002 20 5
3 009 30
2 003 50
1 010 17 6
0
sample output
002 170
009 90
003 250
010 148
answer:If there is no answer, please comment