# PTA.汽车收费（多态）

4-1 汽车收费（多态）

class Vehicle

{

protected:

string NO;


public:

Vehicle(string n){

NO = n;

}

virtual int fee()=0;//计算应收费用

};

Car的收费公式为： 载客数*8+重量*2

Truck的收费公式为：重量*5

Bus的收费公式为： 载客数*3

### 输入样例：

4
1 002 20 5
3 009 30
2 003 50
1 010 17 6


### 输出样例：

002 170
009 90
003 250
010 148

#include<iostream>
#include <string>
using namespace std;
class Vehicle
{
protected:
string NO;//编号
public:
Vehicle(string n){				    NO = n;  }
virtual int fee()=0;//计算应收费用
};

class Car:Vehicle
{
public:
int guest,weight;
Car(string no1,int guest1,int weight1):Vehicle(no1)
{
weight=weight1;
guest=guest1;
}
int fee()
{
return guest*8+weight*2;
}
};
class Truck:Vehicle
{
public:
int weight;
Truck(string no1,int weight1):Vehicle(no1)
{
weight=weight1;
}
int fee()
{
return weight*5;
}
};
class Bus:Vehicle
{	public:
int guest;
Bus(string no1,int guest1):Vehicle(no1)
{
guest=guest1;
}
int fee()
{
return guest*3;
}
};
int main()
{
Car c("",0,0);
Truck t("",0);
Bus b("",0);
int i, repeat, ty, weight, guest;
string no;
cin>>repeat;
for(i=0;i<repeat;i++){
cin>>ty>>no;
switch(ty){
case 1: cin>>guest>>weight; c=Car(no, guest, weight); cout<<no<<' '<<c.fee()<<endl; break;
case 2: cin>>weight; t=Truck(no, weight); cout<<no<<' '<<t.fee()<<endl; break;
case 3: cin>>guest; b=Bus(no, guest); cout<<no<<' '<<b.fee()<<endl; break;
}
}
return 0;
}