![]()
#include<iostream>
#include <string>
using namespace std;
class Vehicle
{
protected:
string NO;//编号
public:
Vehicle(string n){ NO = n; }
virtual int fee()=0;//计算应收费用
};
class Car:public Vehicle
{
public:
Car(string no,int guest,int weight):Vehicle(no)
// 不知道为啥要加一个:Vehicle(no),哪个大神可以讲解一下
{
m_no=no;
m_guest=guest;
m_weight=weight;
}
virtual int fee()
{
return (m_guest*8+m_weight*2);
}
private:
string m_no;
int m_guest,m_weight;
};
class Truck:public Vehicle
{
public:
Truck(string no,int weight):Vehicle(no)
{
m_no=no;
m_weight=weight;
}
virtual int fee()
{
return (m_weight*5);
}
private:
string m_no;
int m_weight;
};
class Bus :public Vehicle
{
public:
Bus(string no,int guest):Vehicle(no)
{
m_no=no;
m_guest=guest;
}
virtual int fee()
{
return (m_guest*3);
}
private:
string m_no;
int m_guest;
};
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;
}
![]()
class Shape
{
public:
Shape(){}
virtual ~Shape(){}
virtual float area() = 0;
};
class Circle:public Shape{
private:
int x, y;
float radius;
public:
Circle(int x, int y, float radius)
{
this->x = x; this->y = y; this->radius = radius;
}
~Circle(){}
float area(){
return 3.1415926f * radius * radius;
}
};
class Rectangle:public Shape{
private:
int width, height;
public:
Rectangle(int w, int h){
width = w;
height = h;
}
~Rectangle(){}
float area(){
return width*height;
}
};