Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Code by proffesional developer Krzysztof Palka
- * Date: 28.01.2015
- * Time: 21:07
- *
- * Project for Patryk Skibiński
- * Have a nice day :)
- */
- #include <iostream>
- #include <conio.h>
- #include <stdlib.h>
- #include <fstream>
- #include <string.h>
- using namespace std;
- class hotel
- {
- string room_no;
- string imie;
- string nazwisko;
- string numer_tel;
- bool admin;
- public:
- hotel();
- void glowne();
- void dodaj_rekord();
- void wyswietl_rekordy();
- void pokoje();
- void modyfikacja();
- bool sprawdz(string r);
- void modyfikuj(string r);
- void usuwanie(string r);
- void logowanie();
- };
- hotel::hotel()
- {
- admin = false;
- }
- void hotel::glowne()
- {
- int wyb;
- if(admin)
- while(wyb!=5)
- {
- system("cls");
- cout<<"\t\t\t\t\t\t\t\t\t Admin\n";
- cout<<"\n\t\t\t\t***************";
- cout<<"\n\t\t\t\t* MENU GLOWNE *";
- cout<<"\n\t\t\t\t***************";
- cout<<"\n\n\n\t\t\t1.ZAREZERWUJ POKOJ";
- cout<<"\n\t\t\t2.ZAJETE POKOJE";
- cout<<"\n\t\t\t3.WSZYSTKIE ZAREZERWOWANE POKOJE";
- cout<<"\n\t\t\t4.MODYFIKACJA REZERWACJI";
- cout<<"\n\t\t\t5.WYJSCIE";
- cout<<"\n\n\t\t\tWYBIERZ OPCJE: ";
- cin>>wyb;
- switch(wyb)
- {
- case 1: dodaj_rekord();
- break;
- case 2: wyswietl_rekordy();
- break;
- case 3: pokoje();
- break;
- case 4: modyfikacja();
- break;
- case 5: break;
- default:
- {
- cout<<"\n\n\t\t\tNIE MA TAKIEJ OPCJI.....!!!";
- cout<<"\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
- getch();
- }
- }
- }
- else
- while(wyb!=4)
- {
- system("cls");
- cout<<"\n\t\t\t\t***************";
- cout<<"\n\t\t\t\t* MENU GLOWNE *";
- cout<<"\n\t\t\t\t***************";
- cout<<"\n\n\n\t\t\t1.ZAREZERWUJ POKOJ";
- cout<<"\n\t\t\t2.ZAJETE POKOJE";
- cout<<"\n\t\t\t3.WSZYSTKIE ZAREZERWOWANE POKOJE";
- cout<<"\n\t\t\t4.WYJSCIE";
- cout<<"\n\n\t\t\tWYBIERZ OPCJE: ";
- cin>>wyb;
- switch(wyb)
- {
- case 1: dodaj_rekord();
- break;
- case 2: wyswietl_rekordy();
- break;
- case 3: pokoje();
- break;
- case 4: break;
- default:
- {
- cout<<"\n\n\t\t\tNIE MA TAKIEJ OPCJI.....!!!";
- cout<<"\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
- getch();
- }
- }
- }
- }
- void hotel::logowanie()
- {
- string pass;
- while(true)
- {
- cout<<"\n\t\tWprowadz haslo: ";
- cin>>pass;
- system("cls");
- if ((pass=="admin") or (pass=="user"))
- break;
- else
- cout<<"\n\t\tWprowadz poprawne haslo!";
- }
- if(pass == "admin")
- admin = true;
- }
- void hotel::dodaj_rekord()
- {
- system("cls");
- cout<<"\n WPROWADZ DANE";
- cout<<"\n ----------------------";
- cout<<"\n\n NUMER POKOJU: ";
- string r;
- cin >> r;
- if(sprawdz(r))
- cout<<"\n PRZEPRASZAMY,POKOJ JEST JUZ ZAJETY";
- else
- {
- fstream fout("rezerwacja.txt",ios::out|ios::app);
- string imie, nazwisko, numer_tel;
- cout<<" IMIE: "; cin>>imie;
- cout<<" NAZWISKO: "; cin>>nazwisko;
- cout<<" NUMER TELEFONU: "; cin>>numer_tel;
- fout << r << endl;
- fout << imie << endl;
- fout << nazwisko << endl;
- fout << numer_tel << endl;
- cout<<"\n POKOJ ZOSTAL ZAREZERWOWANY...!!!";
- fout.close();
- }
- cout<<"\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
- getch();
- }
- void hotel::wyswietl_rekordy()
- {
- system("cls");
- fstream fin("rezerwacja.txt",ios::in);
- if(!fin.good())
- {
- cout << "\n\n\n\t\t\tWSZYSTKIE POKOJE SA WOLNE!" << endl;
- cout <<"\n\n\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
- getch();
- }
- else
- {
- cout<<"\n\n NUMER POKOJU: ";
- string r;
- cin>>r;
- bool jest = false;
- while(!fin.eof())
- {
- string imie;
- string nazwisko;
- string numer_tel;
- string room_no;
- getline(fin,room_no);
- getline(fin,imie);
- getline(fin,nazwisko);
- getline(fin,numer_tel);
- if(room_no==r)
- {
- system("cls");
- cout<<"\n DETALE REZERWACJI";
- cout<<"\n ----------------";
- cout<<"\n\n NUMER POKOJU: " << r;
- cout<<"\n IMIE: " << imie;
- cout<<"\n NAZWISKO: " << nazwisko;
- cout<<"\n NUMER TELEFONU: " << numer_tel;
- jest = true;
- break;
- }
- }
- if(!jest)
- cout<<"\n PRZEPRASZAMY,POKOJ O PODANYM NUMERZE NIE ISTNIEJE LUB JEST NIE WYNAJETY....!!";
- cout<<"\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
- getch();
- fin.close();
- }
- }
- void hotel::pokoje()
- {
- system("cls");
- fstream fin("rezerwacja.txt",ios::in);
- if(!fin.good())
- {
- cout << "\n\n\n\t\t\tWSZYSTKIE POKOJE SA WOLNE!" << endl;
- cout<<"\n\n\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
- getch();
- }
- else
- {
- cout<<"\n\t\t\t LISTA PRZYDZIELONYCH POKOI";
- cout<<"\n\t\t\t --------------------------";
- cout<<"\n\n NR POKOJU\tIMIE\t\t\tNAZWISKO\t\tNUMER.TEL\n";
- while(!fin.eof())
- {
- string imie;
- string nazwisko;
- string numer_tel;
- string room_no;
- getline(fin,room_no);
- getline(fin,imie);
- getline(fin,nazwisko);
- getline(fin,numer_tel);
- cout<<"\n\n ";
- cout << room_no;
- cout<<"\t\t";
- cout<<imie;
- if(imie.length() < 8) cout << "\t";
- cout<<"\t\t";
- cout<<nazwisko;
- if(nazwisko.length() < 8) cout << "\t";
- cout<<"\t\t";
- cout<<numer_tel;
- }
- cout<<"\n\n\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
- getch();
- fin.close();
- }
- }
- void hotel::modyfikacja()
- {
- system("cls");
- cout<<"\n MENU EDYCJI";
- cout<<"\n ---------";
- cout<<"\n\n 1.ZMODYFIKUJ REZERWACJE";
- cout<<"\n 2.USUN REKORD";
- cout<<"\n WYBIERZ OPCJE: ";
- int wyb;
- cin >> wyb;
- system("cls");
- cout<<"\n WPROWADZ NUMER POKOJU " ;
- string r;
- cin >> r;
- switch(wyb)
- {
- case 1: modyfikuj(r); break;
- case 2: usuwanie(r); break;
- default: cout<<"\n NIE MA TAKIEJ OPCJI.....!!";
- }
- cout<<"\n\t\t\tWCISNIJ DOWOLNY KLAWISZ ABY KONTYNUOWAC....!!";
- getch();
- }
- bool hotel::sprawdz(string r)
- {
- bool flag=false;
- fstream fin("rezerwacja.txt",ios::in);
- if(fin.good())
- {
- while(!fin.eof())
- {
- string wczytana;
- getline(fin, wczytana);
- if(wczytana==r)
- {
- flag=true;
- break;
- }
- for (int i=0; i<3; i++)
- getline(fin, wczytana);
- }
- fin.close();
- }
- return(flag);
- }
- void hotel::modyfikuj(string r)
- {
- string nr;
- string imie;
- string nazwisko;
- string numer_tel;
- string PLIK = "";
- bool flag = false;
- fstream file("rezerwacja.txt",ios::in);
- if(file.good())
- {
- getline(file, nr);
- while(!file.eof())
- {
- if(nr == r)
- {
- string TRUNK;
- getline(file, TRUNK);
- getline(file, TRUNK);
- getline(file, TRUNK);
- flag = true;
- cout<<"\n WPROWADZ NOWE DANE";
- cout<<"\n -----------------\n";
- cout<<" IMIE: ";
- cin >> imie;
- cout<<" NAZWISKO: ";
- cin >> nazwisko;
- cout<<" NUMER TELEFONU: ";
- cin >> numer_tel;
- PLIK += nr;
- PLIK += "\n";
- PLIK += imie;
- PLIK += "\n";
- PLIK += nazwisko;
- PLIK += "\n";
- PLIK += numer_tel;
- PLIK += "\n";
- }
- else
- {
- getline(file, imie);
- getline(file, nazwisko);
- getline(file, numer_tel);
- PLIK += nr;
- PLIK += "\n";
- PLIK += imie;
- PLIK += "\n";
- PLIK += nazwisko;
- PLIK += "\n";
- PLIK += numer_tel;
- PLIK += "\n";
- }
- getline(file, nr);
- }
- file.close();
- fstream file("rezerwacja.txt",ios::trunc|ios::out);
- file << PLIK;
- file.close();
- if(!flag)
- cout<<"\n PRZEPRASZAMY NIE MA TAKIEGO POKOJU LUB JEST ON WOLNY...!!";
- }
- else cout << "Nie otworzylem pliku";
- }
- void hotel::usuwanie(string r)
- {
- string nr;
- string imie;
- string nazwisko;
- string numer_tel;
- string PLIK = "";
- bool flag = false;
- fstream file("rezerwacja.txt",ios::in);
- if(file.good())
- {
- getline(file, nr);
- while(!file.eof())
- {
- if(nr == r)
- {
- string TRUNK;
- getline(file, TRUNK);
- getline(file, TRUNK);
- getline(file, TRUNK);
- flag = true;
- }
- else
- {
- getline(file, imie);
- getline(file, nazwisko);
- getline(file, numer_tel);
- PLIK += nr;
- PLIK += "\n";
- PLIK += imie;
- PLIK += "\n";
- PLIK += nazwisko;
- PLIK += "\n";
- PLIK += numer_tel;
- PLIK += "\n";
- }
- getline(file, nr);
- }
- file.close();
- fstream file("rezerwacja.txt",ios::trunc|ios::out);
- file << PLIK;
- file.close();
- if(!flag)
- cout<<"\n PRZEPRASZAMY NIE MA TAKIEGO POKOJU LUB JEST ON WOLNY...!!";
- }
- else cout << "Nie otworzylem pliku";
- }
- int main()
- {
- hotel h;
- h.logowanie();
- h.glowne();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement