Saturday 15 October 2016

C++ Projects: Theater Seat Booking system

Ticket Booking System in c++

This program is a implementation of Ticket Booking System using Doubly Circular Linked List. Data structures used in the program- Doubly Circular Linked List.
Why Dcll?
We know that in theatres more than 200 seats are there, Now if our head pointer points to the seat number ‘A1’ & user want to perform some operation with seat number ‘J1’ then it will be very much time consuming task ,as we need to traverse whole linked list from A1 to J7.








































Now when we use Doubly circular Linked List all seats are connected in a ring fasion so we can directly move from seat A1 to J7 using previous pointer as in previous pointer of head node address of seat J7 is stored.
















So lots of time gets saved which increases efficiency of the system.
FUNCTIONS USED : -
1] create() :- To create 70 nodes internally ( in memory ), each node represent one seat.Each node has 6 parameters
1) previous pointer of node* type to store address of previous node;
2) next pointer of node* type to store address of next node;
3) seat_no- to store seat number (int type)
4) row_no- to store row no(char type)
5)booking status- to show wether seat is alredy booked or available for booking(char type)
6)pin- different pin for each seat(int type)
So this function will create 70 nodes in memory locations & it will assign each node a
seat_no,booking_status and pin.
2] display() :- To display the seating arrangement ie to display the linked list.
The display will show row number followe by seat no followe by booking status (‘a’ or ‘b’ -> available/booked) of each seat/node.
“In display additional lines of codes are added to make display more powerful for LINUX TERMINAL”

inux terminal output of display function
3] book_seat() :- it will take input from user as seat no. If booking status of that seat is ‘a’  then avaibility status of that seat will change from (a) to (b) . else it will show an error message. If Seat is booked succesfully the it will display pin for each seat.


Linux terminal output of book_seat function

4] cancle_seat() :- the purpose of assigning pin to each seat is only one who has booked the seat can cancle it. So at the time of cancelation pins are required .
Now at cancelation time it wil ask for seat number and pin if seat number and pin combination matches and the avaibility status of that seat is booked then that seat will be cancled. Else it will give an error message.


Linux terminal output of cancle_seat() function

“RUN THIS CODE IN LINUX TERMINAL FOR BETTER OUTPUT EXPIRENCE”

CODE(for linux environment)

/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
DEVELOPER: RUSHIKESH SANJAY PHALKE
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
#include<iostream>
using namespace std;

typedef struct node
{
char row_no;
int seat_no,pin;
char book;
struct node *next,*prev;
}node;

class dcll
{
public:
node *hn;
dcll()
{
hn=NULL;
}
public:
void create()
{
node *nn,*cn;
int j=1;
volatile int k=2;
char c ='A';

do
{
int i=1;
do
{
k=(k*k)/10+100-k/2;
nn=new node();
nn->next=nn->prev=NULL;
nn->row_no=c;
nn->seat_no=i;
nn->pin=k;
nn->book='a';
if(hn==NULL)
{
hn=nn;
nn->next=nn->prev=hn;
}
else
{
cn=hn;

while(cn->next!=hn)
cn=cn->next;

cn->next=nn;
nn->prev=cn;
nn->next=hn;
hn->prev=nn;
}
i++;
}while(i<=7);
j++;
c++;
}while(j<=10);
}

void display()
{
node *cn;
cn=hn;
cout<<"------------------------------------------------------------------\n";
cout<<"|                            Platinum                            |\n";
while(cn->next!=hn)
{
if((cn->prev)->row_no!=cn->row_no)
cout<<"| ";
cout<<cn->row_no;
cout<<cn->seat_no;
if(cn->book=='a')
cout << "\033[32;40m -> a  \033[0m";  //green text with black background
else
cout << "\033[1;31;43m -> b  \033[0m";  //red text
if((cn->next)->row_no!=cn->row_no)
cout<<"|\n";
if(cn->row_no=='C'&&cn->seat_no==7)
{
cout<<"------------------------------------------------------------------\n";
cout<<"|                             gold                               |\n";
}
if(cn->row_no=='H'&&cn->seat_no==7)
{
cout<<"------------------------------------------------------------------\n";
cout<<"|                            Silver                              |\n";
}
cn=cn->next;
}
cout<<cn->row_no;
cout<<cn->seat_no;
if(cn->book=='a')
cout << "\033[32;40m -> a  \033[0m";  //green text with black background

else
cout << "\033[1;31;43m -> b  \033[0m";  //red text
cout<<"|\n";

cout<<"------------------------------------------------------------------\n\n";
cout<<"\033[1;33;49mPLATINUM-> 150              GOLD-> 100                  SILVER->60\033[0m\n";
}

void display1(node *tmp[20],int n)
{
if(n!=1)
{
cout<<"------------------------------------------------------------------\n";
cout<<"THANK YOU!\nYOU HAVE SUCCESFULLY BOOKED THE SEATS\n";
for(int i=1;i<n;i++)

cout<<tmp[i]->row_no<<tmp[i]->seat_no<<"    PIN : "<<tmp[i]->pin<<"\n";

cout<<"!!!!!!!!!!!!!!!!!!KEEP PIN SAFELY!!!!!!!!!!!!!!!!!!!\n";
cout<<"PINS ARE REQUIRED AT THE TIME OF CANCELATION OF SEATS\n";
cout<<"------------------------------------------------------------------\n";
}
}
void book_seat()
{
node *cn,*temp[20];
int n,z,flag;
char row;
int seat;
char ch;
do
{
z=1;
cout<<"\nEnter No Of Tickets u Want To Buy: ";
cin>>n;

cout<<"\nEnter Seat Number(s): \n";

for(int i=1;i<=n;i++)
{
cout<<"NO "<<i<<" = "; 
cin>>row>>seat;
cn=hn;
while(cn->next!=hn)
{
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved \n";

}
}
cn=cn->next;
}
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved\n";
}
}
}

display1(temp,z);
cout<<"\n\nPRESS 1 To check Seat Status\n";
cout<<"PRESS 2 To book other seat\n";
cout<<"PRESS 3 To Exit BOOKING PORTAL\n";
cout<<"\ninput: ";
cin>>ch;
if(ch==1)
display();
}while(ch=='2');
}

void cancle()
{
char row,ch;
int seat,pin;
node *cn;
do
{
ch='a';
cn=hn;
cout<<"SEAT NUMBRE :";
cin>>row>>seat;
cout<<"PIN :";
cin>>pin;
while(cn->next!=hn)
{
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle the Seat (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
cn=cn->next;
}
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
cout<<"\n\nPRESS 1 To Check Seat Status\n"; 
cout<<"PRESS 2 To Cancle More Tickets\n";
cout<<"PRESS 3 To Exit CANCELATION PORTAL\n";
cout<<"\ninput: ";
cin>>ch;
if(ch==1)
display();
}while(ch=='2');
}
};


int main()
{
dcll o;
int ch;
char c;
cout<<"\n\n\n";
cout<<"                 @@@@@@   Cinemax  @@@@@@\n";
cout<<"                vvvvvv ARRANGEMENT vvvvvv\n\n";
o.create();
o.display();

do
{
cout<<"\n\n\n";
cout<<"PRESS 1-> BOOK TICKETS\n";
cout<<"PRESS 2-> CANCLE TICKETS\n";
cout<<"PRESS 3-> EXIT\n";
cout<<"\ninput: ";
cin>>ch;
switch(ch)
{
case 1:
o.book_seat();
o.display();
break;
case 2:
o.cancle();
o.display();
break;
}
if(ch!=3)
{
cout<<"\n\nPRESS 1 To Main Menu\n";
cout<<"PRESS 2 To Exit CINEMAX PORTAL\n";
cout<<"\ninput: ";
cin>>c;
}
}while(c=='1');
cout<<"\n\n\n";
return 0;
}

CODE(for windows+linux environment)


/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

DEVELOPER: RUSHIKESH SANJAY PHALKE

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/

#include<iostream>

using namespace std;



typedef struct node

{

char row_no;
int seat_no,pin;
char book;
struct node *next,*prev;
}node;

class dcll
{
public:
node *hn;
dcll()
{
hn=NULL;
}
public:
void create()
{
node *nn,*cn;
int j=1;
volatile int k=2;
char c ='A';

do
{
int i=1;
do
{
k=(k*k)/10+100-k/2;
nn=new node();
nn->next=nn->prev=NULL;
nn->row_no=c;
nn->seat_no=i;
nn->pin=k;
nn->book='a';
if(hn==NULL)
{
hn=nn;
nn->next=nn->prev=hn;
}
else
{
cn=hn;

while(cn->next!=hn)
cn=cn->next;

cn->next=nn;
nn->prev=cn;
nn->next=hn;
hn->prev=nn;
}
i++;
}while(i<=7);
j++;
c++;
}while(j<=10);
}

void display()
{
node *cn;
cn=hn;
cout<<"------------------------------------------------------------------\n";
cout<<"|                            Platinum                            |\n";
while(cn->next!=hn)
{
if((cn->prev)->row_no!=cn->row_no)
cout<<"| ";
cout<<cn->row_no;
cout<<cn->seat_no;
if(cn->book=='a')
cout << " -> a  ";  //green text with black background
else
cout << " -> b  ";  //red text
if((cn->next)->row_no!=cn->row_no)
cout<<"|\n";
if(cn->row_no=='C'&&cn->seat_no==7)
{
cout<<"------------------------------------------------------------------\n";
cout<<"|                             gold                               |\n";
}
if(cn->row_no=='H'&&cn->seat_no==7)
{
cout<<"------------------------------------------------------------------\n";
cout<<"|                            Silver                              |\n";
}
cn=cn->next;
}
cout<<cn->row_no;
cout<<cn->seat_no;
if(cn->book=='a')
cout << " -> a  ";  //green text with black background

else
cout << " -> b  ";  //red text
cout<<"|\n";

cout<<"------------------------------------------------------------------\n\n";
cout<<"PLATINUM-> 150              GOLD-> 100                  SILVER->60\n";
}

void display1(node *tmp[20],int n)
{
if(n!=1)
{
cout<<"------------------------------------------------------------------\n";
cout<<"THANK YOU!\nYOU HAVE SUCCESFULLY BOOKED THE SEATS\n";
for(int i=1;i<n;i++)

cout<<tmp[i]->row_no<<tmp[i]->seat_no<<"    PIN : "<<tmp[i]->pin<<"\n";

cout<<"!!!!!!!!!!!!!!!!!!KEEP PIN SAFELY!!!!!!!!!!!!!!!!!!!\n";
cout<<"PINS ARE REQUIRED AT THE TIME OF CANCELATION OF SEATS\n";
cout<<"------------------------------------------------------------------\n";
}
}
void book_seat()
{
node *cn,*temp[20];
int n,z,flag;
char row;
int seat;
char ch;
do
{
z=1;
cout<<"\nEnter No Of Tickets u Want To Buy: ";
cin>>n;

cout<<"\nEnter Seat Number(s): \n";

for(int i=1;i<=n;i++)
{
cout<<"NO "<<i<<" = "; 
cin>>row>>seat;
cn=hn;
if(row>='A'&&row<='E')
{
while(cn->next!=hn)
{
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved \n";

}
}
cn=cn->next;
}
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved\n";
}
}
}
else //
{
while(cn->prev!=hn)
{
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved \n";

}
}
cn=cn->prev;
}
if(cn->row_no==row && cn->seat_no==seat)
{
if(cn->book=='a')
{
cn->book='b';
temp[z]=cn;
z++;
}
else
{
cout<<"INVALID CHOISE!\n";
cout<<cn->row_no<<cn->seat_no<<" Seat is alredy reserved\n";
}
}
}

}

display1(temp,z);
cout<<"\n\nPRESS 1 To check Seat Status\n";
cout<<"PRESS 2 To book other seat\n";
cout<<"PRESS 3 To Exit BOOKING PORTAL\n";
cout<<"\ninput: ";
cin>>ch;
if(ch==1)
display();
}while(ch=='2');
}

void cancle()
{
char row,ch;
int seat,pin;
node *cn;
cout<<"SEAT CANCELATION\n";
do
{
ch='a';
cn=hn;
cout<<"SEAT NUMBRE :";
cin>>row>>seat;
cout<<"PIN :";
cin>>pin;
if(row>='A'&&row<='E')
{
while(cn->next!=hn)
{
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle the Seat (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
cn=cn->next;
}
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
}
else
{
while(cn->next!=hn)
{
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle the Seat (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
cn=cn->next;
}
if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
{
cout<<"Are you sure u want to cancle (y/n) ";
char c;
cin>>c;
if(c=='y'||c=='Y')
{
cout<<"SEAT CANCELED SUCCESFULLY!\n";
cn->book='a';
}
}
else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
{
cout<<"invalid SEAT NUMBER && PIN combination!!!!\n";
}
}
cout<<"\n\nPRESS 1 To Check Seat Status\n"; 
cout<<"PRESS 2 To Cancle More Tickets\n";
cout<<"PRESS 3 To Exit CANCELATION PORTAL\n";
cout<<"\ninput: ";
cin>>ch;
if(ch==1)
display();
}while(ch=='2');
}
};


int main()
{
dcll o;
int ch;
char c;
cout<<"\n\n\n";
cout<<"                 @@@@@@   Cinemax  @@@@@@\n";
cout<<"                vvvvvv ARRANGEMENT vvvvvv\n\n";
o.create();
o.display();

do
{
cout<<"\n\n\n";
cout<<"PRESS 1-> BOOK TICKETS\n";
cout<<"PRESS 2-> CANCLE TICKETS\n";
cout<<"PRESS 3-> EXIT\n";
cout<<"\ninput: ";
cin>>ch;
switch(ch)
{
case 1:
o.book_seat();
o.display();
break;
case 2:
o.cancle();
o.display();
break;
}
if(ch!=3)
{
cout<<"\n\nPRESS 1 To Main Menu\n";
cout<<"PRESS 2 To Exit CINEMAX PORTAL\n";
cout<<"\ninput: ";
cin>>c;
}
}while(c=='1');
cout<<"\n\n\n";
return 0;

}


2 comments:

  1. You are the besttt .... Thankyou soo much.. your program helps me a lot

    ReplyDelete
  2. Can you send which data structures are used in each module(function)

    ReplyDelete