資源簡介
//編寫一個程序實現公路收費功能,根據輸入的車型
//1:小客車 2:卡車 3:公汽 統計 收費金額
//void cars() 統計小客車的車輛數和收費小記
//void trucks()統計卡車的車輛數和收費小記
//void buss() 統計公汽的車輛數和收費小記
//void process()收費處理
//void display() 輸出收費統計信息
#include
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<>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();
}
代碼片段和文件信息
評論
共有 條評論