Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

DSA Mini Project

Uploaded by

Isha Shah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

DSA Mini Project

Uploaded by

Isha Shah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

/*Problem Statement: Movie Ticket Booking System:

Implement a movie ticket booking system where customers can view available
seats, book tickets, and cancel reservations. Use 2D arrays to represent
the seating arrangement of the theatre and linked lists to handle ticket
booking records*/

#include<iostream>
using namespace std;

class node{
public:
node* prev;
char data;
node* next;

node(char data = ' '){


this -> data = data;
this -> next = prev;
this -> prev = next;

}
};

void make_array(node* &head){


node* h = new node();
head = h;
for (int i = 0; i<6; i++){
node*temp = new node();
h-> next = temp;
temp-> prev = h;
h = h-> next;

}
h->next = head;
head->prev =h;
}

void book_seat(node* head, int pos, char d){


pos --;
while(pos--){
head = head->next;
}
if(head->data =='X'){
cout<<"Already booked"<<endl;

}
else{
head->data = 'X';
cout<<"Seat is booked"<<endl;
}
}

void cancel_seat(node* head, int pos){


pos--;
while(pos--){
head = head->next;
}
if(head -> data =='X'){
head->data = ' ';
cout<<"Booking cancelled"<< endl;
}
else{
cout<<"Your seat is not booked"<< endl;
}
}

void print(node* head){


node* temp = head;
do{
cout<<"["<<head->data<<"]-";
head = head ->next;
}
while(head != temp);
cout<<endl;
}

int main(){
cout<<"Seating arrangement is as follows:"<<endl;
node* heads[10] = {NULL};
for(int i=0; i<10; i++){
make_array(heads[i]);
print(heads[i]);
}
cout<< "Menu: \n1) Book a seat \n2) Cancel booking \n3)Show seating
\n4)END"<<endl;
while(1){
int a;
cout<< "Option of your choice:";
cin>> a;
int r,s;
if(a==1){
cout<<"\nEnter row & seat number to be booked(format: row
column):- ";
cin>>r>>s;
book_seat(heads[r-1],s,'X');
}
else if(a==2){
cout<<"\nEnter seat to be canceled(format: row column) :- ";
cin>>r>>s;
cancel_seat(heads[r-1],s);

}
else if(a==3){
cout<<"===============================================\n";
for(int i =0;i<10;i++){
print(heads[i]);
}
cout<<"===============================================\n";
}else{break;}

}
}

OUTPUT:

You might also like