Imagine a ticket Selling booth at a fair. People passing by are requested to purchase a ticket. A ticket is priced as Rs. 5/- . The ticketbooth keeps the track of the number of peoples that have visited the booth and of the total amount of cash collected. Create a class ticketbooth that contains No_of_people_visited, Total_Amount_collected. Write C++ program to perform following functions: i. To assign initial values. ii. To increment the No_of_people_visited if visitors have just visited the booth. iii. To increment the No_of_people_visited and Total_amount_collected if tickets have been purchased. iv. To display both totals
//Note: If you are not using Borland or Turbo C then add the following line after header files :
//using namespace std;
#include<conio.h>
#include<iostream.h>
class tb // tb=ticket booking
{
int visit;
int amt;
int v; // v= visitors who purchase tickets
int p,n,per,c; //p=person no , c=Ticket count , per=per ticket value , amt=amount , visit=only visit
char a[4];
public:
tb() //constructor
{
visit=0;
amt=0;
v=0;
per=5;
p=0;
c=0;
}
void acc()
{
p++;
cout<<"\nYou want to purchase ticket(yes/no) :- ";
cin>>a;
if((strcmp(a,"yes"))==0)
{
cout<<"\nHow many tickets you want:";
cin>>c;
}
}
void vincre()
{
if((strcmp(a,"no"))==0)
{
visit++;
cout<<"\n=================Ok,no problem===============";
}
else
{
v++;
amt=amt+(per*c);
cout<<"\n**************Thanks for purchasing****************";
}
}
void onlyv() //only visitors function
{
cout<<"\nTotal visitors who are not purchase tickets : "<<visit;
}
void pur()
{
cout<<"\nTotal person who visit : "<<p;
cout<<"\nTotal person who purchase tickets : "<<v;
cout<<"\nTotal amt : "<<amt;
}
};
void main()
{
int ch;
tb b1; //object created
do
{
cout<<"\n\n1.welcome to booth.\n2.display who not purchase\n3.display all\n4.Exit\nenter your choice.";
cin>>ch;
switch(ch)
{
case 1: b1.acc();
b1.vincre();break;
case 2: b1.onlyv();break;
case 3: b1.pur();break;
}
}while(ch!=4);
}
0 Comments