Skip to content

Instantly share code, notes, and snippets.

@annibuliful
Created May 3, 2018 16:12
Show Gist options
  • Save annibuliful/a52e03c6ec2d17d5141b6ff31be51454 to your computer and use it in GitHub Desktop.
Save annibuliful/a52e03c6ec2d17d5141b6ff31be51454 to your computer and use it in GitHub Desktop.
#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 that for creating movie variable
*/
struct Movie {
char name[50], year[5], length[20], showtime[10], screen[5];
int fake;
float endtime;
};
/*
* decare movie
*/
struct Movie r[100];
/*
* global variable store number of ticket that user booked
*/
int numberOfTicket;
/*
* global variable store movie that user booked
*/
int indexOfMovieTicket;
/*
* decare variable seat type
*/
int indexOfSeatType[100];
/*
* Fixing conio.h error on Mac
* From StackOverflow
*/
char * strlwr(char * str) {
unsigned char * p = (unsigned char * ) str;
while ( * p) {
* p = tolower((unsigned char) * p);
p++;
}
return str;
}
/*
* getReal index when user input order key(index) from keyboard
*/
int getRealIndex(int fakeIndex) {
int real, i;
for (i = 0; i < 5; i++) {
if (r[i].fake == fakeIndex) {
return r[i].fake - 1;
}
}
return -1;
}
/*
* load data
*/
void datamovie() {
strcpy(r[0].name, "Jumanji");
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, "Death note");
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, "Avenger");
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, "Fast and furious");
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");
/****************************/
}
/*
* list avaiable seat that movie
*/
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");
}
}
/*
* show ticket
*/
void showTicket(int row, int column) {
int i;
printf("\n\n\n===============================");
printf("\n [Ticket]\n");
printf("SEAT No. %d %d Row %c\n", row, column, 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");
}
/*
* select seat to book
*/
void selectSeat(int movieNumber) {
int counter;
printf("How many ticket do you want : ");
scanf("%d", & counter);
numberOfTicket = counter;
indexOfMovieTicket = movieNumber;
reseat: {
int row[9],
column[9],
i,
row1,
column1,
count = 0;
printf("\nselect Row and Column: ");
for (i = 0; i < counter; i++) {
scanf("%d %d", & row[i], & column[i]);
row1 = row[i] - 1;
column1 = column[i] - 1;
indexOfSeatType[i] = row1;
if (indexOfMovie[movieNumber][row1][column1] != 1) {
indexOfMovie[movieNumber][row1][column1] = 1;
} else {
printf("This seat is unavailable\n");
printf("Please select again");
goto reseat;
}
count++;
}
for (i = 0; i < count; i++) {
showTicket(row[i], column[i]);
}
}
}
/*
* input movie that user interest
*/
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);
printf("%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);
} 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);
r[i].fake = 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", numberOfMovie, r[i].name, r[i].year, r[i].length, r[i].showtime, r[i].screen);
r[i].fake = 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