Created
April 29, 2018 10:10
-
-
Save annibuliful/4da5d84c176ad83625395fbe9c19ece9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| #include <stdlib.h> | |
| #include <ctype.h> | |
| char alphabet[] = { | |
| 'A', | |
| 'B', | |
| 'C', | |
| 'D' | |
| }; | |
| int indexOfMovie[5][4][10]; | |
| int movie = 5; | |
| struct Movie { | |
| char name[50], year[5], length[20], showtime[10], screen[5]; | |
| float endtime; | |
| char rowa[50], rowb[50], rowc[50], rowd[50]; | |
| }; | |
| struct Movie r[5]; | |
| //1-dimension = index of real ; | |
| //2-dimension = index of fake ; | |
| int realIndex[5][2]; | |
| int numberOfTicket; | |
| int indexOfMovieTicket; | |
| int indexOfSeatType[5]; | |
| char * strlwr(char * str) { | |
| unsigned char * p = (unsigned char * ) str; | |
| while ( * p) { | |
| * p = tolower((unsigned char) * p); | |
| p++; | |
| } | |
| return str; | |
| } | |
| void datamovie() { | |
| strcpy(r[0].name, "The Transporter"); | |
| strcpy(r[0].year, "2002"); | |
| strcpy(r[0].length, "1h 32min"); | |
| strcpy(r[0].showtime, "10.00"); | |
| r[0].endtime = 11.32; | |
| strcpy(r[0].screen, "1"); | |
| /***************************/ | |
| strcpy(r[1].name, "Transporter2"); | |
| strcpy(r[1].year, "2005"); | |
| strcpy(r[1].length, "1h 27min"); | |
| strcpy(r[1].showtime, "13.00"); | |
| r[1].endtime = 14.27; | |
| strcpy(r[1].screen, "1"); | |
| /**************************/ | |
| strcpy(r[2].name, "Transporters"); | |
| strcpy(r[2].year, "2007"); | |
| strcpy(r[2].length, "2h 24min"); | |
| strcpy(r[2].showtime, "10.00"); | |
| r[2].endtime = 12.24; | |
| strcpy(r[2].screen, "2"); | |
| /****************************/ | |
| strcpy(r[3].name, "Transporter:\n The Last Night "); | |
| strcpy(r[3].year, "2017"); | |
| strcpy(r[3].length, "2h 34min"); | |
| strcpy(r[3].showtime, "13.00"); | |
| r[3].endtime = 15.34; | |
| strcpy(r[3].screen, "2"); | |
| /******************************/ | |
| strcpy(r[4].name, "Lost in Translation"); | |
| strcpy(r[4].year, "2003"); | |
| strcpy(r[4].length, "1h 42min"); | |
| strcpy(r[4].showtime, "11.00"); | |
| r[4].endtime = 12.42; | |
| strcpy(r[4].screen, "3"); | |
| /****************************/ | |
| } | |
| int getRealIndex(int fakeIndex) { | |
| int real, i; | |
| for (i = 0; i < 5; i++) { | |
| if (realIndex[i][1] == fakeIndex) { | |
| return realIndex[i][0] - 1; | |
| } | |
| } | |
| return -1; | |
| } | |
| void seat(int movieNumber) { | |
| printf("\n==============================="); | |
| printf("\nAvailable Seat"); | |
| printf("\n==============================="); | |
| int i, j; | |
| for (i = 0; i < 4; i++) { | |
| printf("\n Seat %c ", alphabet[i]); | |
| for (j = 0; j < 10; j++) { | |
| if (indexOfMovie[movieNumber][i][j] == 1) { | |
| printf("X|"); | |
| } else { | |
| printf("O|"); | |
| } | |
| } | |
| printf("\n"); | |
| } | |
| } | |
| void showTicket() { | |
| int i; | |
| for (i = 0; i < numberOfTicket; i++) { | |
| printf("\n\n\n==============================="); | |
| printf("\n [Ticket]\n"); | |
| printf("SEAT No. Row %c\n" , alphabet[indexOfSeatType[i]]); | |
| printf("Title: %s\n", r[indexOfMovieTicket].name); | |
| printf("Year: %s\n", r[indexOfMovieTicket].year); | |
| printf("Duration: %s\n", r[indexOfMovieTicket].length); | |
| printf("Time: %s\n", r[indexOfMovieTicket].showtime); | |
| printf("Time %s - %.2f\n", r[indexOfMovieTicket].showtime, r[indexOfMovieTicket].endtime); | |
| printf("Screen: %s\n\n\n", r[indexOfMovieTicket].screen); | |
| printf("===============================\n"); | |
| } | |
| } | |
| void selectSeat(int movieNumber) { | |
| int row, column, counter, i; | |
| printf("How many ticket do you want : "); | |
| scanf("%d", & counter); | |
| numberOfTicket = counter; | |
| indexOfMovieTicket = movieNumber; | |
| printf("select Row and Column: "); | |
| for (i = 0; i < counter; i++) { | |
| scanf("%d %d", & row, & column); | |
| row = row - 1; | |
| column = column - 1; | |
| indexOfSeatType[i] = row; | |
| if (indexOfMovie[movieNumber][row][column] != 1) { | |
| indexOfMovie[movieNumber][row][column] = 1; | |
| } else { | |
| printf("This seat is unavailable"); | |
| printf("Please select again"); | |
| } | |
| } | |
| } | |
| void seller() { | |
| datamovie(); | |
| printf("What movie do you want to watch? : "); | |
| int a, i; | |
| float time, duration, all; | |
| float b; | |
| char timeofbegin[50], movielong[50]; | |
| re: { | |
| scanf("%d", & a); | |
| a = getRealIndex(a); | |
| a = a + 1; | |
| if (r[a].name != NULL) { | |
| printf("\n [%s]\n", r[a].name); | |
| printf("Title: %s\n", r[a].name); | |
| printf("Year: %s\n", r[a].year); | |
| printf("Duration: %s\n", r[a].length); | |
| printf("Time: %s\n", r[a].showtime); | |
| printf("Time %s - %.2f\n", r[a].showtime, r[a].endtime); | |
| printf("Screen: %s\n", r[a].screen); | |
| seat(a); | |
| selectSeat(a); | |
| seat(a); | |
| showTicket(); | |
| } else { | |
| printf("Please check your choice"); | |
| goto re; | |
| } | |
| } | |
| } | |
| void searchFromTitle() { | |
| datamovie(); | |
| system("clear"); | |
| char nameMovie[20]; | |
| char lowername[100]; | |
| char lowersearch[100]; | |
| int i, check = 0, j, no_data = 0, count = 0, numberOfMovie = 1; | |
| char * aa; | |
| printf("[Search Movie from title]\n\n"); | |
| printf("===============================\n"); | |
| printf("Movie ShowTime (Today)\n"); | |
| printf("===============================\n\n"); | |
| printf("Please input Title for searching: "); | |
| scanf("%s", & nameMovie); | |
| printf(" Title Year Length ShowTime Screen\n"); | |
| printf("======================================================================\n"); | |
| for (i = 0; i < movie; i++) { | |
| check = 0; | |
| strcpy(lowername, strlwr(r[i].name)); | |
| strcpy(lowersearch, strlwr(nameMovie)); | |
| aa = strstr(lowername, lowersearch); | |
| if (aa != NULL) { | |
| printf("[%d] %-20s %-12s %-12s %-7s %s \n", numberOfMovie, r[i].name, r[i].year, r[i].length, r[i].showtime, r[i].screen); | |
| realIndex[count][0] = i; | |
| realIndex[count][1] = numberOfMovie; | |
| numberOfMovie++; | |
| count++; | |
| } | |
| } | |
| if (count == 0) { | |
| printf("There is not any movie"); | |
| } else { | |
| seller(); | |
| } | |
| } | |
| void searchingfromtime() { | |
| datamovie(); | |
| system("clear"); | |
| float time; | |
| char lowertime[100], startmovie[50]; | |
| float keeptime; | |
| char lowersearchtime[100]; | |
| int i, check = 0, j, no_data = 0, count = 0, numberOfMovie = 1; | |
| char * aa; | |
| printf("[Search Movie from title]\n\n"); | |
| printf("===============================\n"); | |
| printf("Movie ShowTime (Today)\n"); | |
| printf("===============================\n\n"); | |
| printf("Please input Time for searching: "); | |
| re: { | |
| scanf("%f", & time); | |
| printf("\n"); | |
| for (i = 0; i < movie; i++) { | |
| strcpy(startmovie, r[i].showtime); | |
| keeptime = atof(startmovie); | |
| if (time >= keeptime) { | |
| no_data++; | |
| if (no_data == 1) { | |
| printf(" Title Year Length ShowTime Screen\n"); | |
| printf("======================================================================\n"); | |
| } | |
| printf("[%d] %-20s %-12s %-12s %-7s %s \n", i + 1, r[i].name, r[i].year, r[i].length, r[i].showtime, r[i].screen); | |
| realIndex[count][0] = i; | |
| realIndex[count][1] = numberOfMovie; | |
| numberOfMovie++; | |
| count++; | |
| } | |
| } | |
| if (count == 0) { | |
| printf("[MESSAGE]:There is no movie showing before %.2f in in the system.", time); | |
| printf("\n"); | |
| printf("Please re-input Movie's Title for searching: "); | |
| goto re; | |
| } else { | |
| printf("======================================================================\n"); | |
| seller(); | |
| } | |
| } | |
| } | |
| int main() { | |
| printf("===============================\n"); | |
| printf("ICT Cinema System\n"); | |
| printf("===============================\n"); | |
| printf("[1] Search Movie (title)\n"); | |
| printf("[2] Search Movie (Showtime)\n"); | |
| printf("[0] exit\n"); | |
| printf("-----------------------\n"); | |
| char choice; | |
| newcheck: { | |
| printf("Enter you choice: "); | |
| scanf(" %c", & choice); | |
| switch (choice) { | |
| case '1': | |
| { | |
| searchFromTitle(); | |
| break; | |
| } | |
| case '2': | |
| { | |
| searchingfromtime(); | |
| break; | |
| } | |
| case '0': | |
| { | |
| exit(-1); | |
| break; | |
| } | |
| default: | |
| { | |
| printf("Please check your choice\n"); | |
| goto newcheck; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment