Advertisement
abhask

nproj

Nov 1st, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.49 KB | None | 0 0
  1. /*
  2. Made By: Abhas Krishna, Mohammed Adil and Kriti Pratap.
  3. */
  4.  
  5. #include<fstream.h>
  6. #include<conio.h>
  7. #include<string.h>
  8. #include<stdio.h>
  9. #include<process.h>
  10. #include<ctype.h>
  11. #include<dos.h>
  12. class hotel
  13. {
  14.     int room_no;
  15.     char name[30];
  16.     char address[50];
  17.     char phone[10];
  18.  
  19.     public:
  20.     void main_menu();       //to dispay the main menu
  21.     void add();         //to book a room
  22.     void display();         //to display the customer record
  23.     void rooms();           //to display alloted rooms
  24.     void edit();            //to edit the customer record
  25.     int check(int);         //to check room status
  26.     void modify(int);       //to modify the record
  27.     void delete_rec(int);       //to delete the record
  28. };
  29.  
  30. void hotel::main_menu()
  31. {
  32.     int choice;
  33.     while(choice!=5)
  34.     {
  35.         clrscr();
  36.         cout<<"\n\t\t\t\t*************";
  37.         cout<<"\n\t\t\t\t* MAIN MENU *";
  38.         cout<<"\n\t\t\t\t*************";
  39.         cout<<"\n\n\n\t\t\t1.Book A Room";
  40.         cout<<"\n\t\t\t2.Customer Record";
  41.         cout<<"\n\t\t\t3.Rooms Allotted";
  42.         cout<<"\n\t\t\t4.Edit Record";
  43.         cout<<"\n\t\t\t5.Exit";
  44.         cout<<"\n\n\t\t\tEnter Your Choice: ";
  45.         cin>>choice;
  46.  
  47.         switch(choice)
  48.         {
  49.             case 1: add();
  50.                 break;
  51.             case 2: display();
  52.                 break;
  53.             case 3: rooms();
  54.                 break;
  55.             case 4: edit();
  56.                 break;
  57.             case 5: break;
  58.             default:
  59.                 {
  60.                     cout<<"\n\n\t\t\tWrong choice.....!!!";
  61.                     cout<<"\n\t\t\tPress any key to continue....!!";
  62.                     getch();
  63.                 }
  64.         }
  65.     }
  66. }
  67.  
  68. void hotel::add()
  69. {
  70.     clrscr();
  71.     int r,flag;
  72.     ofstream fout("Record.dat",ios::app);
  73.  
  74.     cout<<"\n Enter Customer Detalis";
  75.     cout<<"\n ----------------------";
  76.     cout<<"\n\n Room no: ";
  77.     cin>>r;
  78.     flag=check(r);
  79.  
  80.     if(flag)
  81.         cout<<"\n Sorry..!!!Room is already booked";
  82.  
  83.     else
  84.     {
  85.         room_no=r;
  86.         cout<<" Name: ";
  87.         gets(name);
  88.         cout<<" Address: ";
  89.         gets(address);
  90.         cout<<" Phone No: ";
  91.         gets(phone);
  92.         fout.write((char*)this,sizeof(hotel));
  93.         cout<<"\n Room is booked...!!!";
  94.     }
  95.  
  96.     cout<<"\n Press any key to continue.....!!";
  97.     getch();
  98.     fout.close();
  99. }
  100.  
  101. void hotel::display()
  102. {
  103.     clrscr();
  104.     ifstream fin("Record.dat",ios::in);
  105.     int r,flag;
  106.     cout<<"\n Enter room no: ";
  107.     cin>>r;
  108.  
  109.     while(!fin.eof())
  110.     {
  111.         fin.read((char*)this,sizeof(hotel));
  112.         if(room_no==r)
  113.         {
  114.             clrscr();
  115.             cout<<"\n Cusromer Details";
  116.             cout<<"\n ----------------";
  117.             cout<<"\n\n Room no: "<<room_no;
  118.             cout<<"\n Name: "<<name;
  119.             cout<<"\n Address: "<<address;
  120.             cout<<"\n Phone no: "<<phone;
  121.             flag=1;
  122.             break;
  123.         }
  124.     }
  125.  
  126.     if(flag==0)
  127.         cout<<"\n Sorry Room no. not found or vacant....!!";
  128.  
  129.     cout<<"\n\n Press any key to continue....!!";
  130.     getch();
  131.     fin.close();
  132.  
  133. }
  134.  
  135.  
  136. void hotel::rooms()
  137. {
  138.     clrscr();
  139.     ifstream fin("Record.dat",ios::in);
  140.     cout<<"\n\t\t\t    List Of Rooms Allotted";
  141.     cout<<"\n\t\t\t    ----------------------";
  142.     cout<<"\n\n Room No.\tName\t\tAddress\t\t\t\tPhone No.\n";
  143.  
  144.     while(!fin.eof())
  145.     {
  146.         fin.read((char*)this,sizeof(hotel));
  147.         cout<<"\n\n "<<room_no<<"\t\t"<<name;
  148.         cout<<"\t\t"<<address<<"\t\t"<<phone;
  149.     }
  150.     cout<<"\n\n\n\t\t\tPress any key to continue.....!!";
  151.     getch();
  152.     fin.close();
  153. }
  154.  
  155. void hotel::edit()
  156. {
  157.     clrscr();
  158.     int choice,r;
  159.  
  160.     cout<<"\n EDIT MENU";
  161.     cout<<"\n ---------";
  162.     cout<<"\n\n 1.Modify Customer Record";
  163.     cout<<"\n 2.Delete Customer Record";
  164.  
  165.     cout<<"\n Enter your choice: ";
  166.     cin>>choice;
  167.     clrscr();
  168.     cout<<"\n Enter room no: " ;
  169.     cin>>r;
  170.  
  171.     switch(choice)
  172.     {
  173.         case 1: modify(r);
  174.             break;
  175.         case 2: delete_rec(r);
  176.             break;
  177.         default: cout<<"\n Wrong Choice.....!!";
  178.     }
  179.     cout<<"\n Press any key to continue....!!!";
  180.     getch();
  181. }
  182.  
  183.  
  184. int hotel::check(int r)
  185. {
  186.     int flag=0;
  187.     ifstream fin("Record.dat",ios::in);
  188.     while(!fin.eof())
  189.     {
  190.         fin.read((char*)this,sizeof(hotel));
  191.         if(room_no==r)
  192.         {
  193.             flag=1;
  194.             break;
  195.         }
  196.     }
  197.  
  198.     fin.close();
  199.     return(flag);
  200. }
  201.  
  202.  
  203. void hotel::modify(int r)
  204. {
  205.     long pos,flag=0;
  206.     fstream file("Record.dat",ios::in|ios::out|ios::binary);
  207.     while(!file.eof())
  208.     {
  209.         pos=file.tellg();
  210.         file.read((char*)this,sizeof(hotel));
  211.         if(room_no==r)
  212.         {
  213.             cout<<"\n Enter New Details";
  214.             cout<<"\n -----------------";
  215.             cout<<"\n Name: ";
  216.             gets(name);
  217.             cout<<" Address: ";
  218.             gets(address);
  219.             cout<<" Phone no: ";
  220.             gets(phone);
  221.  
  222.             file.seekg(pos);
  223.             file.write((char*)this,sizeof(hotel));
  224.             cout<<"\n Record is modified....!!";
  225.             flag=1;
  226.             break;
  227.            }
  228.     }
  229.  
  230.     if(flag==0)
  231.         cout<<"\n Sorry Room no. not found or vacant...!!";
  232.     file.close();
  233. }
  234.  
  235. void hotel::delete_rec(int r)
  236. {
  237.     int flag=0;
  238.     char ch;
  239.     ifstream fin("Record.dat",ios::in);
  240.     ofstream fout("temp.dat",ios::out);
  241.     while(!fin.eof())
  242.     {
  243.         fin.read((char*)this,sizeof(hotel));
  244.         if(room_no==r)
  245.         {
  246.             cout<<"\n Name: "<<name;
  247.             cout<<"\n Address: "<<address;
  248.             cout<<"\n Pone No: "<<phone;
  249.             cout<<"\n\n Do you want to delete this record(y/n): ";
  250.             cin>>ch;
  251.  
  252.             if(ch=='n')
  253.                 fout.write((char*)this,sizeof(hotel));
  254.             flag=1;
  255.         }
  256.         else
  257.             fout.write((char*)this,sizeof(hotel));
  258.     }
  259.  
  260.     fin.close();
  261.     fout.close();
  262.     if(flag==0)
  263.         cout<<"\n Sorry room no. not found or vacant...!!";
  264.     else
  265.     {
  266.         remove("Record.dat");
  267.         rename("temp.dat","Record.dat");
  268.     }
  269. }
  270.  
  271.  
  272. void main()
  273. {
  274.     hotel h;
  275.  
  276.  
  277.     clrscr();
  278.     cout<<"\n\t\t\t****************************";
  279.     cout<<"\n\t\t\t* HOTEL MANAGEMENT PROJECT *";
  280.     cout<<"\n\t\t\t****************************";
  281.  
  282.  
  283.  
  284.     cout<<"\n\n\n\n\t\tMade By:";
  285.     cout<<"\tAbhas Krishna, Mohammed Adil and Kriti Pratap";
  286.     cout<<"\n\n\t\tSubmitted To:";
  287.     cout<<"\tMrs. Seema Chauhan";
  288.     cout<<"\n\n\n\n\n\n\n\t\t\t\t\tPress any key to continue....!!";
  289.     getch();
  290.     h.main_menu();
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement