Sei sulla pagina 1di 14

#include<fstream.h> #include<conio.h> #include<graphics.h> #include<string.h> #include<process.h> #include<stdlib.h> #include<stdio.h> #include<ctype.

h> struct date { int dd,mm,yy; }; class menu { private: void edit_menu(); void report_menu(); void room_edit_menu(); void customer_edit_menu(); public: void intro(); void main_menu(); }; class room { private: char cust_name[16]; char cust_add[35]; int recordno(int); int roomno,flrno; char type[5],status;//type can be "ORD" "SDEL" "DEL" float tariff;//status can be "V"=vacant "O"=occupied "R"=under r epair "U"=under upgradation public: void add (); void modify(); void deletion(); void display_rsp(int); int room_found(int); void change_status(int,char,char*,char*); char room_status(int); float get_data(int); }; class customer { private: int recordno(int); void delete_record(int); int roomno,flrno; char name[21],add[35]; float advance; int nod;//no of days of stay public: void checkin (); void checkout (); void modify(); void deletion(); int no_cust(int,int) int display_mcr(int,int,int); date d_in,d_out;

}; void menu::intro () { clrscr(); gotoxy(30,3); cout<<"Welcome to Project"; gotoxy(30,5); cout<<" Hotel Management "; gotoxy(30,6); cout<<" ----- ---------- "; gotoxy(15,8); cout<<"This project has the facility of maintaining "; gotoxy(15,9); cout<<"records of ROOMS and CUSTOMERS."; gotoxy(15,14); cout<<"This project is very easy to work on and has self"; gotoxy(15,15); cout<<"explanatory menus."; gotoxy(15,17); cout<<"\t"; gotoxy(20,23); cout<<"Press any key to continue..."; getch(); main_menu(); } void menu::main_menu() { char ch; clrscr(); gotoxy(14,2); cout<<"*********** M . A . I . N - M . E . N . U ***********"; gotoxy(30,5); cout<<"1. INTRODUCTION"; gotoxy(30,7); cout<<"2. CHECK IN"; gotoxy(30,9); cout<<"3. CHECK OUT"; gotoxy(30,11); cout<<"4. CUSTOMER RECORD"; gotoxy(30,13); cout<<"5. ROOM RECORD"; gotoxy(30,15); cout<<"6. EDIT"; gotoxy(30,17); cout<<"7. REPORT"; gotoxy(30,19); cout<<"8. EXIT TO DOS"; gotoxy(55,25); gotoxy(30,21); cout<<"Enter your choice:"; cin>>ch; getch(); if (ch=='1') intro(); else if (ch=='2') { customer c; c.checkin(); }

else if (ch=='3') { customer c; c.checkout(); } if (ch=='4') { customer c; c.display_customer_record(); } else if (ch=='5') { room r; r.display_room_record(); } else if (ch=='6') edit_menu(); else if (ch=='7') report_menu(); else if (ch=='8') { getch(); exit(0); } } void menu::edit_menu() { char ch; while(1) { clrscr(); gotoxy(34,4); cout<<" EDIT"; gotoxy(30,8); cout<<"1. ROOM RECORDS"; gotoxy(30,10); cout<<"2. CUSTOMER RECORDS"; gotoxy(30,12); cout<<"3. BACK"; gotoxy(30,15); cout<<"Enter your choice:"; cin>>ch; if (ch=='1') room_edit_menu(); else if (ch=='2') customer_edit_menu(); else if (ch=='3') main_menu(); } } void menu::room_edit_menu() {

char ch; while(1) { clrscr(); gotoxy(34,4); cout<<"EDIT ROOM"; gotoxy(30,8); cout<<"1. ADD ROOM RECORDS"; gotoxy(30,10); cout<<"2. MODIFY ROOM RECORDS"; gotoxy(30,12); cout<<"3. DELETE ROOM RECORDS"; gotoxy(30,14); cout<<"4. BACK"; gotoxy(30,17); cout<<"Enter your choice:"; cin>>ch; if (ch=='1') { room r; r.add(); } else if (ch=='2') { room r; r. modify(); } else if (ch=='3') { room r; r.deletion(); } else if (ch=='4') break; } } void menu::customer_edit_menu() { char ch; while(1) { clrscr(); gotoxy(34,4); cout<<"EDIT CUSTOMER"; gotoxy(30,8); cout<<"1. MODIFY CUSTOMER RECORDS"; gotoxy(30,10); cout<<"2. DELETE CUSTOMER RECORDS"; gotoxy(30,12); cout<<"3. BACK"; gotoxy(30,15); cout<<"Enter your choice:"; cin>>ch; getch(); if (ch=='1') { customer c;

c.modify(); } else if (ch=='2') { customer c; c.deletion(); } else if (ch=='3') break; } } void menu::report_menu() { char ch; while(1) { clrscr(); gotoxy(34,4); cout<<"REPORT"; gotoxy(30,8); cout<<"1.ROOM STATUS REPORT:"; gotoxy(30,10); cout<<"2.MONTHLY COLLECTION REPORT:"; gotoxy(30,12); cout<<"3.TREND REPORT:"; gotoxy(30,15); cout<<"4. BACK:" cout<<"Enter your choice:"; cin>>ch; getch(); if (ch=='1') { int f1=5; room r; ifstream file("ROOM.DAT",ios::binary); file.seekg(0); if(!file) {cout<<"Error";exit(0);} else {while(!file.eof()) { file.read((char*)&r,sizeof(r)); if(file.eof()) break; r.display_rsp(f1++); }} file.close(); } else if (ch=='2') { int f1=6,m,y,x; customer c; ifstream file("CUSTOMER.DAT",ios::binary); file.seekg(0); cout<<"Enter month(mm) and year(yy) of report:"; cin>>m>>y; if(!file)

{cout<<"Error";exit(0);} else { while(!file.eof()) { file.read((char*)&c,sizeof(c)); if(file.eof()) break; if(m==c.d_out.mm && y==c.d_out.yy) x=c.display_mcr(f1++,m,y); } } cout<<"\nTotal no of customers in the month="<<x; file.close(); } } else if (ch=='4') { main_menu(); break; } else if(ch=='3') { trend_report(); } } } void room::display_rsp(int f) { clrscr(); static int sno=1; int i=1; if(f==74 || f==148) i++; if(f>=74) f-=69; if(f>=148) f-=143; while(i<4) { gotoxy(35,1); cout<<"ROOM STATUS REPORT"; gotoxy(1,2); cout<<"DATE="<<d.dd<<"/"<<d.mm<<"/"<<d.yy; gotoxy(75,2); cout<<"PAGENO.="<<i; gotoxy(1,3); cout<<"Sno. | RoomNo. | FlrNO. | Type | Rent | Status | CustomerName | A ddress "; for(int k=1;k<80;k++) { gotoxy(k,4); cout<<"-"; } for(int j=4;j<75;j++) { gotoxy(6,j);cout<<"|"; gotoxy(16,j);cout<<"|"; gotoxy(25,j);cout<<"|"; gotoxy(32,j);cout<<"|";

gotoxy(39,j);cout<<"|"; gotoxy(48,j);cout<<"|"; gotoxy(63,j);cout<<"|"; } gotoxy(1,f);cout<<sno++; gotoxy(7,f);cout<<roomno; gotoxy(17,f);cout<<flrno; gotoxy(26,f);cout<<type; gotoxy(33,f);cout<<tariff; gotoxy(40,f);cout<<status; gotoxy(49,f);cout.write(cust_name,' ',14); gotoxy(64,f);cout.write(cust_add,16); } } void room::change_status(int t_roomno, char t_status,char* t_name="\0", char* t_ add="\0") { int recno; recno=recordno(t_roomno); fstream file("ROOM.DAT",ios::binary|ios::in|ios::ate); int location; location=(recno-1) * sizeof(room); file.seekp(location); status=t_status ; strcpy(cust_name,t_name); strcpy(cust_add,t_add); file.write((char *) this, sizeof(room)); file.close (); } char room::room_status(int t_roomno) { ifstream file("ROOM.DAT", ios::binary); file.seekg(0); int found=0; char t_status; while (file.read((char *) this, sizeof(room)) && !found) { if (t_roomno==roomno) { found=1; t_status=status; } } file.close (); return t_status; } float room::get_data(int t_roomno) { ifstream file("ROOM.DAT", ios::binary); file.seekg(0); float t_tariff; while (file.read((char *)this, sizeof(room))) { if (t_roomno==roomno) { t_tariff=tariff; break; } } file.close();

return t_tariff; } void room::add () { char ch; char t_rtype[5]; int t_floorno,t_roomno; char t_status; float t_tariff; do { ofstream file("ROOM.DAT",ios::app |ios::binary); clrscr(); gotoxy(1,1); cout<<"Enter the details for the room"; cout<<"\nType : "; cin>>t_rtype; cout<<"\nRoom no.: ";cin>>t_roomno; cout<<"\nFloor no.: ";cin>>t_floorno; cout<<"\nStatus : ";gets(t_status); cout<<"\nTariff : "; cin>>t_tariff; strupr(t_rtype); cout<<"\nDo you want to save the record (y/n) : "; cin>>ch; if (ch=='Y'||ch=='y') { strcpy(roomcode,t_rcode); roomno=t_roomno ; flrno=t_floorno; status=t_status ; tariff=t_tariff; file.write((char *) this, sizeof(room)); } cout<<"\nDo you want to add more rooms (y/n): "; cin>>ch; } while (ch=='Y'||ch=='y'); file.close(); } void room::modify() { clrscr(); int valid; char ch; char t_rtype[5]; int t_roomno,tr,t_flrno; char t_status; float t_tariff; ofstream file("ROOM.DAT", ios::binary|ios::out|ios::ate); gotoxy(1,3); cout<<"Enter the Room no. to be modified "; cin>>tr; display_record(tr); cout<<"\n\nDo you want to modify this Room Record (y/n):"; cin>>ch; if (ch=='N'||ch=='n') return; cout<<"ENTER THE NEW DATA FOR THE ROOM"; cout<<"\nType : ";gets(t_rtype); cout<<"\nRoom no.: ";cin>>t_roomno; cout<<"\nFloor no.: ";cin>>t_flrno; cout<<"\nStatus : ";gets(t_status);

cout<<"\nTariff : "; cin>>t_tariff; cout<<"\nDo you want to save the record (y/n) : "; if (ch=='Y' || ch=='y') { int recno; recno=recordno(tr); int location; location=(recno-1) * sizeof(room); file.seekp(location); strcpy(roomcode,t_rcode); roomno=t_roomno ; flrno=t_flrno; status=t_status ; tariff=t_tariff; file.write((char *) this, sizeof(room)); } file.close (); } void room::deletion() { clrscr(); int valid; char ch; int t_roomno; gotoxy(1,3); cout<<"Enter the Room no. to be deleted "; cin>>t_roomno; cout<<"Do you want to delete this Room Record (y/n):"; cin>>ch; if (ch=='N'||ch=='n') return; ifstream file("ROOM.DAT", ios::binary); ofstream temp("temp.dat", ios::binary|ios::out); while (!file.eof()) { file.read((char *) this, sizeof(room)); if (file.eof()) break; if (roomno !=t_roomno) temp.write((char *) this, sizeof(room)); } file.close(); temp.close(); remove("ROOM.DAT"); rename("temp.dat","ROOM.DAT"); } int no_cust(int m,int y) { customer c; ifstream file.open("CUSTOMER.DAT", ios::binary); file.seekg(0); int found=0; int total=0; while (file.read((char *) this, sizeof(c))) {if(c.d_out.mm==m && c.d_out.yy==y) {total++; found=1;} } if(found==0) {

return 0; } else return total; file.close (); } void customer::checkin() { room r; menu m1; char ch; int valid=1; int t_roomno, t_no_cust; char t_name[21], t_address[35], t_nation[16]; float t_advance; clrscr(); gotoxy(1,1); cout<<"Enter the details of the Customer"; cout<<"\n\nRoom no. :"; cin>>t_roomno; cout<<"\nName :"; gets(t_name); cout<<"\nNo. of persons :"; cin>>t_no_cust; cout<<"\nAddress :"; gets(t_address); cout<<"\nNationality :"; gets(t_nation); cout<<"\nAdvance :"; cin>>t_advance; cout<<"\nEnter date of checkin:"; cin>>d_in.dd>>d_in.mm>>d_in.yy; char t_status; t_status=r.room_status(t_roomno); if (!(t_status=='O')) { cout<<"\nROOM NOT VACANT"; cout<<"\nPress any key to continue..."; getch(); m1.main_menu(); } cout<<"Do you want to save the record (y/n) : "; cin>>ch; if (ch=='Y'||ch=='y') { r.change_status(t_roomno,'O',t_name,t_address); roomno=t_roomno; strcpy(name,t_name); advance=t_advance; ofstream file("CUSTOMER.DAT", ios::binary|ios::out|ios::app); file.write((char*) this, sizeof(customer)); file.close(); } m1.main_menu(); } int customer::recordno(int t_roomno) { ifstream file("CUSTOMER.DAT",ios::binary|ios::in); file.seekg(0); int count=0; while (file.read((char *) this, sizeof(customer)))

{ count++; if (t_roomno==roomno) break; } file.close(); return count; } void customer::modify() { clrscr(); room r; char ch; int t_roomno,t_flrno, tr; char t_name[21],t_add[35]; float t_advance; ofstream file("CUSTOMER.DAT",ios::binary |ios::out | ios::ate); gotoxy(1,3); cout<<"\nEnter the Room no. of the customer to be modified "; cin>>tr; char t_status; cout<<"\nDo you want to modify this Room Record (y/n):"; cin>>ch; if (ch=='N' || ch=='n') return; cout<<"\nENTER THE NEW DATA FOR THE CUSTOMER"; cout<<"\nRoom no. :"; cin>>t_roomno; cout<<"\nFloor No. :";cin>>t_flrno; cout<<"\nName :";gets(t_name); cout<<\nAdvance :";cin>>t_advance; t_status=r.room_status(t_roomno); if (!(t_status=='O')) { cout<<"\nROOM NOT VACANT"; cout<<"\nPress any key to continue..."; getch(); m1.main_menu(); } cout<<"\nDo you want to save the record (y/n) : "; cin>>ch; if (ch=='Y'||ch=='y') { if (t_roomno !=tr) { r.change_status(t_roomno,'O'); r.change_status(tr,'V'); } int recno; recno=recordno(tr); int location; location=(recno-1) * sizeof(customer); file.seekp(location); roomno=t_roomno ; strcpy(name,t_name); advance=t_advance; file.write((char *) this, sizeof(customer)); } file.close (); } void customer::delete_record(int t_roomno)

{ ifstream file("CUSTOMER.DAT", ios::binary); ofstream temp("temp.dat", ios::out|ios::binary); while (!file.eof()) { file.read((char *) this, sizeof(customer)); if (file.eof()) break; if (roomno !=t_roomno) temp.write((char *) this, sizeof(customer)); } file.close(); temp.close(); remove("CUSTOMER.DAT"); rename("temp.dat","CUSTOMER.DAT"); } void customer::deletion() { clrscr(); room r; char ch; int t_roomno; gotoxy(1,1); cout<<"Enter the Room no. of the customer to be deleted "; cin>>t_roomno; cout<<"Do you want to delete this Customer Record (y/n):"; cin>>ch; if (ch=='N'||ch=='n') return; r.change_status(t_roomno,'V'); delete_record(t_roomno); } void customer::checkout() { clrscr(); menu m1; room r; char ch; int t_roomno; gotoxy(1,1); cout<<"Enter the Room no. of the customer to be check out "; cin>>t_roomno; cout<<"\nDo you want to prepare bill of this Customer Record (y/n):"; cin>>ch; ch=toupper(ch); if (ch=='N') return; ifstream file("CUSTOMER.DAT", ios::binary); file.seekg(0); char t_name[21]; float t_nod,t_advance, t_tariff; cout<<"Enter no of days of stay;"; cin>>nod; cout<<"Enter date of checkout:"; cin>>d_out.dd>>d_out.mm>>d_out.yy; while (file.read((char *) this, sizeof(customer))) { if (t_roomno==roomno) { strcpy(t_name,name);

t_advance=advance; t_nod=nod; break; } } file.close(); clrscr(); t_tariff=r.get_data(t_roomno); int tot1=t_tariff*nod,tot2=0.05*t_tariff*nod,tot=tot1+tot2; cout<<"\t\t\t\tBILL<<"\n"<<"\t\t\t\tHill View<<"\n" <<"\t\t\t\t5,Lakar Bazar,Shimla"; cout<<"Custname[30]:";puts(t_name);cout<<"\n"; cout<<"Roomno,flrno:";cout<<t_roomno<<"\t"<<t_roomno/100<<"\n"; cout<<"Checkin date:"<<this.d_in.dd<<this.d_in.mm<<this.d_in.yy; cout<<"\tCheckout date:"<<<<this.d_out.dd<<this.d_out.mm<<this.d_out.yy; cout<<"Rent of room = "<<t_tariff<<"per day\n"; cout<<"\nNo of days stayed:";cout<<nod<<"\n"; cout<<"Rent for days stayed ="<<tot1; cout<<"\nLuxury charges(@5%)="<<tot2; cout<<"Advpay:";cout<<t_advance<<"\n"; cout<<"Tot_amt due:";cout<<tot<<"\n"; cout<<"Net amnt due:"<<tot-t_advance<<"\n"; cout<<"\nThanking You"; r.change_status(t_roomno,'V'); delete_record(t_roomno); cout<<"\nPress any key to continue..."; getch(); m1.main_menu(); } int customer::display_mcr(int f,int m,int y) { clrscr(); float t_total=0; int m,y; static int sno=1; gotoxy(35,1); cout<<"MONTHLY COLLECTION REPORT"; gotoxy(1,2); cout<<"Report for month of "<<m<<" in Year "<<y; gotoxy(1,3); cout<<"Sno. | CustomerName | Address | No | Rent | Advance | Tota l | Collected on "; gotoxy(39,4); cout<<"Of Days"; gotoxy(56,4);cout<<"Payment"; gotoxy(66,4);cout<<"Amount"; for(int k=1;k<80;k++) { gotoxy(k,5); cout<<"-"; } for(int j=3;j<f;j++) { gotoxy(6,j);cout<<"|"; gotoxy(21,j);cout<<"|"; gotoxy(38,j);cout<<"|"; gotoxy(48,j);cout<<"|"; gotoxy(55,j);cout<<"|"; gotoxy(65,j);cout<<"|"; gotoxy(73,j);cout<<"|";

} t_total+=getdata(roomno)*nod*1.05; gotoxy(1,f);cout<<sno++; gotoxy(7,f);cout.write(name,' ',13) gotoxy(22,f);cout.write(address,16); gotoxy(39,f);cout<<nod; gotoxy(49,f);cout<<getdata(roomno); gotoxy(56,f);cout<<advance; gotoxy(66,f);cout<<(getdata(roomno)*nod*1.05); gotoxy(74,f);cout<<d_out.dd; return sno-1; } void trend_report() { int y,ini_y; cout<<"Enter starting year(yy):"; cin>>y; ini_y=y; int f1=6,m,x,sum=0; gotoxy(35,1); cout<<"TREND REPORT"; gotoxy(1,2); cout<<"Sno. | Month | Year1 | Year2 | Year3 | Year4 | Year5 "; for(int k=1;k<80;k++) { gotoxy(k,3); cout<<"-"; } for(int j=2;j<68;j++) { gotoxy(6,j);cout<<"|"; gotoxy(14,j);cout<<"|"; gotoxy(22,j);cout<<"|"; gotoxy(30,j);cout<<"|"; gotoxy(38,j);cout<<"|"; gotoxy(46,j);cout<<"|"; } for(j=4;j<16;j++) { gotoxy(1,j);cout<<j-3; } while(y++<(ini_y+5)) {m=1; while(m<=12) { x=no_cust(m++,y);s+=x; for(int q=4;q<16;q++) { gotoxy((7+y-ini_y),q);cout<<x; } } } } void main () { menu m; m.intro(); getch(); }

Potrebbero piacerti anche