Advertisement
varun1729

Untitled

Feb 5th, 2023
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.28 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. }
  115. void book_seat()
  116. {
  117. node *cn,*temp[20];
  118. int n,z,flag;
  119. char row;
  120. int seat;
  121. char ch;
  122. do
  123. {
  124. z=1;
  125. printf("\nEnter No Of Tickets u Want To Buy: ");
  126. scanf("%d",&n);
  127.  
  128. printf("\nEnter Seat Numbers: \n");
  129.  
  130. for(int i=1;i<=n;i++)
  131. {
  132. printf("NO ");
  133. printf("%d",i);
  134. printf(" = ");
  135. scanf(" %c",&row);
  136. scanf("%d",&seat);
  137. cn=hn;
  138. while(cn->next!=hn)
  139. {
  140. if(cn->row_no==row && cn->seat_no==seat)
  141. {
  142. if(cn->book=='a')
  143. {
  144. cn->book='b';
  145. temp[z]=cn;
  146. z++;
  147. }
  148. else
  149. {
  150. printf("INVALID CHOISE!\n");
  151. printf("%c",cn->row_no);
  152. printf("%d",cn->seat_no);
  153. printf(" Seat is alredy reserved \n");
  154.  
  155. }
  156. }
  157. cn=cn->next;
  158. }
  159. if(cn->row_no==row && cn->seat_no==seat)
  160. {
  161. if(cn->book=='a')
  162. {
  163. cn->book='b';
  164. temp[z]=cn;
  165. z++;
  166. }
  167. else
  168. {
  169. printf("INVALID CHOISE!\n");
  170. printf("%c",cn->row_no);
  171. printf("%d",cn->seat_no);
  172. printf(" Seat is alredy reserved\n");
  173. }
  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. scanf("%c",&ch);
  183. if(ch==1)
  184. display();
  185. }while(ch=='2');
  186. }
  187.  
  188. void cancel()
  189. {
  190. char row;
  191. int ch;
  192. int seat,pin;
  193. node *cn;
  194. do
  195. {
  196. ch=1;
  197. cn=hn;
  198. printf("SEAT NUMBER :");
  199. scanf(" %c",&row);
  200. scanf("%d",&seat);
  201. printf("PIN :");
  202. scanf("%d",&pin);
  203. while(cn->next!=hn)
  204. {
  205. if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
  206. {
  207. printf("Are you sure u want to cancle the Seat (y/n) ");
  208. char c;
  209. scanf(" %c",&c);
  210. if(c=='y'||c=='Y')
  211. {
  212. printf("SEAT CANCELED SUCCESFULLY!\n");
  213. cn->book='a';
  214. }
  215. }
  216. else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
  217. {
  218. printf("invalid SEAT NUMBER && PIN combination!!!!\n");
  219. }
  220. cn=cn->next;
  221. }
  222. if(cn->row_no==row && cn->seat_no==seat && cn->pin==pin)
  223. {
  224. printf("Are you sure u want to cancle (y/n) ");
  225. char c;
  226. scanf("%c",&c);
  227. if(c=='y'||c=='Y')
  228. {
  229. printf("SEAT CANCELED SUCCESFULLY!\n");
  230. cn->book='a';
  231. }
  232. }
  233. else if(cn->row_no==row && cn->seat_no==seat && cn->pin!=pin)
  234. {
  235. printf("invalid SEAT NUMBER && PIN combination!!!!\n");
  236. }
  237. printf("\n\nPRESS 1 To Check Seat Status\n");
  238. printf("PRESS 2 To Cancle More Tickets\n");
  239. printf("PRESS 3 To Exit CANCELATION PORTAL\n");
  240. printf("\ninput: ");
  241. scanf("%d",&ch);
  242. if(ch==1);
  243. //display();
  244. }
  245. while(ch==2);
  246. }
  247.  
  248. int main()
  249. {
  250. int ch;
  251. int c;
  252. printf("\n\n\n");
  253. printf("                 WELCOME TO MOVIE TICKET BOOKING \n");
  254. printf("                         ONLINE  \n\n");
  255. create();
  256. display();
  257.  
  258. do
  259. {
  260. printf("\n\n\n");
  261. printf("PRESS 1-> BOOK TICKETS\n");
  262. printf("PRESS 2-> CANCEL TICKETS\n");
  263. printf("PRESS 3-> EXIT\n");
  264. printf("\ninput: ");
  265. scanf("%d",&ch);
  266. switch(ch)
  267. {
  268. case 1:
  269. book_seat();
  270. display();
  271. break;
  272. case 2:
  273. cancel();
  274. display();
  275. break;
  276. }
  277. if(ch!=3)
  278. {
  279. printf("\n\nPRESS 1 To Main Menu\n");
  280. printf("PRESS 2 To Exit CINEMAX PORTAL\n");
  281. printf("\ninput: ");
  282. scanf("%d",&c);
  283. }
  284. }while(c==1);
  285. printf("\n\n\n");
  286. return 0;
  287. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement