diff --git a/BEI/Eastern CinePlex/admin.c b/BEI/Eastern CinePlex/admin.c index 0a243a6..802cee7 100644 --- a/BEI/Eastern CinePlex/admin.c +++ b/BEI/Eastern CinePlex/admin.c @@ -1,209 +1,215 @@ -//For admin part of things. -//Snehaa Completion part. - -int admin_interface() -{ - pattern(); - printf("\tWelcome -- Abhishek--\n\t1) Edit movies and their details\n\t2) Edit price of the ticket\n\t3) View current shows\n\t4) View Reservation \n\t5) View Earnings \n\t6) Logout\n\t7) Exit\n"); - pattern(); - printf("Enter your choice : "); - int a = 0, n; - while (a != 7) - { - scanf("%d", &n); - switch(n) - { - case 1: - edit_movies(); - a = 7; - break; - case 2: - edit_price(); - a = 7; - break; - case 3: - view_current_shows(); - a = 7; - break; - case 4: - view_reservation(); - a = 7; - break; - case 5: - view_balance(); - a = 7; - break; - case 6: - logout(); - a = 7; - break; - case 7: - a = 7; - break; - default: - printf("INVALID INPUT\n"); - break; - } - } - return 0; -} -int edit_price() -{ - pattern(); - printf("\t\tEastern CinePlex\n\tEdit the price of the ticket\n\tThe current price of the ticket is %d", ticket_price); - printf("\n\tEnter the new price of ticket: \t"); - int new_price; - scanf("%d", &new_price); - printf("\n\tAre you sure you want to change the price?(Y/N)?\t"); - char decision; - scanf(" %c", &decision); - if ((decision == 'Y') || (decision == 'y')) - { - ticket_price = new_price; - printf("\n\tPrice changed successfully!!!"); - admin_interface(); - } - else { - admin_interface(); - } -} -int edit_movies() -{ - pattern(); - printf("\tEastern CinePlex\n\tThe current movies in listing are: \n"); - for (int i = 0; i < movies_count; i++) - { - printf("\t%d) %s\n", i + 1, film[i].name); - } - int n; - pattern(); - printf("Enter the movie that you want to edit : "); - scanf("%d", &n); - if ((n) < 1 || (n) > MAX_MOVIES) - { - printf("We cannot show more than %d movies.", MAX_MOVIES); - edit_movies(); - } - printf("\tEnter the new movie that you want to broadcast\n"); - printf("\tName of the movie: \t"); - scanf(" %[^\n]s", film[n - 1].name); - printf("\n\tStarting time: \t"); - scanf("%d", &film[n - 1].starting_time); - printf("\n\tLength of the movie(in minutes): \t"); - scanf("%d", &film[n - 1].length); - printf("\n\tBroadcasting date: \t"); - scanf("%d", &film[n - 1].screening_day); - printf("\n\tBroadcasting month: \t"); - scanf("%s", film[n - 1].screening_month); - printf("\n\tGenre: \t"); - scanf(" %[^\n]s", film[n - 1].genre); - printf("\n\tDirectors: \t"); - scanf(" %[^\n]s", film[n - 1].director); - printf("\tData taken successfully!!!"); - admin_interface(); - return 0; -} -int view_current_shows() -{ - pattern(); - printf("\tEastern CinePlex\n"); - printf("\tThe current shows in the listing are: \n"); - for (int i = 0; i < movies_count; i++) - { - printf("\t%d) %s: Length: %d(minutes)\n \t\tGenre: %s\n\t\tDirectors: %s\n\t\tScreening on: %d'th of %s\n",i+1, film[i].name, film[i].length, film[i].genre, film[i].director, film[i].screening_day, film[i].screening_month); - } - printf("\tDo you want to change the listing?(Y/N)\t"); - char change; - scanf(" %c", &change); - if ((change == 'y') || (change == 'Y')) - { - edit_movies(); - return 0; - } - admin_interface(); - return 0; -} -int logout(void) -{ - printf("\tLogging out!!!\n"); - main(); - return 0; -} -int view_reservation() -{ - pattern(); - printf("\tVIEW_RESERVATION\n\tCurrent Movies Are: \n"); - int i, n; - for (i = 0; i < 5; i++) - { - printf("\t\t%d) %s\n", i+1, film[i].name); - } - printf("\t%d) LOGOUT\n\t", i+1); - printf("%d) EXIT\n", i+2); - pattern(); - printf("Enter your choice : "); - scanf("%d", &n); - if (n > 0 && n < (i + 1)) - { - see_reservation(film[n-1].name); - return 0; - } - else if (n == (i + 1)) - { - logout(); - return 0; - } - else if(n == (i+2)) - { - return 0; - } - else { - view_reservation(); - } -} -int see_reservation(char movie[]) -{ - if (reservation_count == 0) - { - printf("\t There are currently no reservation for %s\n", movie); - view_reservation(); - return 0; - } - pattern(); - printf("VIEWING RESERVATION FOR --%s--\n", movie); - for (int i = 0; i < reservation_count; i++) - { - if (strcmp(reserve[i].movies, movie) == 0) - { - printf("%d) %s has booked seat no. : \t", i+1, reserve[i].name); - for (int j = 0; j < reserve[i].num_seats; j++ ) - { - printf("%d \t", reserve[i].seats[j]); - } - printf("\n"); - } - } - pattern(); - printf(("Press any key to exit....")); - getch(); - admin_interface(); -} -int view_balance() -{ - pattern(); - int total_balance = 0; - for (int i = 0; i < reservation_count; i++) - { - total_balance = total_balance + reserve[i].balance; - } - printf("\t\tEastern CinePlex\n\tTotal balance is: \t NRS.%d\n", total_balance); - printf("\tThe balance report:\n"); - for (int i = 0; i < reservation_count; i++) - { - printf("\t\t%d) NRS. %d from %s.\n", i+1, reserve[i].balance, reserve[i].movies); - } - pattern(); - printf(("Press any key to exit....")); - getch(); - admin_interface(); +//For admin part of things. +//Snehaa Completion part. + +int admin_interface() +{ + pattern(); + printf("\tWelcome -- Abhishek--\n\t1) Edit movies and their details\n\t2) Edit price of the ticket\n\t3) View current shows\n\t4) View Reservation \n\t5) View Earnings \n\t6) Logout\n\t7) Exit\n"); + pattern(); + printf("Enter your choice : "); + int a = 0, n; + while (a != 7) + { + scanf("%d", &n); + switch(n) + { + case 1: + edit_movies(); + a = 7; + break; + case 2: + edit_price(); + a = 7; + break; + case 3: + view_current_shows(); + a = 7; + break; + case 4: + view_reservation(); + a = 7; + break; + case 5: + view_balance(); + a = 7; + break; + case 6: + logout(); + a = 7; + break; + case 7: + a = 7; + break; + default: + printf("INVALID INPUT\n"); + break; + } + } + return 0; +} +int edit_price() +{ + pattern(); + printf("\t\tEastern CinePlex\n\tEdit the price of the ticket\n\tThe current price of the ticket is %d", ticket_price); + printf("\n\tEnter the new price of ticket: \t"); + int new_price; + scanf("%d", &new_price); + printf("\n\tAre you sure you want to change the price?(Y/N)?\t"); + char decision; + scanf(" %c", &decision); + if ((decision == 'Y') || (decision == 'y')) + { + ticket_price = new_price; + printf("\n\tPrice changed successfully!!!"); + admin_interface(); + } + else { + admin_interface(); + } +} +int edit_movies() +{ + pattern(); + printf("\tEastern CinePlex\n\tThe current movies in listing are: \n"); + for (int i = 0; i < movies_count; i++) + { + printf("\t%d) %s\n", i + 1, film[i].name); + } + int n; + pattern(); + printf("Enter the movie that you want to edit : "); + scanf("%d", &n); + if ((n) < 1 || (n) > MAX_MOVIES) + { + printf("We cannot show more than %d movies.", MAX_MOVIES); + edit_movies(); + } + printf("\tEnter the new movie that you want to broadcast\n"); + printf("\tName of the movie: \t"); + scanf(" %[^\n]s", film[n - 1].name); + printf("\n\tStarting time: \t"); + scanf("%d", &film[n - 1].starting_time); + printf("\n\tLength of the movie(in minutes): \t"); + scanf("%d", &film[n - 1].length); + printf("\n\tBroadcasting date: \t"); + scanf("%d", &film[n - 1].screening_day); + printf("\n\tBroadcasting month: \t"); + scanf("%s", film[n - 1].screening_month); + printf("\n\tGenre: \t"); + scanf(" %[^\n]s", film[n - 1].genre); + printf("\n\tDirectors: \t"); + scanf(" %[^\n]s", film[n - 1].director); + printf("\tData taken successfully!!!"); + + // Saving edited file data. + if (saveMoviesToFile(film, movies_count) != 0) + { + printf("Error saving movie data to file.\n"); + } + admin_interface(); + return 0; +} +int view_current_shows() +{ + pattern(); + printf("\tEastern CinePlex\n"); + printf("\tThe current shows in the listing are: \n"); + for (int i = 0; i < movies_count; i++) + { + printf("\t%d) %s: Length: %d(minutes)\n \t\tGenre: %s\n\t\tDirectors: %s\n\t\tScreening on: %d'th of %s\n",i+1, film[i].name, film[i].length, film[i].genre, film[i].director, film[i].screening_day, film[i].screening_month); + } + printf("\tDo you want to change the listing?(Y/N)\t"); + char change; + scanf(" %c", &change); + if ((change == 'y') || (change == 'Y')) + { + edit_movies(); + return 0; + } + admin_interface(); + return 0; +} +int logout(void) +{ + printf("\tLogging out!!!\n"); + main(); + return 0; +} +int view_reservation() +{ + pattern(); + printf("\tVIEW_RESERVATION\n\tCurrent Movies Are: \n"); + int i, n; + for (i = 0; i < 5; i++) + { + printf("\t\t%d) %s\n", i+1, film[i].name); + } + printf("\t%d) LOGOUT\n\t", i+1); + printf("%d) EXIT\n", i+2); + pattern(); + printf("Enter your choice : "); + scanf("%d", &n); + if (n > 0 && n < (i + 1)) + { + see_reservation(film[n-1].name); + return 0; + } + else if (n == (i + 1)) + { + logout(); + return 0; + } + else if(n == (i+2)) + { + return 0; + } + else { + view_reservation(); + } +} +int see_reservation(char movie[]) +{ + if (reservation_count == 0) + { + printf("There are currently no reservation for %s\n", movie); + view_reservation(); + return 0; + } + pattern(); + printf("VIEWING RESERVATION FOR --%s--\n", movie); + for (int i = 0; i < reservation_count; i++) + { + if (strcmp(reserve[i].movies, movie) == 0) + { + printf("%d) %s has booked seat no. : \t", i+1, reserve[i].name); + for (int j = 0; j < reserve[i].num_seats; j++ ) + { + printf("%d \t", reserve[i].seats[j]); + } + printf("\n"); + } + } + pattern(); + printf(("Press any key to exit....")); + getch(); + admin_interface(); +} +int view_balance() +{ + pattern(); + int total_balance = 0; + for (int i = 0; i < reservation_count; i++) + { + total_balance = total_balance + reserve[i].balance; + } + printf("\t\tEastern CinePlex\n\tTotal balance is: \t NRS.%d\n", total_balance); + printf("\tThe balance report:\n"); + for (int i = 0; i < reservation_count; i++) + { + printf("\t\t%d) NRS. %d from %s.\n", i+1, reserve[i].balance, reserve[i].movies); + } + pattern(); + printf(("Press any key to exit....")); + getch(); + admin_interface(); } \ No newline at end of file diff --git a/BEI/Eastern CinePlex/extra.h b/BEI/Eastern CinePlex/extra.h index d640522..73a661a 100644 --- a/BEI/Eastern CinePlex/extra.h +++ b/BEI/Eastern CinePlex/extra.h @@ -1,32 +1,32 @@ -#include -#include - -// Details of movies - -void pattern() -{ - for (int i = 0; i < 3; i++) - { - printf("\n"); - } - for (int i = 0; i < 50; i++) - { - printf("."); - } - for (int i = 0; i < 3; i++) - { - printf("\n"); - } -} - -// Choice of authentication: interface generation -int first_choice(void) -{ - pattern(); - printf("\tWELCOME TO Eastern CinePlex\n\tPLEASE SELECT...\n\t1) ADMIN LOGIN\n\t2) USER REGISTRATION\n\t3) USER LOGIN\n\t4) EXIT SYSTEM"); - pattern(); - printf("Enter your choice : "); - int a; - scanf("%d", &a); - return a; +#include +#include + +// Details of movies + +void pattern() +{ + for (int i = 0; i < 3; i++) + { + printf("\n"); + } + for (int i = 0; i < 50; i++) + { + printf("."); + } + for (int i = 0; i < 3; i++) + { + printf("\n"); + } +} + +// Choice of authentication: interface generation +int first_choice(void) +{ + pattern(); + printf("\tWELCOME TO Eastern CinePlex\n\tPLEASE SELECT...\n\t1) ADMIN LOGIN\n\t2) USER REGISTRATION\n\t3) USER LOGIN\n\t4) EXIT SYSTEM"); + pattern(); + printf("Enter your choice : "); + int a; + scanf("%d", &a); + return a; } \ No newline at end of file diff --git a/BEI/Eastern CinePlex/file-handeling.c b/BEI/Eastern CinePlex/file-handeling.c new file mode 100644 index 0000000..a095e95 --- /dev/null +++ b/BEI/Eastern CinePlex/file-handeling.c @@ -0,0 +1,79 @@ +// Writess movies to file if the movies are not initially in the file i.e default movies are loaded into the file. +void initializeMoviesFile() { + FILE *fp = fopen("movies.txt", "w"); + if (fp == NULL) { + printf("Error opening file.\n"); + return; + } + + int numMovies = 5; // Number of default movies + struct movie default_movies[5] = { + {"Avengers: Endgame", 2, 180, 28, "April", "action, drama", "Russo Brothers", {0}, 60}, + {"Inception", 5, 148, 29, "April", "Sci-fi, adventure", "Christopher Nolan", {0}, 60}, + {"FightClub", 8, 139, 29, "April", "Drama", "David Fincher", {0}, 60}, + {"Tumbbad", 6, 104, 28, "April", "Fantasy, Horror, Drama", "Rahi Anil Barve", {0}, 60}, + {"Whiplash", 2, 106, 30, "April", "Drama, Music", "Damien Cazelle", {0}, 60} + }; + + fwrite(&numMovies, sizeof(numMovies), 1, fp); // Write number of movies + fwrite(default_movies, sizeof(struct movie), numMovies, fp); // Write default movies data + fclose(fp); +} + +// Saves movies into the file. +int saveMoviesToFile(struct movie film[], int numMovies) +{ + FILE *fp = fopen("movies.txt", "w"); + if (fp == NULL) + { + printf("\tError opening file.\n"); + return 1; + } + fwrite(&numMovies, sizeof(numMovies), 1, fp); // Write number of movies + fwrite(film, sizeof(struct movie), numMovies, fp); // Write movies data + fclose(fp); + return 0; +} + +// Loads movie from the file. +int loadMoviesFromFile(struct movie film[], int *numMovies) +{ + FILE *fp = fopen("movies.txt", "r"); + if (fp == NULL) { + printf("\tError opening file.\n"); + return 1; + } + fread(numMovies, sizeof(*numMovies), 1, fp); // Read number of movies + fread(film, sizeof(struct movie), *numMovies, fp); // Read movies data + fclose(fp); + return 0; +} + + +int saveReservationToFile(struct reservation reserve[], int reservationCount) +{ + FILE *fp = fopen("reserve.txt", "w"); + if (fp == NULL) + { + printf("\tError opening file.\n"); + return 1; + } + fwrite(&reservationCount, sizeof(reservationCount), 1, fp); // Writes number of reservation. + fwrite(reserve, sizeof(struct reservation), reservationCount, fp); + fclose(fp); + return 0; +} + +int loadReservationFromFile(struct reservation reserve[], int *reservationCount) +{ + FILE *fp = fopen("reserve.txt", "r"); + if (fp == NULL) + { + printf("\tError opening file.\n"); + return 1; + } + fread(reservationCount, sizeof(*reservationCount), 1, fp); + fread(reserve, sizeof(struct reservation), *reservationCount, fp); + fclose(fp); + return 0; +} \ No newline at end of file diff --git a/BEI/Eastern CinePlex/login.c b/BEI/Eastern CinePlex/login.c index 327aa13..f1d43bb 100644 --- a/BEI/Eastern CinePlex/login.c +++ b/BEI/Eastern CinePlex/login.c @@ -1,113 +1,113 @@ -#define MAX_USERS 100 -#define MAX_USERNAME_LENGTH 50 -#define MAX_PASSWORD_LENGTH 50 - -struct User -{ - char username[MAX_USERNAME_LENGTH]; - char password[MAX_PASSWORD_LENGTH]; -}; - -struct User users[MAX_USERS]; -int userCount = 0; - -void saveUsersToFile() -{ - FILE *file = fopen("users.txt", "w"); - if (file == NULL) - { - printf("Error opening file.\n"); - return; - } - - for (int i = 0; i < userCount; i++) - { - fprintf(file, "\n%s %s", users[i].username, users[i].password); - } - - fclose(file); -} - -void loadUsersFromFile() -{ - FILE *file = fopen("users.txt", "r"); - if (file == NULL) - { - printf("No existing users found.\n"); - return; - } - - while (fscanf(file, "%s %s", users[userCount].username, users[userCount].password) == 2) - { - userCount++; - } - - fclose(file); -} - - -int registerUser() -{ - char username[MAX_USERNAME_LENGTH]; - char password[MAX_PASSWORD_LENGTH]; - - pattern(); - printf("\tWELCOME TO REGISTRATION PAGE\n"); - printf("\tENTER USERNAME: "); - scanf("%s", username); - printf("\tENTER PASSWORD: "); - scanf("%s", password); - - if (userCount >= MAX_USERS) - { - printf("\tCANNOT REGISTER MORE USERS.\n"); - main(); - return 0; - } - - for (int i = 0; i < userCount; i++) - { - if (strcmp(users[i].username, username) == 0) - { - printf("\tUSERNAME ALREADY EXISTS.PLEASE CHOOSE A DIFFERENT ONE.\n"); - main(); - return 0; - } - } - - strcpy(users[userCount].username, username); - strcpy(users[userCount].password, password); - userCount++; - saveUsersToFile(); - printf("\tUSER REGISTERED SUCCESSFULLY.\n"); - main(); - return 1; -} - -int loginUser() -{ - char username[MAX_USERNAME_LENGTH]; - char password[MAX_PASSWORD_LENGTH]; - - loadUsersFromFile(); - pattern(); - printf("\tWELCOME TO LOGIN PAGE\n"); - printf("\tENTER USERNAME: "); - scanf("%s", username); - printf("\tENTER PASSWORD: "); - scanf("%s", password); - - for (int i = 0; i < userCount; i++) - { - if (strcmp(users[i].username, username) == 0 && strcmp(users[i].password, password) == 0) - { - printf("\n\tLOGIN SUCCESSSFUL\n"); - user_interface(username); - return 0; - } - } - - printf("\tINVALID USERNAME OR PASSWORD.\n"); - main(); - return 0; +#define MAX_USERS 100 +#define MAX_USERNAME_LENGTH 50 +#define MAX_PASSWORD_LENGTH 50 + +struct User +{ + char username[MAX_USERNAME_LENGTH]; + char password[MAX_PASSWORD_LENGTH]; +}; + +struct User users[MAX_USERS]; +int userCount = 0; + +void saveUsersToFile() +{ + FILE *file = fopen("users.txt", "w"); + if (file == NULL) + { + printf("Error opening file.\n"); + return; + } + + for (int i = 0; i < userCount; i++) + { + fprintf(file, "\n%s %s", users[i].username, users[i].password); + } + + fclose(file); +} + +void loadUsersFromFile() +{ + FILE *file = fopen("users.txt", "r"); + if (file == NULL) + { + printf("No existing users found.\n"); + return; + } + + while (fscanf(file, "%s %s", users[userCount].username, users[userCount].password) == 2) + { + userCount++; + } + + fclose(file); +} + + +int registerUser() +{ + char username[MAX_USERNAME_LENGTH]; + char password[MAX_PASSWORD_LENGTH]; + + pattern(); + printf("\tWELCOME TO REGISTRATION PAGE\n"); + printf("\tENTER USERNAME: "); + scanf("%s", username); + printf("\tENTER PASSWORD: "); + scanf("%s", password); + + if (userCount >= MAX_USERS) + { + printf("\tCANNOT REGISTER MORE USERS.\n"); + main(); + return 0; + } + + for (int i = 0; i < userCount; i++) + { + if (strcmp(users[i].username, username) == 0) + { + printf("\tUSERNAME ALREADY EXISTS.PLEASE CHOOSE A DIFFERENT ONE.\n"); + main(); + return 0; + } + } + + strcpy(users[userCount].username, username); + strcpy(users[userCount].password, password); + userCount++; + saveUsersToFile(); + printf("\tUSER REGISTERED SUCCESSFULLY.\n"); + main(); + return 1; +} + +int loginUser() +{ + char username[MAX_USERNAME_LENGTH]; + char password[MAX_PASSWORD_LENGTH]; + + loadUsersFromFile(); + pattern(); + printf("\tWELCOME TO LOGIN PAGE\n"); + printf("\tENTER USERNAME: "); + scanf("%s", username); + printf("\tENTER PASSWORD: "); + scanf("%s", password); + + for (int i = 0; i < userCount; i++) + { + if (strcmp(users[i].username, username) == 0 && strcmp(users[i].password, password) == 0) + { + printf("\n\tLOGIN SUCCESSSFUL\n"); + user_interface(username); + return 0; + } + } + + printf("\tINVALID USERNAME OR PASSWORD.\n"); + main(); + return 0; } \ No newline at end of file diff --git a/BEI/Eastern CinePlex/main.c b/BEI/Eastern CinePlex/main.c index 2900166..df41d81 100644 --- a/BEI/Eastern CinePlex/main.c +++ b/BEI/Eastern CinePlex/main.c @@ -1,135 +1,165 @@ -// Definition of standard libraries. -#include -#include -#include -#include -#include -#include "extra.h" - -#define MAX_SEATS 60 -#define MAX_MOVIES 5 -#define admin_username "Abhishek" -#define admin_password "pass" -int ticket_price = 500; -int movies_count = MAX_MOVIES; -int reservation_count = 0; - -struct movie -{ - char name[30]; - int starting_time; - int length; - int screening_day; - char screening_month[8]; - char genre[40]; - char director[50]; - int seats[MAX_SEATS]; - int num_seats; -}; -struct reservation -{ - char movies[30]; - char name[40]; - int seats[MAX_SEATS]; - int num_seats; - int balance; -}; - -struct reservation reserve[100]; - -struct movie film[5] = { - {"Avengers: Endgame", 2, 180, 28, "April", "action, drama", "Russo Brothers", {0}, 60}, - {"Inception", 5, 148, 29, "April", "Sci-fi, adventure", "Christopher Nolan", {0}, 60}, - {"FightClub", 8, 139, 29, "April", "Drama", "David Fincher", {0}, 60}, - {"Tumbbad", 6, 104, 28, "April", "Fantasy, Horror, Drama", "Rahi Anil Barve", {0}, 60}, - {"Whiplash", 2, 106, 30, "April", "Drama, Music", "Damien Cazelle", {0}, 60} -}; - -// For user side of things. -int user_interface(char[]); -int see_shows(void); -int see_movies(int, char[]); -int display_seats(int[], int); -int book_seats(char[]); -int cineplex_info(void); -int logout(void); - -// For admin side of things -int admin_interface(); -int view_current_shows(); -int edit_movies(); -int edit_price(); -int view_reservation(); -int see_reservation(char[]); -int view_balance(); - -// Login part -int registerUser(); -int loginUser(); -int admin_login(); - -// Main Function -int main() -{ - // Step 1: Authentication - int n, a; - while (a != 4) - { - n = first_choice(); - switch(n) - { - case 1: - admin_login(); - a = 4; - break; - case 2: - registerUser(); - a = 4; - break; - case 3: - loginUser(); - a = 4; - break; - case 4: - a = 4; - break; - default: - printf("INVALID INPUT\n"); - break; - } - } - return 0; -} - -// User login part -// Prashan Rai. - -#include "login.c" - -int admin_login() -{ - pattern(); - char username[10], password[10]; - printf("\tWELCOME TO ADMIN LOGIN PAGE\n\n"); - printf("\tEnter your username: \t"); - scanf("%s", username); - printf("\n\tEnter your password: \t"); - scanf("%s", password); - if ((strcmp(username, admin_username) == 0) && (strcmp(password, admin_password)) == 0) - { - printf("\n\tYou are logged in successfully!!!\n"); - pattern(); - admin_interface(); - } - else { - printf("\n\tIncorrect password and/or username.Please try again"); - pattern(); - admin_login(); - } -} - -// For admin's side of things -#include "admin.c" - -// For user's part of things -#include "user.c" \ No newline at end of file +// Definition of standard libraries. +#include +#include +#include +#include +#include +#include "extra.h" + +#define MAX_SEATS 60 +#define MAX_MOVIES 5 +#define admin_username "Abhishek" +#define admin_password "pass" +int ticket_price = 500; +int movies_count = MAX_MOVIES; +int reservation_count = 0; + +struct movie +{ + char name[30]; + int starting_time; + int length; + int screening_day; + char screening_month[8]; + char genre[40]; + char director[50]; + int seats[MAX_SEATS]; + int num_seats; +}; +struct movie film[5]; +struct reservation +{ + char movies[30]; + char name[40]; + int seats[MAX_SEATS]; + int num_seats; + int balance; +}; + +struct reservation reserve[100]; + +// For file i/o movies. +void initializeMoviesFile(); +int saveMoviesToFile(struct movie[], int); +int loadMoviesFromFile(struct movie[], int *); + +int saveReservationToFile(struct reservation[], int); +int loadReservationFromFile(struct reservation[], int *); + +// For user side of things. +int user_interface(char[]); +int see_shows(void); +int see_movies(int, char[]); +int display_seats(int[], int); +int book_seats(char[]); +int cineplex_info(void); +int logout(void); + +// For admin side of things +int admin_interface(); +int view_current_shows(); +int edit_movies(); +int edit_price(); +int view_reservation(); +int see_reservation(char[]); +int view_balance(); + +// Login part +int registerUser(); +int loginUser(); +int admin_login(); + +// Main Function +int main() +{ + // Initialize movies file with default data if it doesn't exist + FILE *file = fopen("movies.txt", "r"); + if (file == NULL) { + initializeMoviesFile(); + printf("Initialized new file - Default Data.\n"); + } else { + fclose(file); + } + + // Load movies data from file. + int numMovies = 0; + if (loadMoviesFromFile(film, &numMovies) != 0) + { + printf("\tError loading movie data from file.\n\tExitting!!!\n"); + return 1; + } + movies_count = numMovies; + printf("%d", movies_count); + // Load reservation data from file. + int reservationCount = 0; + if(loadReservationFromFile(reserve, &reservationCount) != 0) + { + printf("\tThere are not previous reservations.\n"); + } + reservation_count = reservationCount; + + // Step 1: Authentication + int n, a; + while (a != 4) + { + n = first_choice(); + switch(n) + { + case 1: + admin_login(); + a = 4; + break; + case 2: + registerUser(); + a = 4; + break; + case 3: + loginUser(); + a = 4; + break; + case 4: + a = 4; + break; + default: + printf("INVALID INPUT\n"); + break; + } + } + return 0; +} + +// User login part +// Prashan Rai. + +#include "login.c" + +int admin_login() +{ + pattern(); + char username[10], password[10]; + printf("\tWELCOME TO ADMIN LOGIN PAGE\n\n"); + printf("\tEnter your username: \t"); + scanf("%s", username); + printf("\n\tEnter your password: \t"); + scanf("%s", password); + if ((strcmp(username, admin_username) == 0) && (strcmp(password, admin_password)) == 0) + { + printf("\n\tYou are logged in successfully!!!\n"); + pattern(); + admin_interface(); + } + else { + printf("\n\tIncorrect password and/or username.Please try again"); + pattern(); + admin_login(); + } +} + +// For admin's side of things +#include "admin.c" + +// For user's part of things +#include "user.c" + +// For file handeling operations +#include "file-handeling.c" \ No newline at end of file diff --git a/BEI/Eastern CinePlex/main.exe b/BEI/Eastern CinePlex/main.exe index 27c8136..f0a6d02 100644 Binary files a/BEI/Eastern CinePlex/main.exe and b/BEI/Eastern CinePlex/main.exe differ diff --git a/BEI/Eastern CinePlex/movies.txt b/BEI/Eastern CinePlex/movies.txt new file mode 100644 index 0000000..3c9ce20 Binary files /dev/null and b/BEI/Eastern CinePlex/movies.txt differ diff --git a/BEI/Eastern CinePlex/readme.md b/BEI/Eastern CinePlex/readme.md index 29facd0..11095c5 100644 --- a/BEI/Eastern CinePlex/readme.md +++ b/BEI/Eastern CinePlex/readme.md @@ -14,19 +14,23 @@ ## **Project Description** ## -Eastern-CinePlex is a group Project developed for the submission of the final project for C-Programming as I/I (first-year first part) students of electronics engineering at IOE Purwanchal Campus, Dharan. The project reflects a movie ticket management system that allows admin and user login functionality. +**Eastern-CinePlex** is a group Project developed for the submission of the final project for C-Programming as I/I (first-year first part) students of electronics engineering at IOE Purwanchal Campus, Dharan. The project reflects a movie ticket management system that allows admin and user login functionality. **Eastern-CinePlex** is a non-gui project that runs on a terminal and reflects just the internal logic behind how a ticket management system might function in the real world. The primary highlight of the project is a well-thought interface for the terminal. -The project allows users to register with their username, password, and phone number while an admin is hard-coded into the application. The user can view the current movies in the listing, select the movie to view available shows and seats and book the ticket. The admin can change the ticket price, add a film to the listing, create shows, and view already booked shows and earned balance. +The project allows users to register with their username, password, and phone number while an admin is hard-coded into the application. The user can view the current movies in the listing, select the film to view available shows and seats and book the ticket. The admin can change the ticket price, add a film to the listing, create shows, and view already booked shows and earned balance. ## How to run the project?? -- Download all the files in one folder it must include `extra.h`, `main.c`, `users.txt`, `user.c`, `login.c`, `admin.c` file. +- Download all the files in one folder it must include `extra.h`, `main.c`, `users.txt`, `user.c`, `login.c`, and `admin.c` files. - Run `gcc main.c -o main` or Build `main.c` file. -- Run `./main` or execute `main.c` file. -- `Admin-interface` access is hardcoded and for its access: +- Run `./main` or execute the `main.c` file. +- `admin-interface` access is hardcoded and the credentials are: - Username: `Abhishek` - Password: `pass` ## Additional Info: -The project is a infinitely run system and it offers optimum facility if run infinitely. You can exit the coding system by `CTRL+C` but we recomend to use the available options in the interface that we created to run the program. If by any chance the system is exited in the middle of execution all the data changed will be flushed. +- Previously, when the project was presented in front of our respected teacher there was a big loophole with the project i.e on exiting the program with `CTRL + C` all of the changed data would be flushed except for user data which was saved with file handling. + +- But, now with updated code all of the data that are changed will be intact in three files `reserve.txt`, `movies.txt`, and `users.txt` +and loaded as the user interacts with the program. +- If in any case there is an issue with executing `main.exe` you can delete it and rerun the program. If there is an issue with files, the files can just be deleted and they will be created again by the program itself. diff --git a/BEI/Eastern CinePlex/reserve.txt b/BEI/Eastern CinePlex/reserve.txt new file mode 100644 index 0000000..671c79c Binary files /dev/null and b/BEI/Eastern CinePlex/reserve.txt differ diff --git a/BEI/Eastern CinePlex/user.c b/BEI/Eastern CinePlex/user.c index 9bf0b2f..866022b 100644 --- a/BEI/Eastern CinePlex/user.c +++ b/BEI/Eastern CinePlex/user.c @@ -1,251 +1,281 @@ -// For Dhiraj Bikram Rai and Abhishek Niraula -// User part of things -char username[30]; - -int user_interface(char name[]) -{ - // Interface to select movies and about film hall price of ticket etc is accessible through here. - pattern(); - strcpy(username, name); - printf("\tWELCOME --%s--\n\tPLEASE SELECT...\n\t1)OUR AVAILABLE SHOWS\n\t2)INFO ABOUT OUR CINEPLEX \n\t3)LOGOUT\n \t4)EXIT", name); - pattern(); - printf("Enter your choice : "); - int n, a; - while (a != 4) - { - scanf("%d", &n); - switch(n) - { - case 1: - see_shows(); - a = 4; - break; - case 2: - cineplex_info(); - a = 4; - break; - case 3: - logout(); - a = 4; - break; - case 4: - a = 4; - break; - default: - printf("INVALID INPUT\n"); - break; - } - } -} - -// See which shows are available in the movie hall and select a particular date -int see_shows(void) -{ - pattern(); - printf("\tPLEASE SELECT FROM THE AVALABLE SHOWS HERE\n"); - - // Temporary array to store shows date : Given month is a constant, K represents the number of shows (distinct). - int k = 0, temp[5]; - char temp2[5][8]; - - // Code to filter out repeated dates from the shows in movie structure. - for (int i = 0; i < movies_count; i++) - { - int counter = 0; - for (int j = i+1; j < movies_count; j++) - { - if (film[i].screening_day == film[j].screening_day) - { - counter++; - } - } - if (counter == 0) - { - // Storing the shows in temporary array - temp[k] = film[i].screening_day; - strcpy(temp2[k], film[i].screening_month); - k++; - } - } - for (int i = 0; i < k; i++) - { - printf("\t%d) %d'th of %s\n",i + 1,temp[i], temp2[i]); - } - printf("\t%d) EXIT\n", k+1); - pattern(); - printf("Enter your choice : "); - int n; - // An infinite loop that runs until the user selects valid shows or opts to exit. - while (true) - { - scanf("%d", &n); - if (n > 0 && n <= (k + 1)) - { - break; - } - else - { - printf("\tINVALID SHOW. PLEASE RE-ENTER VALID SHOW.\n"); - continue; - } - } - // Mimicing the function of - if (n < (k+1)) - { - see_movies(temp[n-1], temp2[n-1]); - } - return 0; -} -int see_movies(int day, char month[]) -{ - pattern(); - printf("\tSHOW: %d'th of %s\n\tPLEASE SELECT AVAILABLE MOVIES..\n", day, month); - char movie[5][30]; - int k = 0; - for (int i = 0; i < movies_count; i++) - { - // If the date is equal to the date selected by the user return that movie name - if (film[i].screening_day == day && strcmp(month, film[i].screening_month) == 0) - { - int a = film[i].length/60; - int b = film[i].length - a * 60; - - int ending_time = film[i].starting_time + a; - if (b == 0 ) - { - k++; - printf("\t%d) %s: FROM %dPM to %dPM\n", k, film[i].name, film[i].starting_time, ending_time); - printf("\t\tDirected By: %s\n\t\tGenre: %s\n", film[i].director, film[i].genre); - strcpy(movie[k-1], film[i].name); - - } - else { - k++; - printf("\t%d) %s: FROM %dPM to %d:%dPM\n", k, film[i].name, film[i].starting_time, ending_time,b); - printf("\t\tDirected By: %s\n\t\tGenre: %s\n", film[i].director, film[i].genre); - strcpy(movie[k-1], film[i].name); - } - } - } - printf("\t%d) Exit\n", k+1); - pattern(); - printf("Enter your choice : "); - // An infinite loop that runs until the user selects valid shows or opts to exit. - int n; - while (true) - { - scanf("%d", &n); - if (n > 0 && n <= (k + 1)) - { - break; - } - else - { - printf("\tINVALID MOVIE. PLEASE RE-ENTER VALID MOVIE.\n"); - continue; - } - } - // Mimicing the function of calling function withing certain limit if exceeds exits the function. - if (n < (k+1)) - { - book_seats(movie[n-1]); - } - -} -int display_seats(int seats[], int num_seats) -{ - printf("\n\n\t\tAvailable Seats:\n\n"); - for (int i = 0; i < num_seats; i++) - { - if(seats[i] == 0) - { - printf("%d\t", i + 1); - } - else { - printf("*\t"); - } - if ( (i+1) % 10 == 0) - { - printf("\n"); - } - } -} -int book_seats(char name[]) -{ - pattern(); - int film_index; - for (int i = 0; i < movies_count; i++) - { - if (strcmp(name, film[i].name) == 0) - { - printf("\t%s\n\tDirected By: %s\n\tGenre: %s", film[i].name, film[i].director, film[i].genre); - film_index = i; - } - } - printf("\nThe current price of the ticket is: %d", ticket_price); - display_seats(film[film_index].seats, film[film_index].num_seats); - pattern(); - - int numTickets; - printf("Enter the number of tickets: "); - scanf("%d", &numTickets); - - if (numTickets < 1 || numTickets > film[film_index].num_seats) { - printf("Invalid number of tickets.\n"); - user_interface(username); - return 1; - } - printf("Are you sure you want to purchase tickets?(Y/N)\n"); - char change; - scanf(" %c", &change); - if ((change != 'y') && (change != 'Y')) - { - printf("Quitting!!!\n"); - user_interface(username); - return 0; - } - printf("Enter the seat numbers:\n"); - for (int i = 0; i < numTickets; i++) { - int seat; - scanf("%d", &seat); - - if (seat < 1 || seat > film[film_index].num_seats || film[film_index].seats[seat - 1] == 1) { - printf("\tInvalid seat number or already booked.\n"); - book_seats(name); - return 1; - } - - film[film_index].seats[seat - 1] = 1; - reserve[reservation_count].seats[i] = seat; - } - strcpy(reserve[reservation_count].movies,film[film_index].name); - strcpy(reserve[reservation_count].name, username); - reserve[reservation_count].num_seats = numTickets; - reserve[reservation_count].balance = numTickets * ticket_price; - reservation_count++; - printf("\t\t\t\tEastern CinePlex\n\t\t\tLangali Chowk, Dharan\n\t\t\tFilm: %s\n\t\t\tYour total billed price (including taxes) will be: NRS.%d\n",film[film_index].name, numTickets * ticket_price); - printf("\t\t\tTickets booked successfully -- %s!\n", username); - user_interface(username); - return 0; -} -int cineplex_info(void) -{ - pattern(); - printf("\tQFX CINEPLEX DETAILS:\n"); - printf("\t- Location: Langali Chowk, Dharan\n"); - printf("\t- Seating Options: Recliner Seats\n"); - printf("\t- Ventilation: Centralized Air Conditioning\n"); - printf("\t- Sound Quality: Dolby Atmos Surround Sound\n"); - printf("\t- Cafe Features:\n"); - printf("\t - Variety of snacks and beverages\n"); - printf("\t - Comfortable seating area\n"); - printf("\t - WiFi access\n"); - printf("\t- Timings: Open from 1:00 PM to 11:00 PM\n"); - printf("\n\tPRICES:\n"); - printf("\t - Per Seat: NRS. %d\n", ticket_price); - pattern(); - printf(("Press any key to exit....")); - getch(); - user_interface(username); - return 0; +// For Dhiraj Bikram Rai and Abhishek Niraula +// User part of things +char username[30]; + +int user_interface(char name[]) +{ + // Interface to select movies and about film hall price of ticket etc is accessible through here. + pattern(); + strcpy(username, name); + printf("\tWELCOME --%s--\n\tPLEASE SELECT...\n\t1)OUR AVAILABLE SHOWS\n\t2)INFO ABOUT OUR CINEPLEX \n\t3)LOGOUT\n \t4)EXIT", name); + pattern(); + printf("Enter your choice : "); + int n, a; + while (a != 4) + { + scanf("%d", &n); + switch(n) + { + case 1: + see_shows(); + a = 4; + break; + case 2: + cineplex_info(); + a = 4; + break; + case 3: + logout(); + a = 4; + break; + case 4: + a = 4; + break; + default: + printf("INVALID INPUT\n"); + break; + } + } +} + +// See which shows are available in the movie hall and select a particular date +int see_shows(void) +{ + pattern(); + printf("\tPLEASE SELECT FROM THE AVALABLE SHOWS HERE\n"); + + // Temporary array to store shows date : Given month is a constant, K represents the number of shows (distinct). + int k = 0, temp[5]; + char temp2[5][8]; + + // Code to filter out repeated dates from the shows in movie structure. + for (int i = 0; i < movies_count; i++) + { + int counter = 0; + for (int j = i+1; j < movies_count; j++) + { + if (film[i].screening_day == film[j].screening_day) + { + counter++; + } + } + if (counter == 0) + { + // Storing the shows in temporary array + temp[k] = film[i].screening_day; + strcpy(temp2[k], film[i].screening_month); + k++; + } + } + for (int i = 0; i < k; i++) + { + printf("\t%d) %d'th of %s\n",i + 1,temp[i], temp2[i]); + } + printf("\t%d) Return to User Interface\n", k+1); + printf("\t%d) Exit\n", k+2); + pattern(); + printf("Enter your choice : "); + int n; + // An infinite loop that runs until the user selects valid shows or opts to exit. + while (true) + { + scanf("%d", &n); + if (n > 0 && n <= (k + 1)) + { + break; + } + else + { + printf("\tINVALID SHOW. PLEASE RE-ENTER VALID SHOW.\n"); + continue; + } + } + // Mimicing the function of + if (n < (k+1)) + { + see_movies(temp[n-1], temp2[n-1]); + } + else if ( n == (k+1)) + { + printf("\tReturning to user Interface!!!"); + user_interface(username); + } + else { + return 0; + } + return 0; +} +int see_movies(int day, char month[]) +{ + pattern(); + printf("\tSHOW: %d'th of %s\n\tPLEASE SELECT AVAILABLE MOVIES..\n", day, month); + char movie[5][30]; + int k = 0; + for (int i = 0; i < movies_count; i++) + { + // If the date is equal to the date selected by the user return that movie name + if (film[i].screening_day == day && strcmp(month, film[i].screening_month) == 0) + { + int a = film[i].length/60; + int b = film[i].length - a * 60; + + int ending_time = film[i].starting_time + a; + if (b == 0 ) + { + k++; + printf("\t%d) %s: FROM %dPM to %dPM\n", k, film[i].name, film[i].starting_time, ending_time); + printf("\t\tDirected By: %s\n\t\tGenre: %s\n", film[i].director, film[i].genre); + strcpy(movie[k-1], film[i].name); + + } + else { + k++; + printf("\t%d) %s: FROM %dPM to %d:%dPM\n", k, film[i].name, film[i].starting_time, ending_time,b); + printf("\t\tDirected By: %s\n\t\tGenre: %s\n", film[i].director, film[i].genre); + strcpy(movie[k-1], film[i].name); + } + } + } + printf("\t%d) Return to User Interface\n", k+1); + printf("\t%d) Exit\n", k+2); + pattern(); + printf("Enter your choice : "); + // An infinite loop that runs until the user selects valid shows or opts to exit. + int n; + while (true) + { + scanf("%d", &n); + if (n > 0 && n <= (k + 2)) + { + break; + } + else + { + printf("\tINVALID CHOICE.\n"); + continue; + } + } + // Mimicing the function of calling function withing certain limit if exceeds exits the function. + if (n < (k+1)) + { + book_seats(movie[n-1]); + } + else if (n == (k + 1)) + { + printf("\tReturning to user Interface!!!"); + user_interface(username); + } + else { + return 0; + } + return 0; +} +int display_seats(int seats[], int num_seats) +{ + printf("\n\n\t\tAvailable Seats:\n\n"); + for (int i = 0; i < num_seats; i++) + { + if(seats[i] == 0) + { + printf("%d\t", i + 1); + } + else { + printf("*\t"); + } + if ( (i+1) % 10 == 0) + { + printf("\n"); + } + } +} +int book_seats(char name[]) +{ + pattern(); + int film_index; + for (int i = 0; i < movies_count; i++) + { + if (strcmp(name, film[i].name) == 0) + { + printf("\t%s\n\tDirected By: %s\n\tGenre: %s", film[i].name, film[i].director, film[i].genre); + film_index = i; + } + } + printf("\nThe current price of the ticket is: %d", ticket_price); + display_seats(film[film_index].seats, film[film_index].num_seats); + pattern(); + + int numTickets; + printf("Enter the number of tickets: "); + scanf("%d", &numTickets); + + if (numTickets < 1 || numTickets > film[film_index].num_seats) { + printf("Invalid number of tickets.\n"); + user_interface(username); + return 1; + } + printf("Are you sure you want to purchase tickets?(Y/N)\n"); + char change; + scanf(" %c", &change); + if ((change != 'y') && (change != 'Y')) + { + printf("Quitting!!!\n"); + user_interface(username); + return 0; + } + printf("Enter the seat numbers:\n"); + for (int i = 0; i < numTickets; i++) { + int seat; + scanf("%d", &seat); + + if (seat < 1 || seat > film[film_index].num_seats || film[film_index].seats[seat - 1] == 1) { + printf("\tInvalid seat number or already booked.\n"); + book_seats(name); + return 1; + } + + film[film_index].seats[seat - 1] = 1; + reserve[reservation_count].seats[i] = seat; + } + strcpy(reserve[reservation_count].movies,film[film_index].name); + strcpy(reserve[reservation_count].name, username); + reserve[reservation_count].num_seats = numTickets; + reserve[reservation_count].balance = numTickets * ticket_price; + reservation_count++; + printf("\t\t\t\tEastern CinePlex\n\t\t\tLangali Chowk, Dharan\n\t\t\tFilm: %s\n\t\t\tYour total billed price (including taxes) will be: NRS.%d\n",film[film_index].name, numTickets * ticket_price); + printf("\t\t\tTickets booked successfully -- %s!\n", username); + + // Saving booked seats info into the file "movies.txt". + if (saveMoviesToFile(film, movies_count) != 0) + { + printf("Error saving movie data to file.\n"); + } + + // Saving reservatio data into file "reserve.txt". + if (saveReservationToFile(reserve, reservation_count) != 0) + { + printf("Error saving reservation data to file.\n"); + } + user_interface(username); + return 0; +} +int cineplex_info(void) +{ + pattern(); + printf("\tQFX CINEPLEX DETAILS:\n"); + printf("\t- Location: Langali Chowk, Dharan\n"); + printf("\t- Seating Options: Recliner Seats\n"); + printf("\t- Ventilation: Centralized Air Conditioning\n"); + printf("\t- Sound Quality: Dolby Atmos Surround Sound\n"); + printf("\t- Cafe Features:\n"); + printf("\t - Variety of snacks and beverages\n"); + printf("\t - Comfortable seating area\n"); + printf("\t - WiFi access\n"); + printf("\t- Timings: Open from 1:00 PM to 11:00 PM\n"); + printf("\n\tPRICES:\n"); + printf("\t - Per Seat: NRS. %d\n", ticket_price); + pattern(); + printf(("Press any key to exit....")); + getch(); + user_interface(username); + return 0; } \ No newline at end of file diff --git a/BEI/Eastern CinePlex/users.txt b/BEI/Eastern CinePlex/users.txt index 15c58a3..858aafd 100644 --- a/BEI/Eastern CinePlex/users.txt +++ b/BEI/Eastern CinePlex/users.txt @@ -1,5 +1,5 @@ - -Prashan Rai -Prashan Rai -Prashan Rai + +Prashan Rai +Prashan Rai +Prashan Rai Abhishek Niraula \ No newline at end of file