C++初学者,刚开始类和成员函数那里的问题

img

img

img

img


上面两张是要求,下面是我自己写的,但写不下去了,刚接触C++,麻烦帮忙看一下,给个完整过程,如果能在代码旁给个详细一点的注释,那就真的太感谢了

你发图片,也是个人才啊,不能代码?

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退出