Showing posts with label Data structures Assignments. Show all posts
Showing posts with label Data structures Assignments. Show all posts

Sunday, 23 October 2016

Selection Sort Function Template

/*
TITLE:
Write a function template selection Sort. Write a program that inputs, sorts and outputs an integer array and a float array.
*/
#include<iostream>
using namespace std;
template<class T>
class sort
{
public:
T a[50];
int n;
void accept()
{
cout<<"Enter no. of elements:\n";
cin>>n;
cout<<"enter a elements\n";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
void selection_sort()
{
T temp;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
void display()
{
for(int i=0;i<n;i++)
{cout<<a[i]<<"\n";
}
}
};

int main()
{
int v;char ch;
sort<int>s1;
sort<float>s2;

cout<<"*****SELECTION SORT*******\n";
do
{
cout<<"sorting of integer and float array"<<"\n";
cout<<"1.for int array\n";
cout<<"2.for float array\n";
cout<<"enter your choice\n";
cin>>v;
switch(v)
{
case 1:
s1.accept();
cout<<"\nElements are:\n";
s1.display();
s1.selection_sort();
cout<<"\nSorted elements are:\n";
s1.display();
break;
case 2:
s2.accept();
cout<<"\nElements are:\n";
s2.display();
s2.selection_sort();
cout<<"\nSorted elements are:\n";
s2.display();
break;
}
cout<<"\n do you want to continue";
cin>>ch;
}while(ch=='y'||ch=='Y');
return 0;
}

Saturday, 15 October 2016

C++ program using stack to check whether given expression is well parenthesized or not

In any language program mostly syntax error occurs due to unbalancing delimiter such as (),{},[].
So today we are going to see a program which checks whether the given expression is well parenthesized or not.
lets take an example:
{c-[(a+b)*c]} is well parenthesized expression
but
{c-[a+b)*c] is not

how to code
use stack data structure
scan the expression from left to right
if element of expression is opening paranthesis  push it in stack
if element of expression is closing paranthesis  the pop the top most element of stack
if match found repeat the loop
else return false

so lets see the implementation of this problem using c++

#include<iostream>
#include<cstring>
using namespace std;

class stack_
{
char stack[10];  //stack is created using array
int top;
public:
stack_():top(-1){} //initialization of top using constructor

void push(char x)  //push function to insert element in stack
{
if(top==9)
cout<<"overflow";
else
{
top++;
stack[top]=x;
}
}

char pop() //pop function to remove the element from stack
{
if(top!=-1)
{

return(stack[top--]);

}
else
cout<<"underflow";

}

bool is_empty() //is_empty function to check whether the stack is empty or not
{
if(top==-1)
return true;
else
return false;
}

bool is_full() //is_full function to check whether the stack is full or not
{
if(top==9)
return true;
else
return false;
}

bool balence(string ex) // main logic starts from here
{
int j=0;
char c[10];
for(int i=0;i<ex.size();i++)
{
if(ex[i]=='('||ex[i]=='{'||ex[i]=='[')
push(ex[i]);
else if(ex[i]==')'||ex[i]=='}'||ex[i]==']')
{
if(is_empty()||!pair(stack[top],ex[i]))
return false;
else
{

c[j]=pop();
j++;
}
}
}
for(int i=0;i<j;i++)
{
cout<<c[i];
}
for(int i=j-1;i>=0;i--)
{
if(c[i]=='(')
cout<<")";
else if(c[i]=='[')
cout<<"]";
else if(c[i]=='{')
cout<<"}";
}
cout<<endl;
return is_empty()?true:false;
}


bool pair(char ope,char cls)
{
if(ope=='('&& cls==')')
return true;
else if(ope=='['&& cls==']')
return true;
else if(ope=='{'&& cls=='}')
return true;
return false;
}

};

int main()
{
stack_ o;
bool b;
int m;
string s="]";
b=o.balence(s);
if(b==true)
cout<<"expression is well parenthesise\n";
else
cout<<"expression is not well parenthesise\n";
return 0;
}

Expression Conversion using stack

Infix->Postfix || Infix->Prefix || Postfix->Infix || Postfix->Prefix || Prefix->Infix || Prefix->Postfix

This program is implemented using stack. Stack is FILO or LIFO structure this property of stack is used to convert the expression from one form to another

code:

#include<iostream>
#include<string>
#include<cstring>
#include<stack>
using namespace std;

int getWeight(char ch) {
switch (ch) {
case '^':return 3;
case '/':
case '*': return 2;
case '+':
case '-': return 1;
default : return 0;
}
}


void infix2postfix(char infix[], char postfix[], int size) {
stack<char> s;
int weight;
int i = 0;
int k = 0;
char ch;
   
while (i < size) 
{
ch = infix[i];
if (ch == '(') 
{
s.push(ch);
i++;
continue;
}
if (ch == ')') 
{
while (!s.empty() && s.top() != '(') 
{
postfix[k++] = s.top();
s.pop();
}
        
if (!s.empty()) 
{
s.pop();
}
i++;
continue;
}
weight = getWeight(ch);
if (weight == 0) {
         
postfix[k++] = ch;

}
else {
         
if (s.empty()) {
       
s.push(ch);
}
else {
            
while (!s.empty() && s.top() != '(' && weight <= getWeight(s.top())) 
{
postfix[k++] = s.top();
s.pop();
}
            
s.push(ch);
}
}

i++;
}
   
while (!s.empty()) {
postfix[k++] = s.top();
s.pop();
}
postfix[k] = 0; 
}

void infix2prefix(char infix[], char prefix[], int size) {
stack<char> s;
int weight;
int i = 0;
int k = 0;
char ch;
char infix0[size];
int m=0,n=size-1;
while(m<size)
{
if(infix[n]=='(')
infix0[m]=')';
else if(infix[n]==')')
infix0[m]='(';
else
infix0[m]=infix[n];
m++;
n--;
}
infix0[m]=0;
while (i < size) {
ch = infix0[i];
if (ch == '(') {
   
s.push(ch);
i++;
continue;
}
if (ch == ')') {
        
while (!s.empty() && s.top() != '(') {
prefix[k++] = s.top();
s.pop();
}
        
if (!s.empty()) {
s.pop();
}
i++;
continue;
}
weight = getWeight(ch);
if (weight == 0) {
       
prefix[k++] = ch;

}
else {
         
if (s.empty()) {
        
s.push(ch);
}
else {
            
while (!s.empty() && s.top() != '(' && weight < getWeight(s.top())) 
{
prefix[k++] = s.top();
s.pop();
}
            
s.push(ch);
}
}
i++;
}
  
while (!s.empty()) {
prefix[k++] = s.top();
s.pop();
}
prefix[k] = 0; 
}


string postfix2infix(char postfix1[],int size)
{
string infix1;
stack<string> s;
int k=0;
while(k<size)
{
char ch=postfix1[k];
int weight=getWeight(ch);
if(weight==0)
{
string e;
e=ch;
s.push(e);
}
else
{

string operand_2=s.top();
s.pop();
string operand_1=s.top();
s.pop();
s.push("("+operand_1+ch+operand_2+")");

}
k++;
}
infix1=s.top();
s.pop();
return infix1;
}


string postfix2prefix(char postfix1[],int size)
{
string prefix1;
stack<string> s;
int k=0;
while(k<size)
{
char ch=postfix1[k];
int weight=getWeight(ch);
if(weight==0)
{
string e;
e=ch;
s.push(e);
}
else
{

string operand_2=s.top();
s.pop();
string operand_1=s.top();
s.pop();
s.push(ch+operand_1+operand_2);

}
k++;
}
prefix1=s.top();
s.pop();
return prefix1;
}



string prefix2infix(char prefix1[],int size)
{
string infix1;
stack<string> s;
int k=size-1;
while(k>=0)
{
char ch=prefix1[k];
int weight=getWeight(ch);
if(weight==0)
{
string e;
e=ch;
s.push(e);
}
else
{

string operand_1=s.top();
s.pop();
string operand_2=s.top();
s.pop();
s.push("("+operand_1+ch+operand_2+")");

}
k--;
}
infix1=s.top();
s.pop();
return infix1;
}

string prefix2postfix(char prefix1[],int size)
{
string postfix1;
stack<string> s;
int k=size-1;
while(k>=0)
{
char ch=prefix1[k];
int weight=getWeight(ch);
if(weight==0)
{
string e;
e=ch;
s.push(e);
}
else
{

string operand_1=s.top();
s.pop();
string operand_2=s.top();
s.pop();
s.push(operand_1+operand_2+ch);

}
k--;
}
postfix1=s.top();
s.pop();
return postfix1;
}


// main
int main() 
{
char ch;
int c,size;
char infix[20],postfix[20],prefix[20],postfix1[20],prefix1[20];
string infix1,prefix2,postfix2;
do{
cout<<">>>>>>>>>>EXPRESSION CONVERSION<<<<<<<<<<<<\n";
cout<<"1]infix to other\n";
cout<<"2]postfix to other\n";
cout<<"3]prefix to other\n";
cout<<"4]Exit\n";
cout<<"\nENTER YOUR CHOISE :";
cin>>c;
if(c!=4){
switch(c)
{
case 1:
   
   cout<<"insert Infix Expression: ";
   cin>>infix;
   size = strlen(infix);
   infix2postfix(infix,postfix,size);
   infix2prefix(infix,prefix,size);
   cout<<"\nInfix Expression :: "<<infix;
   cout<<"\nPostfix Expression :: "<<postfix;
   cout<<"\nPrefix Expression :: ";
   
   for(int i=strlen(prefix)-1;i>=0;i--)
   {
   cout<<prefix[i];
   }
   cout<<endl<<endl;
   break;
case 2:
   
   cout<<"insert postfix Expression: ";
   cin>>postfix1;
   size = strlen(postfix1);
   infix1 = postfix2infix(postfix1,size);
   prefix2=postfix2prefix(postfix1,size);
   cout<<"\nPostfix Expression :: "<<postfix1;
   cout<<"\nInfix Expression :: "<<infix1;
   cout<<"\nPrefix Expression :: "<<prefix2;
   cout<<endl<<endl;
break;
case 3:
   
   cout<<"insert pretfix Expression: ";
   cin>>prefix1;
   size = strlen(prefix1);
   infix1 = prefix2infix(prefix1,size);
   postfix2=prefix2postfix(prefix1,size);
   cout<<"\nPrefix Expression :: "<<prefix1;
   cout<<"\nInfix Expression :: "<<infix1;
   cout<<"\nPostfix Expression :: "<<postfix2;
   cout<<endl<<endl;
break;
case 4:

   break;

}
cout<<"do you want to continue :";
cin>>ch;}
}while(ch=='y');
   
   return 0;
}

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;

}