Advertisement
Guest User

hotel reservation

a guest
Sep 29th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 27.99 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<windows.h>
  4. #include<string>
  5. using namespace std;
  6.  
  7.     struct Name              // structure for naming in program
  8.     {
  9.       char first[20];       //character arrays for the names used in program..
  10.       char last[20];
  11.       char date[20];
  12.       int room;
  13.       char cnic[20],mob[20];
  14.     };
  15.      
  16.        //\\Functions prototyping//\/\\
  17.            
  18.        void vacant_rooms();                //for vacant rooms|
  19.        void customer_reserve();           //for reservation  |
  20.        void login();                     //for login         |
  21.        void check();                    //for the guest history
  22.        void user_total();                                //for user total on the time checkout
  23.        void loading();                                   // for loading bar
  24.        void help();                                     //for helping the user to operate the application
  25.        void about();                                   //for about the program
  26.        void del_resdata();                            // in order delete
  27.        
  28. //------------------------.>//
  29.  
  30.  
  31. int main()
  32. {
  33.     system("color 34");
  34.     int a;
  35.     int choice;
  36.     char again;
  37.     char x[20];
  38.     cout<<endl;
  39.     cout<<"            *                                           *    "<<endl;  
  40.     cout<<"          **                                            *   "<<endl;
  41.     cout<<"   *** Welcome to the Hotel Reservation Application ****"<<endl;
  42.     cout<<"          **                                             **  "<<endl;
  43.     cout<<"            *                                           *   "<<endl;
  44.     cout<<endl;                                                  
  45.    
  46.     Beep(2020,1100);                                                             // causes the computer to beep
  47.     char l=219;                                                                  //for loading bar
  48.     cout<<"Please wait while system is analyzing the data\n";
  49.     for ( int i=0; i<10 ; i++)
  50.     {
  51.         Beep(2000,500);
  52.         cout<<l;
  53.          }
  54.     cout<<endl;
  55.     cout<<"______________________________"<<endl;
  56.     cout<<"Please Enter Username and Password to proceed: "<<endl;
  57.     cout<<endl;
  58.     login();            //function calling of login
  59.     cout<<"______________________________"<<endl;
  60.     cout<<endl;
  61.     do
  62.     {
  63.     cout<<"Welcome to the Main Menu "<<endl;
  64.     cout<<endl;
  65.     cout<<"Press 1 to Reserve a room. "<<endl;
  66.     cout<<endl;
  67.     cout<<"Press 2 to see the vacant rooms. "<<endl;                        
  68.     cout<<endl;
  69.     cout<<"Press 3 to check out a room. "<<endl;
  70.     cout<<endl;
  71.     cout<<"Press 4 to see the history of reserved rooms. "<<endl;
  72.     cout<<endl;
  73.     cout<<"Press 5 to Delete the Reservation data. "<<endl;
  74.     cout<<endl;
  75.     cout<<"Press 6 to see about the Application. "<<endl;
  76.     cout<<endl;
  77.     cout<<"Press 7 for help. "<<endl;
  78.     cout<<endl;
  79.     cout<<"Press 0 to Exit application. "<<endl;
  80.     cout<<"Enter Here_: ";
  81.     cin>>a;
  82.     cout<<"_____________________________________"<<endl;
  83.     cout<<endl;
  84.     switch(a)
  85.     {
  86.     cout<<"________________________________________"<<endl;
  87.     case 0:
  88.     break;
  89.     case 1:
  90.          cout<<"   *                                 *"<<endl;
  91.          cout<<" ** Welcome to the Reservation Menu **"<<endl;
  92.          cout<<"   *                                 *"<<endl;
  93.          cout<<endl;
  94.          cout<<endl;
  95.          customer_reserve();     // funtion calling
  96.          break;
  97.          case 2:
  98.          cout<<"   *                             *"<<endl;
  99.          cout<<"  ** Welcome to the Vacant Rooms **"<<endl;
  100.          cout<<"   *                             *"<<endl;
  101.          cout<<endl;
  102.          cout<<endl;
  103.          vacant_rooms();    ///funtion calling
  104.          break;
  105.          case 3:
  106.          cout<<" *                                 *"<<endl;
  107.          cout<<"** Welcome to the User Total Menu  **"<<endl;
  108.          cout<<" *                                 *"<<endl;
  109.          cout<<endl;
  110.          cout<<endl;
  111.          user_total();    //function calling  
  112.           break;          
  113.          case 4:
  114.          cout<<"               *                                 *"<<endl;
  115.          cout<<"              ** Welcome to the History Menu     **"<<endl;
  116.          cout<<"               *                                 *"<<endl;
  117.          cout<<endl;
  118.          cout<<endl;
  119.                        
  120.          check();    //function calling          
  121.          break;          
  122.          case 5:
  123.          cout<<"        *                                                           *"<<endl;
  124.          cout<<"    ** Welcome to Delete Reservation data function **"<<endl;
  125.          cout<<"        *                                             *"<<endl;
  126.          cout<<endl;
  127.          cout<<endl;
  128.          del_resdata();    //function calling
  129.          break;        
  130.          case 6:
  131.          cout<<"      *                       *"<<endl;
  132.          cout<<"   ** About the Application **"<<endl;
  133.          cout<<"      *                       *"<<endl;
  134.          cout<<endl;
  135.          cout<<endl;
  136.          about();     //function calling
  137.          break;                    
  138.          case 7:
  139.          cout<<"     *                     *"<<endl;
  140.          cout<<"   ** Welcome to the Help **"<<endl;
  141.          cout<<"      *                     *"<<endl;
  142.          cout<<endl;
  143.          cout<<endl;
  144.          help();    //function calling
  145.          break;
  146.   default:
  147.                  cout<<"you have enter an invalid Choice "<<endl;
  148.                  cout<<endl;
  149.                  }
  150. cout<<"Press 1 to go back into MAIN Menu or 0 to terminate the program: ";                    
  151. cin>>again;
  152. cout<<"___________________________________"<<endl;
  153. cout<<endl;
  154. }
  155. while (again=='1');  
  156. cout<<"Thankyou! for using Hotel Reservation application."<<endl;
  157. cout<<"Have a nice day! "<<endl;
  158. cout<<endl;
  159. cout<<"Copyright(C) 2015. programming passion"<<endl;
  160. cout<<endl;
  161. cout<<"_________________________________________"<<endl;
  162.  
  163.      system ("pause");
  164.      }
  165. //....................................................................//
  166.                        
  167. //....................................................................//
  168. void user_total()   //funtion definition  of function user_total
  169. {
  170.      int choice,days,total1;
  171.     char AC,again;
  172.     int c=1000;
  173.     int single= 3000;
  174.     int doubl=4500;
  175.     int suit=6000;
  176.     int time=24;
  177.     int service=300;
  178.     do
  179.     {
  180.     cout<<"Which kind of Room did the guest stayed in?  "<<endl;
  181.     cout<<endl;
  182.                cout<<" 1.Single Rooms "<<endl;
  183.                cout<<endl;
  184.                cout<<" 2.Double Rooms "<<endl;
  185.                cout<<endl;
  186.                cout<<" 3.Suits "<<endl;
  187.                cout<<endl;
  188.    
  189.     cout<<"Select 1,2 or 3 . "<<endl;
  190.     cout<<endl;
  191.     cout<<"Enter Your CHoice Here_: ";
  192.     cin>>choice;
  193.     cout<<"__________________________________"<<endl;
  194.     switch(choice)
  195.     {
  196.     case 1:
  197.          cout<<"You have Selected single room. "<<endl;
  198.          cout<<endl;
  199.          cout<<" For How many days did the guest stayed: ";
  200.          cin>>days;
  201.          cout<<endl;
  202.          
  203.               cout<<" Press Y for A/c and N for without A/c: ";
  204.          cin>>AC;
  205.          cout<<endl;
  206.         if (AC == 'Y' || AC == 'y')
  207. {
  208.          total1 =(c+single+time+service)*days;
  209.           cout<<"Your Total Total bill + service tax = ("<<total1<<" Rs.)"<<endl;
  210.           cout<<endl;
  211.           cout<<"______________________________"<<endl;
  212. }      
  213.          else if (AC == 'N' || AC == 'n')
  214.  {        
  215.          total1=(single+time+service) * days;
  216.          cout<<"Your Total Total bill + service tax = ("<<total1<<" Rs.)"<<endl;
  217.       cout<<endl;
  218.        cout<<"_______________________________"<<endl;
  219. }      
  220.          break;
  221.          case 2:
  222.          cout<<"You Have Selected Double room."<<endl;
  223.           cout<<endl;
  224.          cout<<" For How many days did the guest stayed: ";
  225.          cin>>days;
  226.          cout<<endl;
  227.         cout<<" Press Y for A/c and N for without A/c: ";
  228.          cin>>AC;
  229.          cout<<endl;
  230.          
  231.         if (AC == 'Y' || AC == 'y')
  232. {
  233.          total1 =(c+doubl+time+service)*days;
  234.           cout<<"Your Total Total bill + service tax = ("<<total1<<" Rs.)"<<endl;
  235. cout<<endl;
  236.  cout<<"__________________________________"<<endl;
  237. }      
  238.          else if (AC == 'N' || AC == 'n')
  239.  {        
  240.          total1=(doubl+time+service) * days;
  241.          cout<<"Your Total Total bill + service tax = ("<<total1<<" Rs.)"<<endl;
  242.         cout<<endl;
  243.          cout<<"_______________________________________"<<endl;
  244. }      
  245.          break;
  246.          case 3:
  247.          cout<<"You Have Selected Suit. "<<endl;
  248.          cout<<endl;
  249.          cout<<" For How many days did the guest stayed: ";
  250.          cin>>days;
  251.          cout<<endl;      
  252.          cout<<" Press Y for A/c and N for without A/c: ";
  253.          cin>>AC;
  254.          cout<<endl;
  255.         if (AC == 'Y' || AC == 'y')
  256. {
  257.          total1 =(c+suit+time+service)*days;
  258.           cout<<"Your Total Total bill + service tax = ("<<total1<<" Rs.)"<<endl;
  259.           cout<<endl;
  260.            cout<<"_______________________________________"<<endl;
  261. }      
  262.          else if (AC == 'N' || AC == 'n')
  263.  {        
  264.          total1=(suit+time+service) * days;
  265.           cout<<"Your Total Total bill + service tax = ("<<total1<<" Rs.)"<<endl;
  266.          
  267.         cout<<endl;
  268.        cout<<"__________________________________________"<<endl;
  269. }      
  270.                   break;
  271.                  default:
  272.                  cout<<"you have enter an invalid Choice "<<endl;
  273.                  cout<<endl;
  274.                  }
  275.                  cout<<"Do you want to checkout for another room? (Y/N): ";
  276.                  cin>>again;
  277.                   cout<<"___________________________________"<<endl;
  278.                  cout<<endl;
  279.     }
  280.        while(again == 'y' || again == 'Y');
  281.  
  282.          }
  283.         //....................................................................//
  284.                        
  285.       //....................................................................//
  286.        
  287.         void customer_reserve()    //function definition
  288. {
  289.  
  290.               Name guest;             // guest is the name structure
  291.               Name guest2;
  292.               char choicedo;       //for enter more data
  293.  
  294.     do
  295.     {
  296.     ofstream file;                    
  297.     file.open("User info input.txt",ios::out | ios::app);  //openning txt file
  298. if(!file)
  299. {
  300.          cout<<"Error: Cannot open file.\n";
  301.          system("pause");
  302.          }
  303.          
  304.     cout<<"Enter The Room # to be Reserved: ";
  305.     cin>>guest.room;
  306.     cin.ignore();                       // to skip the new line character
  307.     cout<<endl;
  308.     cout<<"Enter Guest's First Name: ";
  309.     cin.getline(guest.first, 20);      
  310.      cout<<endl;
  311.     cout<<"Enter Guest's Last Name: ";
  312.     cin.getline(guest.last, 20);
  313.     cout<<endl;
  314.     cout<<"Enter The Mobile no. of The Customer: +";
  315.     cin.getline(guest.mob, 20);
  316.     cout<<endl;
  317.     cout<<"Enter The CNIC of The Customer: ";
  318.     cin.getline(guest.cnic, 20);
  319.     cout<<endl;
  320.     cout<<"The Name of Manager in Charge: ";
  321.     cin.getline(guest2.first, 20);
  322.     cout<<endl;
  323.     cout<<endl;
  324.     cout<<"Date: ";
  325.     cin.getline(guest.date, 20);
  326.     cout<<endl;
  327.     int a;                            ///for choice
  328.     /////////////
  329.     cout<<"Press 1 to Save or 2 to cancel: ";
  330.     cout<<endl;
  331.   cin>>a;
  332.    if(a==1)
  333.        {
  334.     cout<<endl;
  335.     file<<" Guests Info"<<endl;
  336.     cout<<endl;
  337.     file<<"------------------------------------------------------------"<<endl;
  338.                file<<endl;
  339.                file<<"              Reservation Data of Room no.: "<<guest.room<<endl;
  340.                file<<endl;
  341.                file<<"The Name of the Guest is: "<<guest.first<<" "<<guest.last<<endl;
  342.                file<<endl;
  343.                file<<"Mobile No.: +"<<guest.mob<<endl;
  344.                file<<endl;
  345.                file<<"CNIC No.: "<<guest.cnic<<endl;
  346.                file<<endl;
  347.                file<<"Name of Manager in Charge is: "<<guest2.first<<endl;
  348.                file<<endl;
  349.                file<<"Date: "<<guest.date<<endl;
  350.                file<<endl;
  351.     file<<endl;  
  352.     file<<"------------------------------------------------------------"<<endl;
  353.     file.close();
  354.     cout<<"Record Saved..."<<endl;
  355.     cout<<"__________________________________"<<endl;
  356.     cout<<endl;
  357. }        
  358.          else
  359.  {        
  360.          cout<<"Record Was Not Saved"<<endl;
  361.           cout<<"____________________________________"<<endl;
  362.          cout<<endl;
  363.         }
  364.          cout<<"Enter Y To input an other data or Enter N to Exit: ";
  365.          cin>>choicedo;
  366.          cout<<"_____________________________________"<<endl;
  367.          cout<<endl;
  368.          }
  369.          while (choicedo=='y' || choicedo=='Y');  //to enter more data
  370.  //}          
  371. }
  372.          
  373.          
  374.          //....................................................................//
  375.                        
  376. //....................................................................//
  377.  
  378. void vacant_rooms()    //function definition
  379. {
  380.      ifstream infile,infile2,infile3;           //ifstream for file reading
  381.     char name[89],name2[89],name3[89],name4[100];
  382.     int see;
  383.     char again;
  384.     do
  385.     {
  386.     cout<<"Press 1 to see the list of Single Rooms. "<<endl;
  387.     cout<<endl;
  388.     cout<<"Press 2 to See the list of Double Rooms. "<<endl;
  389.     cout<<endl;
  390.     cout<<"Press 3 to See the list of Suits. "<<endl;
  391.     cout<<endl;
  392.     cout<<"Enter Your Choice Here_: ";
  393.     cin>>see;
  394.     cout<<endl;
  395.     switch(see)
  396.     {
  397.     case 1:
  398.     infile.open("infoVS.txt",ios::in);
  399. if (!infile)
  400. {
  401.             cout<<"File not found."<<endl;
  402.             exit(1);
  403.             }
  404.             else
  405.             {
  406. while(!infile.eof())
  407. {
  408. infile>>name>>name2>>name3;
  409.     cout<<name<<" "<<name2<<" "<<name3<<endl;
  410.    
  411.  
  412.     cout<<endl;
  413. }
  414.     infile.close();        //closing the file
  415.                            }
  416. break;
  417. case 2:
  418.  
  419.            infile2.open("infoVD.txt",ios::in);
  420.    if(!infile2)
  421.    {
  422.                cout<<"File not found."<<endl;
  423.                exit(1);
  424.                }
  425.                else
  426.                {
  427.    while(!infile2.eof())
  428.        {  
  429. infile2>>name>>name2>>name3;
  430. cout<<name<<" "<<name2<<" "<<name3<<endl;
  431. cout<<endl;
  432. }
  433.      infile2.close();
  434. }
  435. break;
  436.  
  437. case 3:
  438.  
  439.            infile3.open("infoVSu.txt",ios::in);    // opening file
  440.  if(!infile3)
  441.  {
  442.   cout<<"File not found."<<endl;
  443.   exit(1);
  444. }
  445. else
  446. {
  447.      
  448.      while(!infile3.eof())
  449.      {
  450.       infile3>>name>>name2>>name3;
  451.     cout<<name<<" "<<name2<<" "<<name3<<endl;
  452.     cout<<endl;
  453. }
  454.  
  455.  
  456.      infile3.close();
  457. }
  458.      break;
  459.      
  460.      default:
  461.              cout<<"You have entered an invalid choice"<<endl;
  462.              cout<<endl;
  463.              }
  464.      cout<<"Do you want to see the List of vacant Rooms again? (Y/N): ";
  465.      cin>>again;
  466.      cout<<endl;
  467. }while (again=='Y' || again=='y');
  468.      cout<<endl;  
  469. }
  470.  
  471. //....................................................................//
  472.                        
  473. //....................................................................//
  474.  
  475. void login()                      //function calling
  476. {
  477.  char log_file1[20], pass_file1[20];
  478.     char log_file2[20], pass_file2[20];
  479.    
  480.  ifstream username,passward;
  481.     username.open("user.txt");
  482.  if(!username)
  483.  {
  484.                  cout<<"File Not Found....";
  485.                  exit(1);
  486.                  }
  487.     passward.open("pass.txt");
  488.     if(!passward)
  489.  {
  490.                  cout<<"File Not Found....";
  491.                  exit(1);
  492.                  }
  493.          // reading username from file 2....        
  494.   username.getline(log_file2, 50);
  495.   while (strcmp(log_file1, log_file2))
  496.   {
  497.    cout<<"\nUser Name: ";
  498.           cin.getline(log_file1, 50);
  499.    if (strcmp(log_file1, log_file2) ==0)  //comparing the username
  500.           break;
  501.              
  502.    else
  503.    Beep(3320,400);
  504.           cout<<"\nInvalid Username.\n";  
  505.   }
  506.  
  507.   passward.getline(pass_file2, 50); // reading password from file 2
  508.   while (strcmp(pass_file1, pass_file2) !=0)
  509.   {
  510.    cout<<"\nPassword: ";
  511.    cin.getline(pass_file1, 50);
  512.    if (strcmp(pass_file1, pass_file2) ==0)  //comparing the password
  513.    cout<<"\n\t  Logged in Successfully!!!" <<endl<<endl<<endl;
  514.    else
  515.          Beep(3320,400);
  516.           cout<<"\nInvalid Password\n";
  517.   }
  518.   username.close();          // closing the file
  519.   passward.close();             // closing the file
  520. }
  521. //....................................................................//
  522.                         //function definition ended
  523. //....................................................................//
  524.  
  525. void check()    /// function definition
  526. {
  527.    
  528.     char doagain;
  529.     do
  530.     {
  531.      fstream data;
  532.      char word[100];
  533.      
  534.      data.open("User info input.txt",ios::in);
  535.      cout<<endl;
  536.      if(!data)
  537.      {
  538.               cout<<"File not found."<<endl;
  539.               exit(1);
  540.               }
  541.      else
  542.      {
  543.      while(!data.eof())
  544.      {
  545.    
  546.          data.getline(word,100);
  547.          cout<<word<<"\n";
  548.          data.getline(word,100);
  549.          cout<<word<<"\n";
  550.          data.getline(word,100);  
  551.          cout<<word<<"\n";
  552.          data.getline(word,100);
  553.          cout<<word<<"\n";
  554.          }        
  555.          data.close();
  556.          cout<<"Press Y to see the history again or N to cancel.";
  557.          cin>>doagain;
  558.          cout<<"___________________________________"<<endl;
  559.          cout<<endl;
  560.          }
  561. }
  562. while (doagain=='y' || doagain=='Y');
  563. }                
  564.  
  565. //....................................................................//
  566.  
  567. void del_resdata()    ///function definition
  568. {
  569.    char again;
  570.    int x;
  571.    fstream deletefile;
  572.   do
  573.   {
  574.     cout<<"Enter 1 to delete the reservation data or 2 to cancel: ";
  575.     cin>>x;
  576.     cout<<endl;
  577.     if (x==1)
  578.     {
  579.     deletefile.open("User info input.txt", ios::out | ios::trunc); //trunc for delete data
  580.     if(!deletefile)
  581.     {
  582.     cout<<"File not found."<<endl;
  583.     exit(1);
  584.     }
  585.     else
  586.     {
  587.     cout<<"Data has been deleted from the file."<<endl;
  588.     cout<<endl;
  589.     }
  590. }
  591. else
  592. {
  593. cout<<"Data not deleted.."<<endl;
  594. cout<<endl;
  595. }
  596. cout<<"Enter Y to run this function again or N to cancel: ";
  597. cin>>again;
  598. cout<<endl;
  599. cout<<"_____________________________________________"<<endl;
  600. }
  601. while (again=='Y' || again=='y');
  602. deletefile.close();
  603. }
  604. void about()
  605. {
  606.              cout<<"About the Application"<<endl;
  607.              cout<<"______________________________________"<<endl;
  608.              cout<<endl;
  609.              cout<<"This application is specially made for Hotel Reservation to "<<endl;
  610.              cout<<"Organize data and to perform tasks, which can be useful for "<<endl;
  611.              cout<<"Reservation.It can recored and analyze data of guests.With "<<endl;
  612.              cout<<"this application you can not only see the past history of "<<endl;
  613.              cout<<"guests,stayed in the hotel but you can also reserve rooms "<<endl;
  614.              cout<<"for the future as well.You can also calculate the bill of "<<endl;
  615.              cout<<"guests on the basis of time they have spent in the hotel  "<<endl;
  616.              cout<<endl;
  617.              cout<<"This application is user friendly and one can easily use "<<endl;
  618.              cout<<"this application.Thank you!"<<endl;
  619.              cout<<endl;
  620.              cout<<"Copyright(C) 2015 programming passion"<<endl;
  621.              cout<<"______________________________________________"<<endl;
  622. }
  623.                    //=======>Programming passion ===========>//
  624.                   //For more info visit our site googler700.blogspot.com??///
  625. void help()
  626. {
  627.              cout<<endl;
  628.              cout<<"This application will work according to the desired entries by "<<endl;
  629.              cout<<"the user.The reservation data will be stored in a text file present "<<endl;
  630.              cout<<"where the application is located.If the text file is not present "<<endl;
  631.              cout<<"the program will not work properly and will terminate.Follow the  "<<endl;
  632.              cout<<"displayed on the screen.Select the proper option to operate "<<endl;
  633.              cout<<"instructions the application.Goodluck! "<<endl;
  634.              cout<<endl;
  635. }
  636.  
  637.  
  638. ___________________________________________________________________________________________________
  639. #include "conio.h"
  640. #include "iostream.h"
  641. #include "graphics.h"
  642. #include "stdio.h"
  643. #include "dos.h"
  644. #include "process.h"
  645.  
  646.  
  647. void logo()
  648. {
  649. int gdriver=DETECT,gmode;
  650. initgraph(&amp;gdriver,&amp;gmode,"C:\\TURBOC3\\BGI");
  651. rectangle(250,30,387,48);
  652. rectangle(275,143,398,160);
  653. rectangle(275,175,398,192);
  654.  
  655.  
  656. }
  657.  
  658.  
  659. void main()
  660. {
  661. clrscr();
  662. char u[20],p[20];
  663. logo();
  664. gotoxy(34,3);
  665. cout&lt;&lt;"CodingSec Login";
  666.  
  667.  
  668. gotoxy(25,10);
  669. cout&lt;&lt;"Username:";
  670.  
  671.  
  672. gotoxy(25,12);
  673. cout&lt;&lt;"Password:";
  674.  
  675.  
  676. gotoxy(51,10);
  677. cout&lt;&lt;"(Press enter after entering)";
  678.  
  679.  
  680. gotoxy(51,12);
  681. cout&lt;&lt;"(8 characters only)";
  682.  
  683. gotoxy(36,10);
  684. gets(u);
  685.  
  686.  
  687. gotoxy(36,12);
  688. for(int i=0;i&lt;8;++i)
  689. {
  690. p[i]=getch();
  691. if(p[i]=='b')
  692.   {
  693.     printf("b b");
  694. i=i-2;
  695.   }
  696.   else
  697.    cout&lt;&lt;"*";
  698. }
  699. p[i]=' ';
  700. getch();
  701.  
  702.  
  703.  
  704.  
  705. gotoxy(20,20);
  706. cout&lt;&lt;"Plz wait Redirecting";
  707. for(int j=0;j&lt;8;++j)
  708. {
  709. sleep(1);
  710. cout&lt;&lt;".";
  711. }
  712. }
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719. #include<iostream.h>
  720. #include<conio.h>
  721. #include<fstream.h>
  722. #include<stdio.h>
  723. #include<dos.h>
  724.  
  725. class hotel
  726. {
  727.     int room_no;
  728.     char name[30];
  729.     char address[50];
  730.     char phone[10];
  731.    
  732.     public:
  733.     void main_menu();    //to dispay the main menu
  734.     void add();        //to book a room
  735.     void display();    //to display the customer record
  736.     void rooms();    //to display alloted rooms
  737.     void edit();    //to edit the customer record
  738.     int check(int);    //to check room status
  739.     void modify(int);    //to modify the record
  740.     void delete_rec(int);    //to delete the record
  741. };
  742.  
  743. void hotel::main_menu()
  744. {
  745.     int choice;
  746.    
  747.     while(choice!=5)
  748.     {
  749.         clrscr();
  750.         cout<<"\n\t\t\t\t*************";
  751.         cout<<"\n\t\t\t\t* MAIN MENU *";
  752.         cout<<"\n\t\t\t\t*************";
  753.         cout<<"\n\n\n\t\t\t1.Book A Room";
  754.         cout<<"\n\t\t\t2.Customer Record";
  755.         cout<<"\n\t\t\t3.Rooms Allotted";
  756.         cout<<"\n\t\t\t4.Edit Record";
  757.         cout<<"\n\t\t\t5.Exit";
  758.         cout<<"\n\n\t\t\tEnter Your Choice: ";
  759.         cin>>choice;
  760.        
  761.         switch(choice)
  762.         {
  763.             case 1: add();
  764.                     break;
  765.             case 2: display();
  766.                     break;
  767.             case 3: rooms();
  768.                     break;
  769.             case 4: edit();
  770.                     break;
  771.             case 5: break;
  772.             default:
  773.                     {
  774.                         cout<<"\n\n\t\t\tWrong choice!!!";
  775.                         cout<<"\n\t\t\tPress any key to continue!!";
  776.                         getch();
  777.                     }
  778.         }
  779.     }
  780. }
  781.  
  782. void hotel::add()
  783. {
  784.     clrscr();
  785.     int r,flag;
  786.     ofstream fout("Record.dat",ios::app);
  787.    
  788.     cout<<"\n Enter Customer Detalis";
  789.     cout<<"\n **********************";
  790.     cout<<"\n\n Room no: ";
  791.     cin>>r;
  792.     flag=check(r);
  793.    
  794.     if(flag)
  795.         cout<<"\n Sorry..!!!Room is already booked";
  796.     else
  797.     {
  798.         room_no=r;
  799.         cout<<" Name: ";
  800.         gets(name);
  801.         cout<<" Address: ";
  802.         gets(address);
  803.         cout<<" Phone No: ";
  804.         gets(phone);
  805.         fout.write((char*)this,sizeof(hotel));
  806.         cout<<"\n Room is booked!!!";
  807.     }
  808.    
  809.     cout<<"\n Press any key to continue!!";
  810.     getch();
  811.     fout.close();
  812. }
  813.  
  814. void hotel::display()
  815. {
  816.     clrscr();
  817.     ifstream fin("Record.dat",ios::in);
  818.     int r,flag;
  819.     cout<<"\n Enter room no: ";
  820.     cin>>r;
  821.    
  822.     while(!fin.eof())
  823.     {
  824.         fin.read((char*)this,sizeof(hotel));
  825.         if(room_no==r)
  826.         {
  827.             clrscr();
  828.             cout<<"\n Cusromer Details";
  829.             cout<<"\n ****************";
  830.             cout<<"\n\n Room no: "<<room_no;
  831.             cout<<"\n Name: "<<name;
  832.             cout<<"\n Address: "<<address;
  833.             cout<<"\n Phone no: "<<phone;
  834.             flag=1;
  835.             break;
  836.         }
  837.     }
  838.    
  839.     if(flag==0)
  840.         cout<<"\n Sorry Room no. not found or vacant!!";
  841.        
  842.     cout<<"\n\n Press any key to continue!!";
  843.     getch();
  844.     fin.close();
  845. }
  846.  
  847. void hotel::rooms()
  848. {
  849.     clrscr();
  850.     ifstream fin("Record.dat",ios::in);
  851.     cout<<"\n\t\t\tList Of Rooms Allotted";
  852.     cout<<"\n\t\t\t*********************";
  853.     cout<<"\n\n Room No.\tName\t\tAddress\t\tPhone No.\n";
  854.    
  855.     while(!fin.eof())
  856.     {
  857.         fin.read((char*)this,sizeof(hotel));
  858.         cout<<"\n\n "<<room_no<<"\t\t"<<name;
  859.         cout<<"\t\t"<<address<<"\t\t"<<phone;
  860.     }
  861.    
  862.     cout<<"\n\n\n\t\t\tPress any key to continue!!";
  863.     getch();
  864.     fin.close();
  865. }
  866.  
  867. void hotel::edit()
  868. {
  869.     clrscr();
  870.     int choice,r;
  871.    
  872.     cout<<"\n EDIT MENU";
  873.     cout<<"\n *********";
  874.     cout<<"\n\n 1.Modify Customer Record";
  875.     cout<<"\n 2.Delete Customer Record";
  876.    
  877.     cout<<"\n Enter your choice: ";
  878.     cin>>choice;
  879.    
  880.     clrscr();
  881.     cout<<"\n Enter room no: ";
  882.     cin>>r;
  883.    
  884.     switch(choice)
  885.     {
  886.         case 1: modify(r);
  887.                 break;
  888.         case 2: delete_rec(r);
  889.                 break;
  890.         default: cout<<"\n Wrong Choice!!";
  891.     }
  892.    
  893.     cout<<"\n Press any key to continue!!!";
  894.     getch();
  895. }
  896.  
  897. int hotel::check(int r)
  898. {
  899.     int flag=0;
  900.     ifstream fin("Record.dat",ios::in);
  901.     while(!fin.eof())
  902.     {
  903.         fin.read((char*)this,sizeof(hotel));
  904.         if(room_no==r)
  905.         {
  906.             flag=1;
  907.                 break;
  908.         }
  909.     }
  910.    
  911.     fin.close();
  912.     return(flag);
  913. }
  914.  
  915. void hotel::modify(int r)
  916. {
  917.     long pos,flag=0;
  918.     fstream file("Record.dat",ios::in|ios::out|ios::binary);
  919.    
  920.     while(!file.eof())
  921.     {
  922.         pos=file.tellg();
  923.         file.read((char*)this,sizeof(hotel));
  924.         if(room_no==r)
  925.         {
  926.             cout<<"\n Enter New Details";
  927.             cout<<"\n *****************";
  928.             cout<<"\n Name: ";
  929.             gets(name);
  930.             cout<<" Address: ";
  931.             gets(address);
  932.             cout<<" Phone no: ";
  933.             gets(phone);
  934.            
  935.             file.seekg(pos);
  936.             file.write((char*)this,sizeof(hotel));
  937.             cout<<"\n Record is modified!!";
  938.             flag=1;
  939.             break;
  940.         }
  941.     }
  942.    
  943.     if(flag==0)
  944.         cout<<"\n Sorry Room no. not found or vacant!!";
  945.        
  946.     file.close();
  947. }
  948.  
  949. void hotel::delete_rec(int r)
  950. {
  951.     int flag=0;
  952.     char ch;
  953.     ifstream fin("Record.dat",ios::in);
  954.     ofstream fout("temp.dat",ios::out);
  955.    
  956.     while(!fin.eof())
  957.     {
  958.         fin.read((char*)this,sizeof(hotel));
  959.         if(room_no==r)
  960.         {
  961.             cout<<"\n Name: "<<name;
  962.             cout<<"\n Address: "<<address;
  963.             cout<<"\n Pone No: "<<phone;
  964.             cout<<"\n\n Do you want to delete this record(y/n): ";
  965.             cin>>ch;
  966.            
  967.             if(ch=='n')
  968.             fout.write((char*)this,sizeof(hotel));
  969.            
  970.             flag=1;
  971.         }
  972.         else
  973.             fout.write((char*)this,sizeof(hotel));
  974.     }
  975.    
  976.     fin.close();
  977.     fout.close();
  978.    
  979.     if(flag==0)
  980.         cout<<"\n Sorry room no. not found or vacant!!";
  981.     else
  982.     {
  983.         remove("Record.dat");
  984.         rename("temp.dat","Record.dat");
  985.     }
  986. }
  987.  
  988. void main()
  989. {
  990.     hotel h;
  991.     textmode(C80);
  992.     textbackground(WHITE);
  993.     textcolor(RED);
  994.    
  995.     clrscr();
  996.     cout<<"\n\t\t\t****************************";
  997.     cout<<"\n\t\t\t* HOTEL MANAGEMENT PROJECT *";
  998.     cout<<"\n\t\t\t****************************";
  999.     sleep(2);
  1000.    
  1001.     cout<<"\n\n\n\n\t\tMade By:";
  1002.     sleep(2);
  1003.     cout<<" The Crazy Programmer";
  1004.     sleep(2);
  1005.     cout<<"\n\n\n\n\n\t\t\t\tPress any key to continue!!";
  1006.     getch();
  1007.     h.main_menu();
  1008. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement