Advertisement
Guest User

Hotel

a guest
Jan 28th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.62 KB | None | 0 0
  1. /*
  2. * Code by proffesional developer Krzysztof Palka
  3. * Date: 28.01.2015
  4. * Time: 21:07
  5. *
  6. * Project for Patryk Skibiński
  7. * Have a nice day :)
  8. */
  9.  
  10. #include <iostream>
  11. #include <conio.h>
  12. #include <stdlib.h>
  13. #include <fstream>
  14. #include <string.h>
  15.  
  16. using namespace std;
  17. class hotel
  18. {
  19.     string room_no;
  20.     string imie;
  21.     string nazwisko;
  22.     string numer_tel;
  23.     bool admin;
  24.    
  25. public:
  26.     hotel();
  27.     void glowne();
  28.     void dodaj_rekord();
  29.     void wyswietl_rekordy();
  30.     void pokoje();
  31.     void modyfikacja();
  32.     bool sprawdz(string r);
  33.     void modyfikuj(string r);
  34.     void usuwanie(string r);
  35.     void logowanie();
  36. };
  37.  
  38. hotel::hotel()
  39. {
  40.     admin = false;
  41. }
  42.  
  43. void hotel::glowne()
  44. {
  45.     int wyb;
  46.    
  47.     if(admin)
  48.         while(wyb!=5)
  49.         {
  50.             system("cls");
  51.             cout<<"\t\t\t\t\t\t\t\t\t Admin\n";
  52.             cout<<"\n\t\t\t\t***************";
  53.             cout<<"\n\t\t\t\t* MENU GLOWNE *";
  54.             cout<<"\n\t\t\t\t***************";
  55.             cout<<"\n\n\n\t\t\t1.ZAREZERWUJ POKOJ";
  56.             cout<<"\n\t\t\t2.ZAJETE POKOJE";
  57.             cout<<"\n\t\t\t3.WSZYSTKIE ZAREZERWOWANE POKOJE";
  58.             cout<<"\n\t\t\t4.MODYFIKACJA REZERWACJI";
  59.             cout<<"\n\t\t\t5.WYJSCIE";
  60.             cout<<"\n\n\t\t\tWYBIERZ OPCJE: ";
  61.             cin>>wyb;
  62.            
  63.             switch(wyb)
  64.             {
  65.                 case 1: dodaj_rekord();
  66.                 break;
  67.                 case 2: wyswietl_rekordy();
  68.                 break;
  69.                 case 3: pokoje();
  70.                 break;
  71.                 case 4: modyfikacja();
  72.                 break;
  73.                 case 5: break;
  74.                 default:
  75.                 {
  76.                     cout<<"\n\n\t\t\tNIE MA TAKIEJ OPCJI.....!!!";
  77.                     cout<<"\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
  78.                     getch();
  79.                 }
  80.             }
  81.         }
  82.     else
  83.         while(wyb!=4)
  84.         {
  85.             system("cls");
  86.             cout<<"\n\t\t\t\t***************";
  87.             cout<<"\n\t\t\t\t* MENU GLOWNE *";
  88.             cout<<"\n\t\t\t\t***************";
  89.             cout<<"\n\n\n\t\t\t1.ZAREZERWUJ POKOJ";
  90.             cout<<"\n\t\t\t2.ZAJETE POKOJE";
  91.             cout<<"\n\t\t\t3.WSZYSTKIE ZAREZERWOWANE POKOJE";
  92.             cout<<"\n\t\t\t4.WYJSCIE";
  93.             cout<<"\n\n\t\t\tWYBIERZ OPCJE: ";
  94.             cin>>wyb;
  95.            
  96.             switch(wyb)
  97.             {
  98.                 case 1: dodaj_rekord();
  99.                 break;
  100.                 case 2: wyswietl_rekordy();
  101.                 break;
  102.                 case 3: pokoje();
  103.                 break;
  104.                 case 4: break;
  105.                 default:
  106.                 {
  107.                     cout<<"\n\n\t\t\tNIE MA TAKIEJ OPCJI.....!!!";
  108.                     cout<<"\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
  109.                     getch();
  110.                 }
  111.             }
  112.         }
  113. }
  114.  
  115. void hotel::logowanie()
  116. {
  117.     string pass;
  118.     while(true)
  119.     {
  120.         cout<<"\n\t\tWprowadz haslo: ";
  121.         cin>>pass;
  122.         system("cls");
  123.        
  124.         if ((pass=="admin") or (pass=="user"))
  125.             break;
  126.         else       
  127.             cout<<"\n\t\tWprowadz poprawne haslo!";        
  128.     }
  129.     if(pass == "admin")
  130.         admin = true;
  131. }
  132.  
  133. void hotel::dodaj_rekord()
  134. {
  135.     system("cls");
  136.    
  137.     cout<<"\n WPROWADZ DANE";
  138.     cout<<"\n ----------------------";
  139.     cout<<"\n\n NUMER POKOJU: ";
  140.    
  141.     string r;
  142.     cin >> r;
  143.  
  144.     if(sprawdz(r))
  145.         cout<<"\n PRZEPRASZAMY,POKOJ JEST JUZ ZAJETY";
  146.     else
  147.     {
  148.         fstream fout("rezerwacja.txt",ios::out|ios::app);
  149.         string imie, nazwisko, numer_tel;
  150.  
  151.         cout<<" IMIE: "; cin>>imie;
  152.         cout<<" NAZWISKO: "; cin>>nazwisko;
  153.         cout<<" NUMER TELEFONU: "; cin>>numer_tel;
  154.        
  155.         fout << r << endl;
  156.         fout << imie << endl;
  157.         fout << nazwisko << endl;
  158.         fout << numer_tel << endl;
  159.        
  160.         cout<<"\n POKOJ ZOSTAL ZAREZERWOWANY...!!!";
  161.        
  162.         fout.close();
  163.     }
  164.    
  165.    
  166.     cout<<"\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
  167.     getch();
  168. }
  169.  
  170. void hotel::wyswietl_rekordy()
  171. {
  172.     system("cls");
  173.     fstream fin("rezerwacja.txt",ios::in);
  174.     if(!fin.good())
  175.     {
  176.         cout << "\n\n\n\t\t\tWSZYSTKIE POKOJE SA WOLNE!" << endl;
  177.         cout <<"\n\n\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
  178.         getch();
  179.     }
  180.     else
  181.     {
  182.         cout<<"\n\n NUMER POKOJU: ";
  183.         string r;
  184.         cin>>r;
  185.         bool jest = false;
  186.                
  187.         while(!fin.eof())
  188.         {
  189.             string imie;
  190.             string nazwisko;
  191.             string numer_tel;
  192.             string room_no;
  193.             getline(fin,room_no);
  194.             getline(fin,imie);
  195.             getline(fin,nazwisko);
  196.             getline(fin,numer_tel);
  197.            
  198.             if(room_no==r)
  199.             {
  200.                 system("cls");
  201.                 cout<<"\n DETALE REZERWACJI";
  202.                 cout<<"\n ----------------";
  203.                 cout<<"\n\n NUMER POKOJU: " << r;
  204.                 cout<<"\n IMIE: " << imie;
  205.                 cout<<"\n NAZWISKO: " << nazwisko;
  206.                 cout<<"\n NUMER TELEFONU: " << numer_tel;
  207.                 jest = true;
  208.                 break;
  209.             }
  210.         }      
  211.         if(!jest)
  212.             cout<<"\n PRZEPRASZAMY,POKOJ O PODANYM NUMERZE NIE ISTNIEJE LUB JEST NIE WYNAJETY....!!";
  213.  
  214.         cout<<"\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
  215.         getch();       
  216.         fin.close();   
  217.     }
  218. }
  219.  
  220. void hotel::pokoje()
  221. {
  222.     system("cls");
  223.     fstream fin("rezerwacja.txt",ios::in);
  224.    
  225.     if(!fin.good())
  226.     {
  227.         cout << "\n\n\n\t\t\tWSZYSTKIE POKOJE SA WOLNE!" << endl;
  228.         cout<<"\n\n\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
  229.         getch();
  230.     }
  231.     else
  232.     {
  233.         cout<<"\n\t\t\t    LISTA PRZYDZIELONYCH POKOI";
  234.         cout<<"\n\t\t\t    --------------------------";
  235.         cout<<"\n\n NR POKOJU\tIMIE\t\t\tNAZWISKO\t\tNUMER.TEL\n";
  236.        
  237.         while(!fin.eof())
  238.         {
  239.             string imie;
  240.             string nazwisko;
  241.             string numer_tel;
  242.             string room_no;
  243.             getline(fin,room_no);
  244.             getline(fin,imie);
  245.             getline(fin,nazwisko);
  246.             getline(fin,numer_tel);
  247.  
  248.            
  249.             cout<<"\n\n ";
  250.             cout << room_no;
  251.             cout<<"\t\t";
  252.             cout<<imie;
  253.             if(imie.length() < 8) cout << "\t";
  254.             cout<<"\t\t";
  255.             cout<<nazwisko;
  256.             if(nazwisko.length() < 8) cout << "\t";
  257.             cout<<"\t\t";
  258.             cout<<numer_tel;
  259.         }
  260.         cout<<"\n\n\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
  261.         getch();
  262.         fin.close();
  263.     }
  264. }
  265.  
  266. void hotel::modyfikacja()
  267. {
  268.     system("cls");
  269.    
  270.     cout<<"\n MENU EDYCJI";
  271.     cout<<"\n ---------";
  272.     cout<<"\n\n 1.ZMODYFIKUJ REZERWACJE";
  273.     cout<<"\n 2.USUN REKORD";
  274.     cout<<"\n WYBIERZ OPCJE: ";
  275.     int wyb;
  276.     cin >> wyb;
  277.    
  278.     system("cls");
  279.     cout<<"\n WPROWADZ NUMER POKOJU " ;
  280.     string r;
  281.     cin >> r;
  282.    
  283.     switch(wyb)
  284.     {
  285.         case 1: modyfikuj(r); break;
  286.         case 2: usuwanie(r); break;
  287.         default: cout<<"\n NIE MA TAKIEJ OPCJI.....!!";
  288.     }
  289.     cout<<"\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
  290.     getch();
  291. }
  292.  
  293.  
  294. bool hotel::sprawdz(string r)
  295. {
  296.     bool flag=false;
  297.     fstream fin("rezerwacja.txt",ios::in);
  298.     if(fin.good())
  299.     {
  300.         while(!fin.eof())
  301.         {
  302.             string wczytana;
  303.            
  304.             getline(fin, wczytana);
  305.                
  306.             if(wczytana==r)
  307.             {
  308.                 flag=true;
  309.                 break;
  310.             }
  311.            
  312.             for (int i=0; i<3; i++)
  313.                 getline(fin, wczytana);
  314.         }
  315.         fin.close();
  316.     }
  317.     return(flag);
  318. }
  319.  
  320.  
  321. void hotel::modyfikuj(string r)
  322. {
  323.     string nr;
  324.     string imie;
  325.     string nazwisko;
  326.     string numer_tel;
  327.     string PLIK = "";
  328.    
  329.     bool flag = false;
  330.     fstream file("rezerwacja.txt",ios::in);
  331.    
  332.     if(file.good())
  333.     {
  334.         getline(file, nr); 
  335.         while(!file.eof())
  336.         {  
  337.             if(nr == r)
  338.             {
  339.                 string TRUNK;
  340.                 getline(file, TRUNK);
  341.                 getline(file, TRUNK);
  342.                 getline(file, TRUNK);
  343.                
  344.                 flag = true;
  345.                 cout<<"\n WPROWADZ NOWE DANE";
  346.                 cout<<"\n -----------------\n";
  347.                 cout<<" IMIE: ";
  348.                 cin >> imie;
  349.                
  350.                 cout<<" NAZWISKO: ";
  351.                 cin >> nazwisko;
  352.                
  353.                 cout<<" NUMER TELEFONU: ";
  354.                 cin >> numer_tel;
  355.                
  356.                 PLIK += nr;
  357.                 PLIK += "\n";
  358.                 PLIK += imie;
  359.                 PLIK += "\n";
  360.                 PLIK += nazwisko;
  361.                 PLIK += "\n";
  362.                 PLIK += numer_tel;
  363.                 PLIK += "\n";
  364.             }
  365.             else
  366.             {
  367.                 getline(file, imie);
  368.                 getline(file, nazwisko);
  369.                 getline(file, numer_tel);
  370.                
  371.                 PLIK += nr;
  372.                 PLIK += "\n";
  373.                 PLIK += imie;
  374.                 PLIK += "\n";
  375.                 PLIK += nazwisko;
  376.                 PLIK += "\n";
  377.                 PLIK += numer_tel;
  378.                 PLIK += "\n";
  379.             }
  380.             getline(file, nr);
  381.         }
  382.         file.close();
  383.        
  384.         fstream file("rezerwacja.txt",ios::trunc|ios::out);
  385.         file << PLIK;
  386.         file.close();
  387.        
  388.         if(!flag)
  389.             cout<<"\n PRZEPRASZAMY NIE MA TAKIEGO POKOJU LUB JEST ON WOLNY...!!";
  390.            
  391.     }
  392.     else cout << "Nie otworzylem pliku";
  393. }
  394.  
  395. void hotel::usuwanie(string r)
  396. {
  397.     string nr;
  398.     string imie;
  399.     string nazwisko;
  400.     string numer_tel;
  401.     string PLIK = "";
  402.    
  403.     bool flag = false;
  404.     fstream file("rezerwacja.txt",ios::in);
  405.    
  406.     if(file.good())
  407.     {
  408.         getline(file, nr); 
  409.         while(!file.eof())
  410.         {  
  411.             if(nr == r)
  412.             {
  413.                 string TRUNK;
  414.                 getline(file, TRUNK);
  415.                 getline(file, TRUNK);
  416.                 getline(file, TRUNK);
  417.                 flag = true;
  418.             }
  419.             else
  420.             {
  421.                 getline(file, imie);
  422.                 getline(file, nazwisko);
  423.                 getline(file, numer_tel);
  424.                
  425.                 PLIK += nr;
  426.                 PLIK += "\n";
  427.                 PLIK += imie;
  428.                 PLIK += "\n";
  429.                 PLIK += nazwisko;
  430.                 PLIK += "\n";
  431.                 PLIK += numer_tel;
  432.                 PLIK += "\n";
  433.             }
  434.             getline(file, nr);
  435.         }
  436.         file.close();
  437.        
  438.         fstream file("rezerwacja.txt",ios::trunc|ios::out);
  439.         file << PLIK;
  440.         file.close();
  441.        
  442.         if(!flag)
  443.             cout<<"\n PRZEPRASZAMY NIE MA TAKIEGO POKOJU LUB JEST ON WOLNY...!!";
  444.            
  445.     }
  446.     else cout << "Nie otworzylem pliku";
  447. }
  448.  
  449. int main()
  450. {
  451.     hotel h;
  452.     h.logowanie();
  453.     h.glowne();
  454. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement