/*write c++ program for imagine a toobath at a bridge. a car passing by the booth
is expected to pay a toll. the toolbooth keeps the track of the number
car that gone and total cash amount collected.
create a class toolbooth with the data member
-total number of cars passed
-total toll collected
write necessary member function
1.a constructor tha initialises both data member to zero.
2.paying ca(): when any cars passes through the toolbath. that much
toll gets added into total toll collected and total number of cars passed is
incremented by one
3. nonpaying car(); increment the car total but adds nothing to cash total
4.display(); the total number car passed and total cash collected
*/
#include<iostream.h>
#include<conio.h>
class toolbath
{
int noc,tot;
public:toolbath(int n=0,int t=0)
{
noc=n;
tot=t;
}
void pay()
{
int i;
noc++;
cout<<"\nenter the amount to pay toll:-";
cin>>i;
tot=tot+i;
}
void non_pay()
{
noc++;
}
void display()
{
cout<<"\ntotal number of car passed:-"<<noc;
cout<<"\ntotal toll collected:-"<<tot;
}
};
int main()
{
int n,t,ans;
char ch='y';
clrscr();
cout<<"\nenter total number of car passed:-";
cin>>n;
cout<<"\nenter total toll collected:-";
cin>>t;
toolbath b(n,t);
while(ch=='y'||ch=='Y')
{
cout<<"\nenter the car type:-";
cout<<"\npress 1: for paying car";
cout<<"\npress 2: for non-paying car";
cin>>ans;
if(ans==1)
b.pay();
if(ans==2)
b.non_pay();
cout<<"\ndo you want to continue(Y|N):-";
cin>>ch;
}
b.display();
getch();
return 0;
}
/*
enter total number of car passed:-123
enter total toll collected:-7478
enter the car type:-
press 1: for paying car
press 2: for non-paying car1
enter the amount to pay toll:-12
do you want to continue(Y|N):-y
enter the car type:-
press 1: for paying car
press 2: for non-paying car1
enter the amount to pay toll:-14
do you want to continue(Y|N):-y
enter the car type:-
press 1: for paying car
press 2: for non-paying car2
do you want to continue(Y|N):-n
total number of car passed:-126
total toll collected:-7504
*/
is expected to pay a toll. the toolbooth keeps the track of the number
car that gone and total cash amount collected.
create a class toolbooth with the data member
-total number of cars passed
-total toll collected
write necessary member function
1.a constructor tha initialises both data member to zero.
2.paying ca(): when any cars passes through the toolbath. that much
toll gets added into total toll collected and total number of cars passed is
incremented by one
3. nonpaying car(); increment the car total but adds nothing to cash total
4.display(); the total number car passed and total cash collected
*/
#include<iostream.h>
#include<conio.h>
class toolbath
{
int noc,tot;
public:toolbath(int n=0,int t=0)
{
noc=n;
tot=t;
}
void pay()
{
int i;
noc++;
cout<<"\nenter the amount to pay toll:-";
cin>>i;
tot=tot+i;
}
void non_pay()
{
noc++;
}
void display()
{
cout<<"\ntotal number of car passed:-"<<noc;
cout<<"\ntotal toll collected:-"<<tot;
}
};
int main()
{
int n,t,ans;
char ch='y';
clrscr();
cout<<"\nenter total number of car passed:-";
cin>>n;
cout<<"\nenter total toll collected:-";
cin>>t;
toolbath b(n,t);
while(ch=='y'||ch=='Y')
{
cout<<"\nenter the car type:-";
cout<<"\npress 1: for paying car";
cout<<"\npress 2: for non-paying car";
cin>>ans;
if(ans==1)
b.pay();
if(ans==2)
b.non_pay();
cout<<"\ndo you want to continue(Y|N):-";
cin>>ch;
}
b.display();
getch();
return 0;
}
/*
enter total number of car passed:-123
enter total toll collected:-7478
enter the car type:-
press 1: for paying car
press 2: for non-paying car1
enter the amount to pay toll:-12
do you want to continue(Y|N):-y
enter the car type:-
press 1: for paying car
press 2: for non-paying car1
enter the amount to pay toll:-14
do you want to continue(Y|N):-y
enter the car type:-
press 1: for paying car
press 2: for non-paying car2
do you want to continue(Y|N):-n
total number of car passed:-126
total toll collected:-7504
*/
No comments:
Post a Comment