This C++ program defines a Toolbooth class to track the number of cars that pass through, pay, and do not pay. The class initializes counters to zero, increments the appropriate counter for pay or non-pay calls, and displays the totals. The main function prompts for input, calls the paycar or nonpaycar methods, and finally displays the results.
This C++ program defines a Toolbooth class to track the number of cars that pass through, pay, and do not pay. The class initializes counters to zero, increments the appropriate counter for pay or non-pay calls, and displays the totals. The main function prompts for input, calls the paycar or nonpaycar methods, and finally displays the results.
class toolbooth { private: unsigned int totalcar,givecar,freecar; double totalcash; public: toolbooth () { totalcar=0; givecar=0; totalcash=0; freecar=0; } void paycar() { totalcar++; givecar++; totalcash=totalcash+50; } void nonpaycar() { freecar++; totalcar++; } void show() { cout<<"Total cars pass (including pay and non pay) =="<<totalcar<<endl; cout<<"Number of cars that NOT pay=="<<freecar<<endl; cout<<"Number of cars that pay=="<<givecar<<endl; cout<<"One Car Paid == 50"<<endl; cout<<"Total amount of paing cars =="<<totalcash<<endl; } }; int main() { toolbooth count; int x; do { cout<<"Enter 1 for payingcar and 2 for non payingcar and for leaving press 0== "; cin>>x; if (x==1) { count.paycar(); } if(x==2) { count.nonpaycar(); } } while (x!=0); count.show(); return 0; }