SHARE
TWEET

CINEMA

a guest Jul 21st, 2019 117 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define ROW 3
  5. #define COL 10
  6. #define MVSIZE 7
  7.  
  8. int ticketNumber[MVSIZE] = {0, 0, 0, 0, 0, 0, 0};
  9.  
  10. typedef struct{
  11.     char fName[33];
  12.     char MI;
  13.     char lName[33];
  14. }NameDetails;
  15.  
  16. typedef struct{
  17.     char custID[7];
  18.     NameDetails custName;
  19. }CustomerDetails;
  20.  
  21. typedef struct{
  22.     char movieName[33];
  23.     float price;
  24. }MovieDetails;
  25.  
  26. typedef struct{
  27.     int row;
  28.     int col;
  29. }SeatDetails;
  30.  
  31. typedef struct seatNode{
  32.     SeatDetails seat;
  33.     struct seatNode* nextSeat;
  34. }seatNode, *SeatList;
  35.  
  36. typedef struct{
  37.     int seat[ROW][COL]; /* Multi-dimensional array representing the seats in the cinema. 0 if vacant, 1 if occupied. */
  38.     SeatList nextAvail; /* Linked list containing the list of available seats */
  39. }CinemaSeating;
  40.  
  41. typedef struct{
  42.     char cinemaID[4];
  43.     MovieDetails movie;
  44.     CinemaSeating cinemaSeats;
  45.     int availSeats;                 /* Contains the number of available seats */
  46. }CinemaDetails;
  47.  
  48. typedef struct{
  49.     CinemaDetails cinema[MVSIZE];
  50.     int count;                      /* Contains the number of cinemas. Starts at 0 */
  51. }CinemaList;
  52.  
  53. typedef struct{
  54.     CustomerDetails cust;
  55.     SeatDetails seatNum;
  56.     MovieDetails movie;
  57. }TicketDetails;
  58.  
  59. typedef struct ticketNode{
  60.     char ticketNo[9];
  61.     TicketDetails ticket;
  62.     struct ticketNode* nextTicket;
  63. }*TList;
  64.  
  65. /* Completed functions */
  66. void pause(void);
  67. void generateMovieRecords(void);
  68. void displaySeatList(SeatList);
  69.  
  70. /* Problem 1 */
  71. /* Instructions:
  72.     1) resetSeating() - The function will initialize all of the seats within a cinema to be empty.
  73.                         The ff: fields within the Cinema are to be initialized.
  74.                         - C->availSeats
  75.                         - C->cinemaSeats.seat
  76.                         - C->cinemaSeats.nextAvail
  77.     2) populateSeatList() - The function will populate the SeatList passed as a parameter.
  78.                             The first node of the SeatList will contain SL->seat = {0, 0}, the second node will contain {0, 1},
  79.                             the third {0, 2} and the last node will contain {2, 9}
  80.                             Insertion into the SeatList will be done via insertFirst.
  81.     3) initCinemaSeats() - The function will simply make a function call to resetSeating() and populateSeatList().
  82.     4) populateCinemaList() - The function will read from a file called movieList.bin. It will store all of the records inside the file
  83.                               into each of the movies in the cinemaList. The function will also call initCinemaSeats() for EACH cinema
  84.                               in the cinemaList, to prepare the cinema for ticket purchasing. Finally, it will set the cinemaID of each
  85.                               cinema to be "C0N" where N is the cinema number (starting from 1. EG. cinema[0] = "C01").
  86.     5) dispCinemaList() - The function will display the details inside the cinemaList().
  87.                           Partial Code is provided.
  88.     6) dispSeating() - The function will display the seat arrangement within the cinema passed. The seat arrangement is represented by
  89.                        the multidimensional array seat inside the CinemaSeating structure. 0 is printed when the seat is vacant, and 1
  90.                        if it is occupied.  
  91.                        Partial Code is provided.               
  92. */
  93. void resetSeating(CinemaDetails*);
  94. void populateSeatList(SeatList*);
  95. void initCinemaSeats(CinemaDetails*);
  96. void populateCinemaList(CinemaList*);
  97. void dispCinemaList(CinemaList);
  98. void dispSeating(CinemaDetails);
  99.  
  100. /* Problem 2 */
  101. /* Instructions:
  102.     1) initTicketList() = The function will initialize the TList passed to be empty.
  103.     2) displayTickets() = The function will display all of the tickets in the TList with their respective details.
  104.                           Partial Code is provided.
  105.     3) getSeat() = The function will delete the first node of the SeatList and return it to the calling function.
  106.                    It will also update the seat multidimensional array and set the row and col of the seat returned to be 1.
  107.     4) hasTicket() = The function will check the ticketList and see if the passed customer already has a ticket for that movie.
  108.                      If the customer already has a ticket for that movie, return 0. Else return 1.
  109.     5) findCinema() = The function will go through the CinemaList and return the index of the cinema showing that movie.
  110.                       If the movie is not found in any cinema, return -1.
  111.     6) purchaseTicket() = The function will insert into the ticketList a new ticket for a certain movie, for that customer.
  112.                           Insertion will only be possible if ALL of the ff: conditions are met.
  113.                           1) Movie is being shown in any of the cinemas in the cinemaList.
  114.                           2) There are still available seats in that cinema.
  115.                           3) The customer does not yet have a ticket for that movie inside the ticketList.
  116.                           Insertion into the ticketList will be done via insertSorted, sorted in ascending order via ticketNumber.
  117.                           Ticket number is defined as a global array. Ticket number is in the form "CinemaID000TicketNumber".
  118.                           Example: "C010001" Which is Cinema 1, 2nd ticket.
  119. */
  120. TList initTicketList(void);
  121. void displayTickets(TList);
  122. SeatDetails getSeat(CinemaDetails*);
  123. int hasTicket(TList TL, MovieDetails movie, CustomerDetails cust);
  124. int findCinema(CinemaList CL, MovieDetails movie);
  125. void purchaseTicket(CinemaList*, TList*, MovieDetails, CustomerDetails);
  126.  
  127. /* Problem 3 */
  128. /* Instructions:
  129.     1) cancelSeat() - The function will insertFirst back into the seatList the SeatNum that has been passed. Update the necessary fields in the
  130.                       Cinema.
  131.     2) returnTicket() - The function will check the ticketList if the passed TicketNumber exists in the list. If it does, delete the ticket from the
  132.                         list and call cancelSeat() to insert the deleted seat back into the seatList.
  133. */
  134. void cancelSeat(CinemaDetails*, SeatDetails);
  135. void returnTicket(CinemaList*, TList*, char[]);
  136.  
  137. /* Problem 4 */
  138. /* Instructions:
  139.     1) generateReports() - The function will go through the ticketList and delete all of the tickets inside the list.
  140.                            Prior to deletion, write the movieName of the ticket to a file named "CustIDFamilyNameCust.txt";
  141.                            Example: "000001Militante.txt"
  142.                            This means that by the end of the function, all of the movies that the customer has watched will be
  143.                            stored into their own seperate file. Finally, print the number of tickets deleted.                          
  144. */
  145. void generateReports(CinemaList*, TList*);
  146.  
  147.  
  148. void pause(void)
  149. {
  150.     printf("\n\nPress any key to continue...");
  151.     getch();
  152.     system("CLS");
  153. }
  154.  
  155. void generateMovieRecords(void)
  156. {
  157.     MovieDetails movies[MVSIZE] = { {"Avengers - Endgame", 390.00},
  158.                                     {"Detective Pikachu", 240.00},
  159.                                     {"John Wick 3", 240.00},
  160.                                     {"Aladdin", 210.00},
  161.                                     {"Toy Story 4", 390.00},
  162.                                     {"Annabelle Comes Home", 220.00},
  163.                                     {"The Lion King", 210.00},
  164.                                   };
  165.                              
  166.     FILE* fp = fopen("movieList.bin", "wb");
  167.     if(fp != NULL){
  168.         fwrite(movies, sizeof(MovieDetails), MVSIZE, fp);
  169.     }
  170.     fclose(fp);
  171. }
  172.  
  173. void displaySeatList(SeatList SL)
  174. {
  175.     for(; SL != NULL; SL = SL->nextSeat){
  176.         printf("[%d][%d]\n", SL->seat.row, SL->seat.col);
  177.     }  
  178. }
  179.  
  180. void resetSeating(CinemaDetails* CD)
  181. {
  182.  
  183. }
  184.  
  185. void populateSeatList(SeatList* SL)
  186. {
  187.  
  188. }
  189.  
  190. void initCinemaSeats(CinemaDetails* CD)
  191. {
  192.  
  193. }
  194.  
  195. void populateCinemaList(CinemaList* CL)
  196. {  
  197.  
  198. }
  199.  
  200. void dispCinemaList(CinemaList CL)
  201. {
  202.     printf("\n\n<-- Today's Movie Schedule -->\n");
  203.     printf("%-15s", "Cinema ID");
  204.     printf("%-25s", "Movie");
  205.     printf("%-15s", "Price");
  206.     printf("%-15s", "Available Seats");
  207.  
  208.     /* insert code here */ 
  209. }
  210.  
  211. void dispSeating(CinemaDetails C)
  212. {
  213.     printf("\n\n<-- Cinema: %s -->\n", C.cinemaID);
  214.     printf("Now Showing: %s\n", C.movie.movieName);
  215.    
  216.     /* insert code here */
  217. }
  218.  
  219. TList initTicketList(void)
  220. {
  221.  
  222. }
  223.  
  224. SeatDetails getSeat(CinemaDetails* CD)
  225. {
  226.  
  227. }
  228.  
  229. int hasTicket(TList TL, MovieDetails movie, CustomerDetails cust)
  230. {
  231.  
  232. }
  233.  
  234. int findCinema(CinemaList CL, MovieDetails movie)
  235. {
  236.  
  237. }
  238.  
  239. void purchaseTicket(CinemaList* CL, TList* TL, MovieDetails movie, CustomerDetails cust)
  240. {
  241.  
  242. }
  243.  
  244. void cancelSeat(CinemaDetails* CD, SeatDetails seatNum)
  245. {
  246.  
  247. }
  248.  
  249. void returnTicket(CinemaList* CL, TList* TL, char ticketNo[])
  250. {
  251.  
  252. }
  253.  
  254. void displayTickets(TList TL)
  255. {
  256.     printf("\n\n<-- Tickets -->\n");
  257.     printf("%-15s", "Ticket No.");
  258.     printf("%-15s", "Customer");
  259.     printf("%-25s", "Movie");
  260.     printf("%-15s", "Seat");
  261.    
  262.     /* insert code here */
  263. }
  264.  
  265. void generateReports(CinemaList* CL, TList* TL)
  266. {
  267.  
  268. }
  269.  
  270. int main(void)
  271. {
  272.     CinemaList ayalaMalls;
  273.     CustomerDetails cust1 = {"000001", {"Cris", 'G', "Militante"}};
  274.     CustomerDetails cust2 = {"000002", {"Nadi", 'L', "Lim"}};
  275.     CustomerDetails cust3 = {"000003", {"Marai", 'G', "Nicole"}};
  276.     MovieDetails movie1 = {"Avengers - Endgame", 390.00};
  277.     MovieDetails movie2 = {"Detective Pikachu", 240.00};
  278.     MovieDetails movie3 = {"John Wick 3", 240.00};
  279.     char ticket1[] = "C010001";
  280.     char ticket2[] = "C040001";
  281.     TList tickets;
  282.    
  283.     /* Problem 1 */
  284.     /* Instructions:
  285.         1) Call function generateMovieRecords() to create the file containing all the movies to be shown for the current day.
  286.         2) Call function initCinemaList() passing as parameter ayalaMalls.
  287.         3) Call function dispCinemaList().
  288.         4) Call the pause() function.
  289.     */
  290.     printf("\nProblem 1\n");
  291.    
  292.    
  293.     /* Problem 2 */
  294.     /* Instructions:
  295.         1)  Call function initTicketList() to initialize the tickets variable.
  296.         2)  Call function purchaseTicket(), passing movie1 and cust1 as parameters.
  297.         3)  Call function purchaseTicket(), passing movie2 and cust1 as parameters.
  298.         4)  Call function purchaseTicket(), passing movie1 and cust2 as parameters.
  299.         5)  Call function purchaseTicket(), passing movie2 and cust2 as parameters.
  300.         6)  Call function purchaseTicket(), passing movie3 and cust3 as parameters.
  301.         7)  Call function purchaseTicket(), passing movie1 and cust3 as parameters.
  302.         8)  Call function purchaseTicket(), passing movie1 and cust3 as parameters.
  303.         9)  Call function purchaseTicket(), passing movie2 and cust2 as parameters.
  304.         10) Call the dispSeating() function for the first cinema.
  305.         11) Call the dispSeating() function for the second cinema.
  306.         12) Call the dispSeating() function for the third cinema.
  307.         13) Call function dispCinemaList().
  308.         14) Call displayTickets() function.
  309.         15) Call the pause() function.
  310.     */
  311.     printf("\nProblem 2\n");
  312.  
  313.    
  314.     /* Problem 3 */
  315.     /* Instructions:
  316.         1) Call the returnTicket() function, passing ticket1 as parameter.
  317.         2) Call the returnTicket() function, passing ticket2 as parameter.
  318.         3) Call the dispSeating() function for the first cinema.
  319.         4) Call function dispCinemaList().
  320.         5) Call displayTickets() function.
  321.         6) Call the pause() function.
  322.     */
  323.     printf("\nProblem 3\n");
  324.  
  325.    
  326.     /* Problem 4 */
  327.     /* Instructions:
  328.         1) Call the generateReports() function.
  329.         2) Call the dispSeating() function for the first cinema.
  330.         3) Call the dispSeating() function for the second cinema.
  331.         4) Call the dispSeating() function for the third cinema.
  332.         5) Call function dispCinemaList().
  333.         6) Call displayTickets() function.
  334.         7) Call the pause() function.
  335.     */
  336.     printf("\nProblem 4\n");
  337.  
  338.    
  339.     return 0;
  340. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top