Saturday, 23 March 2019

CPP-EX51



Imagine a ticket selling booth at a fair.People passing by are requested            to purchase a ticket.A ticket is priced at 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. Write a 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. 

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
 class Ticketbooth
   {
    int No_of_people_visited;
    int Total_amount_collected;
    public:
    Ticketbooth()
      {
       No_of_people_visited=0;
       Total_amount_collected=0;
      }
    void payingpeople();
    void visitingpeople();
    void display();
   };
 void Ticketbooth::payingpeople()
   {
    No_of_people_visited=1+No_of_people_visited;
    Total_amount_collected=5+Total_amount_collected;
    return;
   }
 void Ticketbooth::visitingpeople()
   {
    No_of_people_visited=1+No_of_people_visited;
    return;
   }
 void Ticketbooth::display()
   {
    cout<<"\nTotal Number of people visited so far:"<<No_of_people_visited;
    cout<<"\nTotal amount collected so far:"<<Total_amount_collected;
    return;
   }
 int main()
   {
    Ticketbooth ticket;
    clrscr();
    int choice;
    cout<<"\n\n******** Ticket Selling booth at a fair. ***************";
    cout<<"\n***************** MENU ********************";
    cout<<"\n1.Increment the Number of people visited.";
    cout<<"\n2.Increment the Number of people visited and Total amount collected.";
    cout<<"\n3.Display both totals.";
    cout<<"\n4.Exit.";
    do
      {
       cout<<"\nEnter your choice:";
       cin>>choice;
       switch(choice)
             {
              case 1:
              ticket.visitingpeople();
              cout<<"\nNo of people visited have
             been incemented.";
              break;

              case 2:
              ticket.payingpeople();
              cout<<"\nNo of people visited and
            Total cash have been incremented.";
              break;

              case 3:
              ticket.display();
              break;

              case 4:
              exit(0);
              default:
              cout<<"\nYou entered wrong choice.";
             }
      }while(choice!=4);
    getch();
    return 0;
   }