Imagine a ticket selling booth at a fair. People passing by are requested to purchase a ticket. A ticket is priced at Rs. 2.50. The booth keeps track of the number of people that have visited the fair and of the total amount of money collected. Model this ticket selling booth with a class tick. Include a program to rest this class



#include<iostream.h>
#include<conio.h>
#include<process.h>

class tick
{
               int nop;
               float total;
               public:
               tick()
               {
                              nop=0;
                              total=0;
               }
               void inc();
               void display();
               void displaynop();
};



void tick::inc()
{
               nop++;
               total+=2.50;
               cout<<"\nThe no. of people and the total have beem incremented";
}

void tick::display()
{
               cout<<"\nThe number of people who have entered the fair are:"<<nop<<endl;
               cout<<"The total amount collected till now is:"<<total<<endl;
}


void tick::displaynop()
{
               cout<<"The no. of people who have visited so far are:"<<nop<<endl;
}



int main()
{
               char ch='y';
               int choice;
               tick t1;

               l1:cout<<"\n\n\n\n1.Increment person and total"<<endl;
               cout<<"2.Display no. of people and the amount collected till now"<<endl;
               cout<<"3.Display no. of people who entered"<<endl;
               cout<<"4.Exit"<<endl;
               cout<<"Enter your choice:";
               cin>>choice;
               switch(choice)
               {
                              case 1:t1.inc();
                                             goto l1;
                                             break;
                              case 2:t1.display();
                                             goto l1;
                                             break;
                              case 3:t1.displaynop();
                                             goto l1;
                                             break;
                              case 4:exit(0);
                                     break;

               }
               return 0;
}

OUTPUT:

 
1.Increment person and total
2.Display no. of people and the amount collected till now
3.Display no. of people who entered
4.Exit
Enter your choice:1

The no. of people and the total have beem incremented



1.Increment person and total
2.Display no. of people and the amount collected till now
3.Display no. of people who entered
4.Exit
Enter your choice:1

The no. of people and the total have beem incremented



1.Increment person and total
2.Display no. of people and the amount collected till now
3.Display no. of people who entered
4.Exit
Enter your choice:2

The number of people who have entered the fair are:2
The total amount collected till now is:5




1.Increment person and total
2.Display no. of people and the amount collected till now
3.Display no. of people who entered
4.Exit
Enter your choice:3
The no. of people who have visited so far are:2




1.Increment person and total
2.Display no. of people and the amount collected till now
3.Display no. of people who entered
4.Exit
Enter your choice:4

No comments:

Post a Comment