Page

Movie Booking System In C/C++

#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
void search();
void current_movie();
void main_menu();
void book();
void print_ticket();
void add_hall();
void list_movie();
void ticket_cancel();
void screen();
typedef struct
{
int mid;
int hid;
char hname[40];
char mname[30];
char actor[30];
char actoress[30];
char r_date[30];
}movie;
typedef struct
{
char hname[30];
char area[30];
int id;
int a_seat;
int d_seat;
}hall;
typedef struct
{
char name[30];
char gender;
char c_type[10];
int age;
int amount;
int seat_no;
int tno;
}ticket;
FILE *fm,*ft,*fh;
void main()
{
clrscr();
screen();
delay(7000);
main_menu();
getch();
}
void screen()
{
textcolor(BLUE);
gotoxy(20,4);
cprintf("sourcecodernp.blogspot.com");
gotoxy(30,6);
cprintf("Project on");
gotoxy(25,8);
cprintf("Movie Booking System");
gotoxy(20,10);
}
void main_menu()
{
int ch;
clrscr();
gotoxy(30,2);
cprintf("Main Menu");
gotoxy(30,4);
cprintf("Add Hall Information  [1] ");
gotoxy(30,6);
cprintf("Add Current Movie     [2]");
gotoxy(30,8);
cprintf("Book Ticket           [3]");
gotoxy(30,10);
cprintf("List of Current Movie [4]");
gotoxy(30,12);
cprintf("Ticket Cancel         [5]");
gotoxy(30,14);
cprintf("Search Movie          [6]");
gotoxy(30,16);
cprintf("Exit                  [7]");
gotoxy(30,18);
cprintf("Enter Your Choice : ");
scanf("%d",&ch);
while(1)
{
switch(ch)
{
case 1:
add_hall();
break;
case 2:
current_movie();
break;
case 3:
book();
break;
case 4:
list_movie();
break;
case 5:
ticket_cancel();
break;
case 6:
search();
break;
case 7:
exit(1);
break;
default:
main_menu();
}
}
}
void current_movie()
{
char another='Y';
movie m;
fm=fopen("movie.dat","ab");
while(another=='Y'||another=='y')
{
fflush(stdin);
printf("\nEnter Movie ID:");
scanf("%d",&m.mid);
fflush(stdin);
printf("Enter Hall ID  :");
scanf("%d",&m.hid);
fflush(stdin);
printf("Enter Hall Name :");
gets(m.hname);
fflush(stdin);
printf("\nEnter Movie Name:");
gets(m.mname);
fflush(stdin);
printf("\nEnter Actor Name:");
gets(m.actor);
fflush(stdin);
printf("\nEnter Actoress Name:");
gets(m.actoress);
fflush(stdin);
printf("\nEnter Releas Year:");
gets(m.r_date);
fwrite(&m,sizeof(m),1,fm);
printf("\n\nRecords is Added");
printf("\n\nAdd record(Y/N) : ");
another=getche();
}
fclose(fm);
main_menu();
}
void book()
{
int ch;
char another='Y';
ticket t;
clrscr();
ft=fopen("ticket.dat","wb");
while(another=='Y'||another=='y')
{
fflush(stdin);
printf("Enter Name:");
gets(t.name);
fflush(stdin);
printf("Enter Gender(M/F):");
scanf("%c",&t.gender);
fflush(stdin);
printf("Enter age");
scanf("%d",&t.age);
fflush(stdin);
printf("\nEnter Class Type");
printf("1.AC");
printf("2.DC");
scanf("%d",&ch);
switch(ch)
{
case 1:
t.amount=400;
break;
case 2:
t.amount=200;
break;
default:
printf("Input is in Valid");
break;
}
printf("Class Type : %s",t.c_type);
printf("Total Amount : %d",t.amount);
fflush(stdin);
printf("\n\nEnter Seat No:");
scanf("%d",&t.seat_no);
printf("\n\nEnter ticket No:");
scanf("%d",&t.tno);
fwrite(&t,sizeof(t),1,ft);
printf("\n\nRecords is Updated");
printf("\n\nAdd another Record : ");
fflush(stdin);
another=getche();
}
fclose(fm);
}
void add_hall()
{
char another='Y';
hall h;
clrscr();
fh=fopen("hall.dat","wb");
while(another=='Y'||another=='y')
{
fflush(stdin);
printf("\nEnter Hall ID:");
scanf("%d",&h.id);
fflush(stdin);
printf("\nEnter Hall Name:");
gets(h.hname);
fflush(stdin);
printf("\nEnter Area Name:");
gets(h.area);
fflush(stdin);
printf("\nEnter Total AC Seat:");
scanf("%d",&h.a_seat);
fflush(stdin);
printf("\nEnter Total DC Seat  : ");
scanf("%d",&h.d_seat);
fwrite(&h,sizeof(h),1,fh);
printf("\n\nRecords is Added");
printf("\n\nAdd record(Y/N) : ");
another=getche();
}
fclose(fh);
main_menu();
}
void list_movie()
{
int i=1;
movie m;
clrscr();
fm=fopen("movie.dat","rb");
while(fread(&m,sizeof(m),1,fm)==1)
{
gotoxy(30,3);
printf("All Movie Information");
printf("\n\t\t*********************************************");
printf("\n\n\t\tMovie ID        :  %d",m.mid);
printf("\n\n\t\tHall ID         :  %d",m.hid);
printf("\n\n\t\tMovie Name      :  %s",m.mname);
printf("\n\n\t\tHall Name       :  %s",m.hname);
printf("\n\n\t\tActor Name      :  %s",m.actor);
printf("\n\n\t\tActoress Name   :  %s",m.actoress);
printf("\n\n\t\tRealse Year     :  %s",m.r_date);
if(i%1==0)
{
printf("\n\n\n\t\tPress any key to continue");
fflush(stdin);
getch();
clrscr();
}
i++;
}
printf("\n\nPress any key to back Main menu");
getch();
main_menu();
fclose(fm);
}
void ticket_cancel()
{
int t_id,c=1;
ticket t;
FILE *ftd;
char another='y';
clrscr();
while(another=='y'||another=='Y')
{
ftd=fopen("temp.dat","wb");
ft=fopen("ticket.dat","rb");
printf("\n\nEnter Ticket No For Cancelation     :");
scanf("%d",&t_id);
while(fread(&t,sizeof(t),1,ft)==1)
{
if(t.tno==t_id)
{
c++;
}
else
{
fwrite(&t,sizeof(t),1,ftd);
}
}
fclose(ftd);
fclose(ft);
remove("ticket.dat");
rename("temp.dat","ticket.dat");
if(c);
{
printf("\n\nBook is Deleted");
printf("You want to delete another record :");
}
fflush(stdin);
another=getche();
}
main_menu();
}
void search()
{
int hid;
movie m;
char another;
clrscr();
fm=fopen("movie.dat","rb");
another='y';
printf("\nEnter Hall Id No:");
scanf("%d",&hid);
while(fread(&m,sizeof(m),1,fm)==1)
{
if(m.hid==hid)
{
printf("\n\nHall is found");
printf("\n\n\t\tHall ID                 :  %d",m.hid);
printf("\n\n\t\tMovie ID                :  %d",m.mid);
printf("\n\n\t\tMovie Name              :  %s",m.mname);
printf("\n\n\t\tHall Name               :  %s",m.hname);
printf("\n\n\t\tActor Name              :  %s",m.actor);
printf("\n\n\t\tActoress Name           :  %s",m.actoress);
printf("\n\n\t\tRealse Year             :  %s",m.r_date);
printf("\n\nYou want to search another flight(Y/N) :");
fflush(stdin);
another=getchar();
if(another=='y'||another=='Y')
search();
else
{
fclose(fm);
main_menu();
}
}
}
printf("\n\nHall is not available");
printf("\n\nDo you want to Search another medicine(Y/N) :");
fflush(stdin);
another=getchar();
if(another=='Y'||another=='y')
search();
else
{
fclose(fm);
}
getch();
main_menu();
}

No comments:

Post a Comment