Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define ROW 3
- #define COL 10
- #define MVSIZE 7
- int ticketNumber[MVSIZE] = {0, 0, 0, 0, 0, 0, 0};
- typedef struct{
- char fName[33];
- char MI;
- char lName[33];
- }NameDetails;
- typedef struct{
- char custID[7];
- NameDetails custName;
- }CustomerDetails;
- typedef struct{
- char movieName[33];
- float price;
- }MovieDetails;
- typedef struct{
- int row;
- int col;
- }SeatDetails;
- typedef struct seatNode{
- SeatDetails seat;
- struct seatNode* nextSeat;
- }seatNode, *SeatList;
- typedef struct{
- int seat[ROW][COL]; /* Multi-dimensional array representing the seats in the cinema. 0 if vacant, 1 if occupied. */
- SeatList nextAvail; /* Linked list containing the list of available seats */
- }CinemaSeating;
- typedef struct{
- char cinemaID[4];
- MovieDetails movie;
- CinemaSeating cinemaSeats;
- int availSeats; /* Contains the number of available seats */
- }CinemaDetails;
- typedef struct{
- CinemaDetails cinema[MVSIZE];
- int count; /* Contains the number of cinemas. Starts at 0 */
- }CinemaList;
- typedef struct{
- CustomerDetails cust;
- SeatDetails seatNum;
- MovieDetails movie;
- }TicketDetails;
- typedef struct ticketNode{
- char ticketNo[9];
- TicketDetails ticket;
- struct ticketNode* nextTicket;
- }*TList;
- /* Completed functions */
- void pause(void);
- void generateMovieRecords(void);
- void displaySeatList(SeatList);
- /* Problem 1 */
- /* Instructions:
- 1) resetSeating() - The function will initialize all of the seats within a cinema to be empty.
- The ff: fields within the Cinema are to be initialized.
- - C->availSeats
- - C->cinemaSeats.seat
- - C->cinemaSeats.nextAvail
- 2) populateSeatList() - The function will populate the SeatList passed as a parameter.
- The first node of the SeatList will contain SL->seat = {0, 0}, the second node will contain {0, 1},
- the third {0, 2} and the last node will contain {2, 9}
- Insertion into the SeatList will be done via insertFirst.
- 3) initCinemaSeats() - The function will simply make a function call to resetSeating() and populateSeatList().
- 4) populateCinemaList() - The function will read from a file called movieList.bin. It will store all of the records inside the file
- into each of the movies in the cinemaList. The function will also call initCinemaSeats() for EACH cinema
- in the cinemaList, to prepare the cinema for ticket purchasing. Finally, it will set the cinemaID of each
- cinema to be "C0N" where N is the cinema number (starting from 1. EG. cinema[0] = "C01").
- 5) dispCinemaList() - The function will display the details inside the cinemaList().
- Partial Code is provided.
- 6) dispSeating() - The function will display the seat arrangement within the cinema passed. The seat arrangement is represented by
- the multidimensional array seat inside the CinemaSeating structure. 0 is printed when the seat is vacant, and 1
- if it is occupied.
- Partial Code is provided.
- */
- void resetSeating(CinemaDetails*);
- void populateSeatList(SeatList*);
- void initCinemaSeats(CinemaDetails*);
- void populateCinemaList(CinemaList*);
- void dispCinemaList(CinemaList);
- void dispSeating(CinemaDetails);
- /* Problem 2 */
- /* Instructions:
- 1) initTicketList() = The function will initialize the TList passed to be empty.
- 2) displayTickets() = The function will display all of the tickets in the TList with their respective details.
- Partial Code is provided.
- 3) getSeat() = The function will delete the first node of the SeatList and return it to the calling function.
- It will also update the seat multidimensional array and set the row and col of the seat returned to be 1.
- 4) hasTicket() = The function will check the ticketList and see if the passed customer already has a ticket for that movie.
- If the customer already has a ticket for that movie, return 0. Else return 1.
- 5) findCinema() = The function will go through the CinemaList and return the index of the cinema showing that movie.
- If the movie is not found in any cinema, return -1.
- 6) purchaseTicket() = The function will insert into the ticketList a new ticket for a certain movie, for that customer.
- Insertion will only be possible if ALL of the ff: conditions are met.
- 1) Movie is being shown in any of the cinemas in the cinemaList.
- 2) There are still available seats in that cinema.
- 3) The customer does not yet have a ticket for that movie inside the ticketList.
- Insertion into the ticketList will be done via insertSorted, sorted in ascending order via ticketNumber.
- Ticket number is defined as a global array. Ticket number is in the form "CinemaID000TicketNumber".
- Example: "C010001" Which is Cinema 1, 2nd ticket.
- */
- TList initTicketList(void);
- void displayTickets(TList);
- SeatDetails getSeat(CinemaDetails*);
- int hasTicket(TList TL, MovieDetails movie, CustomerDetails cust);
- int findCinema(CinemaList CL, MovieDetails movie);
- void purchaseTicket(CinemaList*, TList*, MovieDetails, CustomerDetails);
- /* Problem 3 */
- /* Instructions:
- 1) cancelSeat() - The function will insertFirst back into the seatList the SeatNum that has been passed. Update the necessary fields in the
- Cinema.
- 2) returnTicket() - The function will check the ticketList if the passed TicketNumber exists in the list. If it does, delete the ticket from the
- list and call cancelSeat() to insert the deleted seat back into the seatList.
- */
- void cancelSeat(CinemaDetails*, SeatDetails);
- void returnTicket(CinemaList*, TList*, char[]);
- /* Problem 4 */
- /* Instructions:
- 1) generateReports() - The function will go through the ticketList and delete all of the tickets inside the list.
- Prior to deletion, write the movieName of the ticket to a file named "CustIDFamilyNameCust.txt";
- Example: "000001Militante.txt"
- This means that by the end of the function, all of the movies that the customer has watched will be
- stored into their own seperate file. Finally, print the number of tickets deleted.
- */
- void generateReports(CinemaList*, TList*);
- void pause(void)
- {
- printf("\n\nPress any key to continue...");
- getch();
- system("CLS");
- }
- void generateMovieRecords(void)
- {
- MovieDetails movies[MVSIZE] = { {"Avengers - Endgame", 390.00},
- {"Detective Pikachu", 240.00},
- {"John Wick 3", 240.00},
- {"Aladdin", 210.00},
- {"Toy Story 4", 390.00},
- {"Annabelle Comes Home", 220.00},
- {"The Lion King", 210.00},
- };
- FILE* fp = fopen("movieList.bin", "wb");
- if(fp != NULL){
- fwrite(movies, sizeof(MovieDetails), MVSIZE, fp);
- }
- fclose(fp);
- }
- void displaySeatList(SeatList SL)
- {
- for(; SL != NULL; SL = SL->nextSeat){
- printf("[%d][%d]\n", SL->seat.row, SL->seat.col);
- }
- }
- void resetSeating(CinemaDetails* CD)
- {
- }
- void populateSeatList(SeatList* SL)
- {
- }
- void initCinemaSeats(CinemaDetails* CD)
- {
- }
- void populateCinemaList(CinemaList* CL)
- {
- }
- void dispCinemaList(CinemaList CL)
- {
- printf("\n\n<-- Today's Movie Schedule -->\n");
- printf("%-15s", "Cinema ID");
- printf("%-25s", "Movie");
- printf("%-15s", "Price");
- printf("%-15s", "Available Seats");
- /* insert code here */
- }
- void dispSeating(CinemaDetails C)
- {
- printf("\n\n<-- Cinema: %s -->\n", C.cinemaID);
- printf("Now Showing: %s\n", C.movie.movieName);
- /* insert code here */
- }
- TList initTicketList(void)
- {
- }
- SeatDetails getSeat(CinemaDetails* CD)
- {
- }
- int hasTicket(TList TL, MovieDetails movie, CustomerDetails cust)
- {
- }
- int findCinema(CinemaList CL, MovieDetails movie)
- {
- }
- void purchaseTicket(CinemaList* CL, TList* TL, MovieDetails movie, CustomerDetails cust)
- {
- }
- void cancelSeat(CinemaDetails* CD, SeatDetails seatNum)
- {
- }
- void returnTicket(CinemaList* CL, TList* TL, char ticketNo[])
- {
- }
- void displayTickets(TList TL)
- {
- printf("\n\n<-- Tickets -->\n");
- printf("%-15s", "Ticket No.");
- printf("%-15s", "Customer");
- printf("%-25s", "Movie");
- printf("%-15s", "Seat");
- /* insert code here */
- }
- void generateReports(CinemaList* CL, TList* TL)
- {
- }
- int main(void)
- {
- CinemaList ayalaMalls;
- CustomerDetails cust1 = {"000001", {"Cris", 'G', "Militante"}};
- CustomerDetails cust2 = {"000002", {"Nadi", 'L', "Lim"}};
- CustomerDetails cust3 = {"000003", {"Marai", 'G', "Nicole"}};
- MovieDetails movie1 = {"Avengers - Endgame", 390.00};
- MovieDetails movie2 = {"Detective Pikachu", 240.00};
- MovieDetails movie3 = {"John Wick 3", 240.00};
- char ticket1[] = "C010001";
- char ticket2[] = "C040001";
- TList tickets;
- /* Problem 1 */
- /* Instructions:
- 1) Call function generateMovieRecords() to create the file containing all the movies to be shown for the current day.
- 2) Call function initCinemaList() passing as parameter ayalaMalls.
- 3) Call function dispCinemaList().
- 4) Call the pause() function.
- */
- printf("\nProblem 1\n");
- /* Problem 2 */
- /* Instructions:
- 1) Call function initTicketList() to initialize the tickets variable.
- 2) Call function purchaseTicket(), passing movie1 and cust1 as parameters.
- 3) Call function purchaseTicket(), passing movie2 and cust1 as parameters.
- 4) Call function purchaseTicket(), passing movie1 and cust2 as parameters.
- 5) Call function purchaseTicket(), passing movie2 and cust2 as parameters.
- 6) Call function purchaseTicket(), passing movie3 and cust3 as parameters.
- 7) Call function purchaseTicket(), passing movie1 and cust3 as parameters.
- 8) Call function purchaseTicket(), passing movie1 and cust3 as parameters.
- 9) Call function purchaseTicket(), passing movie2 and cust2 as parameters.
- 10) Call the dispSeating() function for the first cinema.
- 11) Call the dispSeating() function for the second cinema.
- 12) Call the dispSeating() function for the third cinema.
- 13) Call function dispCinemaList().
- 14) Call displayTickets() function.
- 15) Call the pause() function.
- */
- printf("\nProblem 2\n");
- /* Problem 3 */
- /* Instructions:
- 1) Call the returnTicket() function, passing ticket1 as parameter.
- 2) Call the returnTicket() function, passing ticket2 as parameter.
- 3) Call the dispSeating() function for the first cinema.
- 4) Call function dispCinemaList().
- 5) Call displayTickets() function.
- 6) Call the pause() function.
- */
- printf("\nProblem 3\n");
- /* Problem 4 */
- /* Instructions:
- 1) Call the generateReports() function.
- 2) Call the dispSeating() function for the first cinema.
- 3) Call the dispSeating() function for the second cinema.
- 4) Call the dispSeating() function for the third cinema.
- 5) Call function dispCinemaList().
- 6) Call displayTickets() function.
- 7) Call the pause() function.
- */
- printf("\nProblem 4\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement