Practical No.8
Practical No.8
Problem Statement:
Statement:-- The
The ticket
ticket booking system of Cinemax theater has to be
implemented using C++ program. There are 10 rows and 7 seats in each row.
Doubly circular linked list has to be maintained to keep track of free seats at rows.
Assume some random booking to start with. Use array to store pointers (Head
pointer) to each row. On demand
a) The list of available seats is to be displayed
b) The seats are to be booked
c) The booking can be cancelled.
Code:
Code:
#include <iostream>
#include<stdlib.h>
using namespace std;
class node { public:
node* next;
node* prev;
int seat;
string id; int
status; class
cinemax
public:
node* head, * tail , * temp; cinemax()
head=NULL;
void create_list();
void display();
void book();
void cancel();
void avail();
node *p; p=
new node; p-
>seat=i; p-
>status=O;
{ int r=l;
node* temp;
temp=head;
int count=O;
while(temp->next!=head)
if(temp->seat/10==O)
else cout<<"S"<<temp-
>seat<<" if(temp-
>status==O)
else
count++;
if(count%7==O)
>status==O)
else
void cinemax::book()
{ int x;
string y;
label:
cout<<"\n\n\nEnter seat number to be booked\n";
cin>>x; cout<<"Enter your ID number\n"; cin>>y;
node *temp;
temp=new node;
temp=head;
while(temp->seat!=x)
temp=temp->next;
if(temp->status==l)
cout<<"Seat already booked
; else{ temp->status=l;
temp->id=y; cout<<"Seat
booked!\n";
void cinemax::cancel()
int x;
string
y;
labell:
cout<<"Enter seat number to cancel booking\n"; cin>>x;
node *temp;
temp=new node;
temp=head;
while(temp->seat!=x)
temp=temp->next;
if(temp->status==O)
cout<<"Seat not booked yet!!\n , else
if(temp->id==y)
int r=l;
node* temp;
temp=head; int
count=O;
cout<<"\n\n\n\n"
;
\n"; while(temp-
>next!=head) if(temp-
>seat/10==O)
cout<<endl;
temp=temp->next;
if(temp->status==O)
if(temp->status==O)
int main() {
cinemax obj;
obj.create_list()
; int ch; char
c='y';
{ obj.display(); cout<< \n
Seat\n4.CancelSeat\n"
; cin>>ch; switch(ch)
case l:obj.display();
break; case 2:
obj.book(); break;
case 3:obj.avail();
break; case 4:
obj.cancel(); break;
default: choice input\n";
return O;
Output: