9. Imagine a tollbooth at a bridge. A Car passing by the booth is expected to pay a toll. The tollbooth keeps the track of the number of cars that gone by and the total amount of cash collected. Create a class tollbooth with the data members as:- -total number of cars passed. -total toll collected. Write necessary member functions: 1. a constructors that initializes both data members to zero. 2. paying car(): when any car passes through the tollbooth,that much toll gets added into total toll collected and total number of cars passed is incremented by one. 3. nonpaying car(): increments the car total but adds nothing to cash total. 4. display (): displays total no. of cars passed and the total amount collected.


#include<iostream.h>
#include<conio.h>
#include<string.h>
class car
{
public:
int cars,cash;
car()
{
cars=0;
cash=0;
}
void pcar()
{
cout<<“\nEnter the amount of toll:”;
cin>>cash;
cash=cash+cash;
cars++;
}
void npcar()
{
cars++;
}
void disp()
{
cout<<” \n\ninformation about the tollbooth\n\n”;
cout<<“\tTollamount\tNoof passing cars\n\n”;
cout<<“\t”<<cash<<“\t\t\t”<<cars;

}
};
void main()
{
car ob1;
int num;
char ch=’y’;
clrscr();
while(ch==’y’)
{
cout<<“\n\nEnter the informayion about the toolbooth”;
cout<<“\n1.for paying cars:”;
cout<<“\n2.for non paying cars:”;
cout<<“\n3.for display the collected information:”;
cout<<“\n4.for exit\n”;
cin>>num;
switch(num)
{
case 1:
ob1.pcar();
break;
case 2:
ob1.npcar();
break;
case 3:
ob1.disp();
break;
case 4:
goto a;
}
cout<<“\t\t\tWant to perform more oprations(y/n)?”;
cin>>ch;
}
a:getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s