varun1729

Untitled

Feb 5th, 2023
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.98 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct node
  5. {
  6. char row_no;
  7. int seat_no,pin;
  8. char book;
  9. struct node *next,*prev;
  10. }node;
  11.  
  12. node *hn=NULL;
  13.  
  14. void create()
  15. {
  16. node *nn,*cn;
  17. int j=1;
  18. int k=2;
  19. char c ='A';
  20.  
  21. do
  22. {
  23. int i=1;
  24. do
  25. {
  26. k=(k*k)/10+100-k/2;
  27. nn=(struct node*)malloc(sizeof(node));
  28. nn->next=nn->prev=NULL;
  29. nn->row_no=c;
  30. nn->seat_no=i;
  31. nn->pin=k;
  32. nn->book='a';
  33. if(hn==NULL)
  34. {
  35. hn=nn;
  36. nn->next=nn->prev=hn;
  37. }
  38. else
  39. {
  40. cn=hn;
  41.  
  42. while(cn->next!=hn)
  43.     cn=cn->next;
  44.  
  45. cn->next=nn;
  46. nn->prev=cn;
  47. nn->next=hn;
  48. hn->prev=nn;
  49. }
  50. i++;
  51. }while(i<=7);
  52. j++;
  53. c++;
  54. }while(j<=10);
  55. }
  56.  
  57. void display()
  58. {
  59. node *cn;
  60. cn=hn;
  61. printf("------------------------------------------------------------------\n");
  62. printf("|                            Platinum                            |\n");
  63. while(cn->next!=hn)
  64. {
  65. if((cn->prev)->row_no!=cn->row_no)
  66. printf("| ");
  67. printf("%c ",cn->row_no);
  68. printf("%d ",cn->seat_no);
  69. if(cn->book=='a')
  70. printf("\033[32;40m -> a  \033[0m");  //green text with black background
  71. else
  72. printf("\033[1;31;43m -> b  \033[0m");  //red text
  73. if((cn->next)->row_no!=cn->row_no)
  74. printf("|\n");
  75. if(cn->row_no=='C'&&cn->seat_no==7)
  76. {
  77. printf("-----------------------------------------------------------------------\n");
  78. printf("|                             gold                               |\n");
  79. }
  80. if(cn->row_no=='H'&&cn->seat_no==7)
  81. {
  82. printf("----------------------------------------------------------------------\n");
  83. printf("|                            Silver                              |\n");
  84. }
  85. cn=cn->next;
  86. }
  87. printf("%c",cn->row_no);
  88. printf("%d",cn->seat_no);
  89. if(cn->book=='a')
  90. printf("\033[32;40m -> a  \033[0m");
  91. else
  92. printf("\033[1;31;43m -> b  \033[0m");  
  93. printf("|\n");
  94.  
  95. printf("------------------------------------------------------------------\n\n");
  96. printf("\033[1;33;49mPLATINUM-> 150              GOLD-> 100                  SILVER->60\033[0m\n");
  97. }
  98.  
  99. void display1(node *tmp[20],int n)
  100. {
  101. if(n!=1)
  102. {
  103. printf("------------------------------------------------------------------\n");
  104. printf("THANK YOU!\nYOU HAVE SUCCESFULLY BOOKED THE SEATS\n");
  105. for(int i=1;i<n;i++)
  106. {
  107. printf("%c %d ",tmp[i]->row_no,tmp[i]->seat_no);
  108. printf("   PIN : %d \n",tmp[i]->pin);
  109. }
  110. printf("!!!!!!!!!!!!!!!!!!KEEP PIN SAFELY!!!!!!!!!!!!!!!!!!!\n");
  111. printf("PINS ARE REQUIRED AT THE TIME OF CANCELATION OF SEATS\n");
  112. printf("------------------------------------------------------------------\n");
  113. }
  114.  //printf("hello");
  115. }
  116. void book_seat()
  117. {
  118.     node *cn,*temp[20];
  119.     int n,z,flag;
  120.     char row;
  121.     int seat;
  122.     int ch1;
  123.     do
  124.     {
  125.     z=1;
  126.     printf("\nEnter No Of Tickets u Want To Buy: ");
  127.     scanf("%d",&n);
  128.    
  129.     printf("\nEnter Seat Numbers: \n");
  130.    
  131.     for(int i=1;i<=n;i++)
  132.     {
  133.     printf("NO ");
  134.     printf("%d",i);
  135.     printf(" = ");
  136.     scanf(" %c",&row);
  137.     scanf("%d",&seat);
  138.     cn=hn;
  139.     while(cn->next!=hn)
  140.     {
  141.     if(cn->row_no==row && cn->seat_no==seat)
  142.     {
  143.     if(cn->book=='a')
  144.     {
  145.     cn->book='b';
  146.     temp[z]=cn;
  147.     z++;
  148.     }
  149.     else
  150.     {
  151.     printf("INVALID CHOISE!\n");
  152.     printf("%c",cn->row_no);
  153.     printf("%d",cn->seat_no);
  154.     printf(" Seat is alredy reserved \n");
  155.    
  156.     }
  157.     }
  158.     cn=cn->next;
  159.     }
  160.     if(cn->row_no==row && cn->seat_no==seat)
  161.     {
  162.     if(cn->book=='a')
  163.     {
  164.     cn->book='b';
  165.     temp[z]=cn;
  166.     z++;
  167.     }
  168.     else
  169.     {
  170.     printf("INVALID CHOISE!\n");
  171.     printf("%c",cn->row_no);
  172.     printf("%d",cn->seat_no);
  173.     printf(" Seat is alredy reserved\n");
  174.     }
  175.     }
  176.     }
  177.     display1(temp,z);
  178.     printf("\n\nPRESS 1 To check Seat Status\n");
  179.     printf("PRESS 2 To book other seat\n");
  180.     printf("PRESS 3 To Exit BOOKING PORTAL\n");
  181.     printf("\ninput: ");
  182.     char temp;
  183.    // scanf("%c",&temp);
  184.     scanf("%d",&ch1);
  185.     if(ch1==1);
  186.         // display();
  187.     }while(ch1==2);
  188. }
  189.  
  190. void cancel()
  191. {
  192.     char row;
  193.     int ch;
  194.     int seat,pin;
  195.     node *cn;
  196.     do
  197.     {
  198.     ch=1;
  199.     cn=hn;
  200.     printf("SEAT NUMBER :");
  201.     scanf(" %c",&row);
  202.     scanf("%d",&seat);
  203.     printf("PIN :");
  204.     scanf("%d",&pin);
  205.     while(cn->next!=hn)
  206.     {
  207.     if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
  208.     {
  209.     printf("Are you sure u want to cancle the Seat (y/n) ");
  210.     char c;
  211.     scanf(" %c",&c);
  212.     if(c=='y'||c=='Y')
  213.     {
  214.     printf("SEAT CANCELED SUCCESFULLY!\n");
  215.     cn->book='a';
  216.     }
  217.     }
  218.     else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
  219.     {
  220.     printf("invalid SEAT NUMBER && PIN combination!!!!\n");
  221.     }
  222.     cn=cn->next;
  223.     }
  224.     if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
  225.     {
  226.     printf("Are you sure u want to cancle (y/n) ");
  227.     char c;
  228.     scanf("%c",&c);
  229.     if(c=='y'||c=='Y')
  230.     {
  231.     printf("SEAT CANCELED SUCCESFULLY!\n");
  232.     cn->book='a';
  233.     }
  234.     }
  235.     else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
  236.     {
  237.     printf("invalid SEAT NUMBER && PIN combination!!!!\n");
  238.     }
  239.     printf("\n\nPRESS 1 To Check Seat Status\n");
  240.     printf("PRESS 2 To Cancle More Tickets\n");
  241.     printf("PRESS 3 To Exit CANCELATION PORTAL\n");
  242.     printf("\ninput: ");
  243.     scanf("%d",&ch);
  244.     if(ch==1);
  245.         // display();
  246.     }
  247.     while(ch==2);
  248. }
  249.  
  250. int main()
  251. {
  252. int ch;
  253. int c=0;
  254. printf("\n\n\n");
  255. printf("                 WELCOME TO MOVIE TICKET BOOKING \n");
  256. printf("                         ONLINE  \n\n");
  257. create();
  258. display();
  259.  
  260. do
  261. {
  262. printf("\n\n\n");
  263. printf("PRESS 1-> BOOK TICKETS\n");
  264. printf("PRESS 2-> CANCEL TICKETS\n");
  265. printf("PRESS 3-> EXIT\n");
  266. printf("\ninput: ");
  267. // char temp;
  268. // scanf("%d",&temp);
  269. scanf("%d",&ch);
  270. switch(ch)
  271. {
  272.     case 1:
  273.     book_seat();
  274.     display();
  275.     break;
  276.     case 2:
  277.     cancel();
  278.     display();
  279.     break;
  280.     }
  281.    
  282.     if(ch==3)
  283.     {
  284.         printf("\n\nPRESS 1 To Main Menu\n");
  285.         printf("PRESS 2 To Exit CINEMAX PORTAL\n");
  286.         printf("\ninput: ");
  287.         scanf("%d",&c);
  288.     }
  289. }
  290.     while(c!=2);
  291.     printf("\n\n\n");
  292.     return 0;
  293. }
Add Comment
Please, Sign In to add comment