#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class tollbooth
{
int no_of_car;
int tot_toll;
public:
       tollbooth()
       {
no_of_car = 0;
tot_toll = 0;
       }
       void car_passes();
       void paying_car(void);
       void non_paying_car(void);
       void display(void);
};

void tollbooth :: car_passes()
{
char cartype;
cout<<"\n\nEnter Car Type Paying car(P) & Nonpaying car(N) : ";
cin>>cartype;
if(cartype=='P'||cartype=='p')
paying_car();
else if(cartype=='N'||cartype=='n')
non_paying_car();
}

void tollbooth :: paying_car(void)
{
tot_toll=tot_toll+50;
no_of_car=no_of_car+1;
}
void tollbooth :: non_paying_car(void)
{
no_of_car=no_of_car+1;
}
void tollbooth :: display()
{
cout<<"\n\nTotal number of cars passed :"<<no_of_car;
cout<<"\n\nTotal amount collected :"<<tot_toll;
}

int main()
{
tollbooth t;
int ch;
clrscr();
do
{
cout<<"\nMenu";
cout<<"\n1. Car Passes";
cout<<"\n2. Display";
cout<<"\n3. Exit";
cout<<"\nEnter your choice";
cin>>ch;
switch(ch)
{
case 1: t.car_passes();
break;
case 2: t.display();
break;
case 3:exit(0);
}
}while(ch!=3);
getch();
return 0;
}

Post a Comment

Previous Post Next Post