//编写一个程序实现公路收费功能,根据输入的车型
//1:小客车 2:卡车 3:公汽 统计 收费金额
//void cars() 统计小客车的车辆数和收费小记
//void trucks()统计卡车的车辆数和收费小记
//void buss() 统计公汽的车辆数和收费小记
//void process()收费处理
//void display() 输出收费统计信息
#include<iostream.h>
const int unitcar=10;
const int unittruck=25;
const int unitbus=15;
class Free
{
int car,carfee;
int truck,truckfee;
int bus,busfee;
public:
Free()
{
car=carfee=truck=truckfee=bus=busfee=0;
}
void cars()
{
car++;
carfee+=unitcar;
}
void trucks()
{
truck++;
truckfee+=unittruck;
}
void buss()
{
bus++;
busfee+=unitbus;
}
void process()
{
int no,n=0;
cout<<"1:卡车 2:卡车 3:公汽 0:退出"<<endl;
while(1)
{
cout<<" "<<++n<<"-车型:";
cin>>no;
switch(no)
{
case 0:break;
case 1:cars();break;
case 2:trucks();break;
case 3:buss();break;
default:cout<<"车型输入有误!"<<endl;
}
if(no==0)
break;
}
}
void display()
{
cout<<"收费统计如下: "<<endl;
cout<<"小客车: "<<car<<"辆收费小计:"<<carfee<<endl;
cout<<"卡车: "<<truck<<"辆收费小计:"<<truckfee<<endl;
cout<<"公汽: "<<bus<<"辆收费小计:"<<busfee<<endl;
cout<<"收费合计: "<<carfee+truckfee+busfee<<endl;
}
};
void main()
{
Free obj;
obj.process();
obj.display();
}