V
Vasudevan
16 Nov 18

//CS

include

include

include

include

include

include

int ad=0,cs=0,cls1,cls2,balc; class Theatre {  private:  char pass[24];  protected:  char m1[100];  float fcl,tcl,bal; //fcl->1st class, tcl->2nd class, bal->Balcony  public:  Theatre();  void admin();  void check();  void display();  void clear(); }; Theatre::Theatre() {  strcpy(pass,"abc123");  strcpy(m1,"Odiyan");  tcl=100;  fcl=150;  bal=200; } class Theatre {  public:  char name[50],ph[15];  int num;  void book();  void check2(char[],char[]);  void cancel(char[],char[]);  void bill(int);  void view(char[],char[]);  void menu(); }u1; class user {  public:  char Name[50],Ph[15],seat[10];  int Num;  int getseat(int); }; void choice(); void main() {  clrscr();  int ch;  char c;  cout<<"\n\t\tMOVIE RESERVATION\n ";  choice();  getch() ; } void choice() {  clrscr();  int ch;  char c;  cout<<"\nChoose your option\n";  cout<<"[1]Admin\n[2]User\n[3]Exit\n";  cin>>ch;  switch(ch)  {   case 1:   u1.admin();   break;   case 2:   u1.menu();   break;   case 3:   cout<<"\nAre you sure you want to exit ?(Y/N)";   cin>>c;   if(c=='y'||c=='Y')   {    exit(0);   }   else   {    choice();   }   default:   cout<<"Try Again ";   choice();   break;

} } int user::getseat(int x) {  user cus;  cls1=0,cls2=0,balc=0;  ifstream f("Cinema.dat",ios::in);  f.seekg(0);  while(f.read((char*)&cus,sizeof(cus)))  {   if(strcmp(cus.seat,"1st class")==0)   {    cls1=cls1+cus.Num;   }   else if(strcmp(cus.seat,"2nd class")==0)   {    cls2=cls2+cus.Num;   }   else if(strcmp(cus.seat,"Balcony")==0)   {    balc=balc+cus.Num;   }   if(f.eof())   {    break;   }

}  f.close();  if(x==1)  {   return cls2;  }  if(x==2)  {   return cls1;  }  if(x==3)  {   return balc;  }  return 0; } void User::menu() {  clrscr();  int ch;  char x;  if(cs==0)  {   cout<<"\nLogin\n";   cout<<"\nEnter your name (USERNAME) : ";   gets(name);   cout<<"\nEnter your phone number(PASSWORD) : ";   gets(ph);   cs=1;  }  clrscr();  cout<<"Welcome "<<name;  cout<<"\nMenu ";  cout<<"\n\t[1] Book ticket";  cout<<"\n\t[2] Cancel ticket";  cout<<"\n\t[3] View Reservations";  cout<<"\n\t[4] Logout";  cout<<"\n\tEnter your choice(1-4): ";  cin>>ch;  switch(ch)  {   case 1:   check2(name,ph);   book();   break;   case 2:   cancel(name,ph);   break;   case 3:   view(name,ph);   break;   case 4:   cs=0;   cout<<"Thank You,"<<name;   getch();   choice();   break;   default:   cout<<"Try Again ";   choice();   break;  } } void User::check2(char name[32],char ph[15]) {  user cus;  ifstream file("Cinema.dat",ios::in);  file.seekg(0);  while(file.read((char)&cus,sizeof(cus)))  {   if((strcmp(cus.Name,name)==0)&&(strcmp(cus.Ph,ph)==0))   {    cout<<"You have already booked tickets... To change reseravtion please cancel and book again.";    getch();    menu();   }  } } void User::book() {  user cus;  clrscr();  int chs,re;     //chs-seat choice  cout<<"\nMOVIE : "<<m1;  cout<<"Choose your seat type (1/2/3): ";  cout<<"\n1.2nd class(1-40) \t cost : Rs. "<<tcl;  cout<<"\n2.1st class (41-80)\t cost : Rs."<<fcl;  cout<<"\n3.Balcony (81-120)\t cost : Rs."<<bal<<"\n";  cin>>chs;  if(chs!=1&&chs!=2&&chs!=3)  {   cout<<"Choice invalid try again!!!\n";   book();  }  int no;  strcpy(cus.Name,name);  strcpy(cus.Ph,ph);  if(chs==1)  {   strcpy(cus.seat,"2nd class");   no=cus.getseat(chs);  }  if(chs==2)  {   strcpy(cus.seat,"1st class");   no=cus.getseat(chs);  }  if(chs==3)  {   strcpy(cus.seat,"Balcony");   no=cus.getseat(chs);  }  cout<<"\n \nNumber of Seats required\n ";  cin>>num;  cus.Num=num;  no=no+num;  if(no>40)  {   chs=0;   bill(chs);  }  fstream file;  file.open("Cinema.dat",ios::app);  file.write((char)&cus,sizeof(cus));  file.close();  bill(chs);  getch(); } void User::bill(int chs) {  float money,total;  if(chs==0)  {   cout<<"Sorry... Seat reservation failed\n ";   cout<<"Seats you are trying to  book are not available...\n Please Try Again";   getch();   menu();  }  else  {   cout<<"\nSeat reserved";   cout<<"\n\t\tYour Bill\n";   cout<<"\nMovie:"<<m1;   cout<<"\nSeat Type: ";   switch(chs)   {    case 1:    cout<<"\n2nd Class";    money=tcl;    break;    case 2:    cout<<"\n1st Class";    money=fcl;    break;    case 3:    cout<<"\nBalcony";    money=bal;    break;   }   cout<<"\t\tRs."<<money;   total=moneynum;   cout<<"\nTotal: "<<total;   char x;   getch();   menu();  } } void User::view(char n[32],char p[15]) {  user cus;  char found='n';  ifstream file("Cinema.dat",ios::in);  file.seekg(0);  while(!file.eof())  {   file.read((char)&cus,sizeof(cus));   if((strcmp(cus.Name,n)==0)&&(strcmp(cus.Ph,p)==0))   {    cout<<"\nName : "<<cus.Name;    cout<<"\nPhone Number : "<<cus.Ph;    cout<<"\nSeat Type : "<<cus.seat;    cout<<"\nNumber of seats : "<<cus.Num<<"\n";    found='y';    break;   }  }  if(found=='n')  {   cout<<"\nSorry... Match Not Found\nPlease recheck Name(case sensitive) and phone number...\n";  }  getch();  menu(); }

void User::cancel(char n[32],char p[15]) {  user cus;  char found='n',confirm='n';  ifstream file("Cinema.dat",ios::in);  ofstream temp("Temp.dat",ios::out);  file.seekg(0);  while(file.read((char)&cus,sizeof(cus)))  {   if((strcmp(cus.Name,n)==0)&&(strcmp(cus.Ph,p)==0))   {    cout<<"\nName : "<<cus.Name;    cout<<"\nPhone Number : "<<cus.Ph;    cout<<"\nSeat Type : "<<cus.seat;    cout<<"\nNumber of seats : "<<cus.Num;    found='y';    cout<<"\nAre you sure you want to cancel this reservation?(Y/N) : ";    cin>>confirm;    if(confirm=='n'||confirm=='N')    {     temp.write((char)&cus,sizeof(cus));    }   }   else   {    temp.write((char)&cus,sizeof(cus));   }  }  if(found=='n')  {   cout<<"\nSorry... Match Not Found\nPlease recheck Name(case sensitive) and phone number...\n";   menu();  }  temp.close();  file.close();  remove("Cinema.dat");  rename("Temp.dat","Cinema.dat");  if(confirm=='y'||confirm=='Y')  {   cout<<"Reservation cancelled! Returning to main menu...";  }  getch();  menu(); } void Theatre::admin() {  clrscr();  int ch;  if(ad==0)  {   check();   ad=1;  }  clrscr();  cout<<"\nWelcome Admin,\n";  cout<<"\nChoose your activity :- ";  cout<<"\n[1]View Reservation ";  cout<<"\n[2]Clear Reservation ";  cout<<"\n[3]Logout \n";  cin>>ch;  switch(ch)  {   case 1:   {    user cus;    cus.getseat(0);    cout<<"\nSEATS BOOKED\n";    cout<<"\n2nd class : "<<cls2;    cout<<"\n1st class : "<<cls1;    cout<<"\nBalcony : "<<balc;    getch();    admin();    break;   }   case 2:   {    clear();    break;   }   case 3:   {    ad=0;    choice();    break;   }   default:   {    cout<<"\nChoice invalid Try again ";    admin();    break;   }  } } void Theatre::clear() {  ofstream file;  file.open("Cinema.dat",ios::out);  file.close();  cout<<"\nReservation cleared...\nReturn to admin page ";  getch();  admin(); } void Theatre::check() {  char password[24],ch;  cout<<"User ";  cout<<"Password : ";  for(int i=0;i<24;i++)  {   password[i]=getch();   if(password[i]=='\r')   {    password[i]='\0';    break;   }   else   cout<<"";  }  if(strcmp(pass,password)!=0)  {   cout<<"Password incorrect...";   cout<<"Would You like to try again(Y/N) ";   cin>>ch;   if(ch=='y'||ch=='Y')   {    check();   }   else   {    cout<<"\nReturning to main menu ";    getch();    choice();   }  } }

Replies to this post

S
Surya

What is this ? And why are you posting it here? Please don't spam this forum.

2