你发图片,也是个人才啊,不能代码?
class tollBooth
{
private:
int carCnt;
double payCnt;
public:
tollBooth()
{
carCnt = 0;
payCnt = 0;
}
void AddNonPayingCar()
{
carCnt++;
}
void AddPayingCar()
{
carCnt++;
payCnt += 0.5;
}
void Display()
{
cout << "car number is " << carCnt << ", paying is " << payCnt << endl;
}
};
int main()
{
tollBooth booth1;
char ch;
cout << "\nPress" << endl;
cout << "0 for each non-paying car, " << "\n 1 for each paying car." << "\nESC to exit the program\n";
while (true)
{
ch = getche();
if (ch == '0')
{
booth1.AddNonPayingCar();
}
else if (ch == '1')
{
booth1.AddPayingCar();
}
else if (ch == ESC)
{
booth1.Display();
break;
}
}
return 0;
}
问题没啥难度,就是读到0车辆计数+1,读到1车辆计数+1,计费+0.5,读到ESC退出