make solution of this question

Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay a 50 Rs toll. Mostly they do, but sometimes a car goes by without paying. The tollbooth keeps track of the number of cars that have gone by, and of the total amount of money collected. Model this tollbooth with a class called tollBooth. The two data items are a type unsigned int to hold the total number of cars, and a type double to hold the total amount of money collected. A constructor initializes both of these to 0. A member function called payingCar() increments the car total and adds 0.50 to the cash total. Another function, called nopayCar(), increments the car total but adds nothing to the cash total. Finally, a member function called display() displays the two totals. Include a program to test this class. This program should allow the user to push one key to count a paying car, and another to count a nonpaying car. Pushing the Esc key should cause the program to print out the total cars and total cash and then exit.

2 answers

This is the class of your program……
class TollBooth
{
unsigned int TotalCars;
double TotalAmount;
public:
TollBooth()
{
TotalCars=0;
TotalAmount=0;
}
void PayingCar()
{
TotalCars++;
TotalAmount+=0.50;
}
void NoPayCar()
{
TotalCars++;
}
void Display()
{
cout<<“\nThe Total No of passing cars: “<<TotalCars;
cout<<“\nThe Total Amount Collected: “<<TotalAmount;
}
};

#1

You can use the condition in main function is …..
TollBooth Obj;
int c;
char ch;
do
{
cin>>c;
switch(c)
{
case 1:
Obj.PayingCar();
break;
case 2:
Obj.NoPayCar();
break;
default:
cout<<“Incorect input: “;
break;
}
}while((c=getche())!=27);
Obj.Display();

#2

Please login or Register to Submit Answer