//CS
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
} } 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
What is this ? And why are you posting it here? Please don't spam this forum.