Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <vector>
  5. using namespace std;
  6.  
  7.  
  8. void menu(){
  9.     cout <<"1. Dodaj osobe do książki\n";
  10.     cout <<"2. Wyświetl książkę\n";
  11.     cout <<"3. Wyszukaj osobe z książki\n";
  12.     cout <<"4. Usuń osobe z książki\n";
  13.     cout <<"5. Zmień dane osoby z książki\n";
  14.     cout <<"6. Wyjscie z programu\n";
  15.     cout <<"Podaj co mam zrobić: ";
  16.  
  17. }
  18. void zapisDoPliku(string imie="", string nazwisko="", string numer=""){ //w argumentach dane do zapisu
  19.     fstream plik;
  20.     plik.open("ksiazkatel.txt",ios::in|ios::app);
  21.     if(plik.good()==true){
  22.         plik << imie << "|" << nazwisko << "|" << numer << "\n"; //zapis
  23.     } else cout <<"BLAD ZAPISU DO BAZY!\n";
  24.     plik.close();
  25. }
  26. void dodajOsobe(string imie, string nazwisko, string numer){
  27.     zapisDoPliku(imie,nazwisko,numer);
  28. }
  29.  
  30. int wyszukajOsobe(string szukane){  //zwraca indeks wyszukanej osoby
  31.     fstream plik;
  32.     plik.open("ksiazkatel.txt",ios::in);
  33.     string dane; string pomocnicza="";
  34.     vector<string> rekord;
  35.     if(plik.good()==true){
  36.         while(!plik.eof()){
  37.             getline(plik,dane);
  38.             for(int i=0; i<dane.length(); i++){
  39.                 if(dane[i]!='|'){ //{
  40.                     /*cout << dane[i];*/ pomocnicza+=dane[i];
  41.                 //} else {cout << " ";/*i++;*/}
  42.                 }
  43.                 if(pomocnicza==szukane){
  44.                     cout << "Znalazłem!";
  45.                 }cout << pomocnicza << " ";pomocnicza="";
  46.             } cout <<"\n";
  47.         }
  48.     } else cout <<"BLAD ODCZYTU BAZY!\n";
  49.  
  50. return 0;
  51. }
  52.  
  53. void wyswietlKsiazke(){
  54.     fstream plik;
  55.     plik.open("ksiazkatel.txt",ios::in);
  56.     string dane;
  57.     if(plik.good()==true){
  58.         while(!plik.eof()){
  59.             getline(plik,dane);
  60.             for(int i=0; i<dane.length(); i++){
  61.                 if(dane[i]!='|') {
  62.                     cout << dane[i];
  63.                 } else {cout << " ";/*i++;*/}
  64.             } cout <<"\n";
  65.         }
  66.     } else cout <<"BLAD ODCZYTU BAZY!\n";
  67.     plik.close();
  68. }
  69. int main(){
  70.     menu();
  71.     int wybor;
  72.     string imie, nazwisko, numer, szuk; //zmiennej szuk nie moge zdefiniowac w switchu
  73.     cin >> wybor;
  74.     switch (wybor){
  75.         case 1:
  76.             cout << "Podaj imie osoby: ";
  77.             cin >> imie;
  78.             cout <<"Podaj nazwisko: ";
  79.             cin >> nazwisko;
  80.             cout <<"Podaj numer: ";
  81.             cin >> numer;
  82.             dodajOsobe(imie,nazwisko,numer);
  83.             break;
  84.         case 2:
  85.             wyswietlKsiazke();
  86.             break;
  87.         case 3:
  88.             cout <<"Po czym mam szukać: ";
  89.             cin >> szuk;
  90.             wyszukajOsobe(szuk);
  91.             //funkcja3
  92.             break;
  93.         case 4:
  94.             break;
  95.         case 5:
  96.             break;
  97.         case 6:
  98.             return 0;
  99.         default:
  100.             cout << "\n\n\nNIE MA TAKIEJ OPCJI!\n\n";
  101.             //menu();
  102.             return 0;
  103.         }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement