Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- using namespace std;
- void menu(){
- cout <<"1. Dodaj osobe do książki\n";
- cout <<"2. Wyświetl książkę\n";
- cout <<"3. Wyszukaj osobe z książki\n";
- cout <<"4. Usuń osobe z książki\n";
- cout <<"5. Zmień dane osoby z książki\n";
- cout <<"6. Wyjscie z programu\n";
- cout <<"Podaj co mam zrobić: ";
- }
- void zapisDoPliku(string imie="", string nazwisko="", string numer=""){ //w argumentach dane do zapisu
- fstream plik;
- plik.open("ksiazkatel.txt",ios::in|ios::app);
- if(plik.good()==true){
- plik << imie << "|" << nazwisko << "|" << numer << "\n"; //zapis
- } else cout <<"BLAD ZAPISU DO BAZY!\n";
- plik.close();
- }
- void dodajOsobe(string imie, string nazwisko, string numer){
- zapisDoPliku(imie,nazwisko,numer);
- }
- int wyszukajOsobe(string szukane){ //zwraca indeks wyszukanej osoby
- fstream plik;
- plik.open("ksiazkatel.txt",ios::in);
- string dane; string pomocnicza="";
- vector<string> rekord;
- if(plik.good()==true){
- while(!plik.eof()){
- getline(plik,dane);
- for(int i=0; i<dane.length(); i++){
- if(dane[i]!='|'){ //{
- /*cout << dane[i];*/ pomocnicza+=dane[i];
- //} else {cout << " ";/*i++;*/}
- }
- if(pomocnicza==szukane){
- cout << "Znalazłem!";
- }cout << pomocnicza << " ";pomocnicza="";
- } cout <<"\n";
- }
- } else cout <<"BLAD ODCZYTU BAZY!\n";
- return 0;
- }
- void wyswietlKsiazke(){
- fstream plik;
- plik.open("ksiazkatel.txt",ios::in);
- string dane;
- if(plik.good()==true){
- while(!plik.eof()){
- getline(plik,dane);
- for(int i=0; i<dane.length(); i++){
- if(dane[i]!='|') {
- cout << dane[i];
- } else {cout << " ";/*i++;*/}
- } cout <<"\n";
- }
- } else cout <<"BLAD ODCZYTU BAZY!\n";
- plik.close();
- }
- int main(){
- menu();
- int wybor;
- string imie, nazwisko, numer, szuk; //zmiennej szuk nie moge zdefiniowac w switchu
- cin >> wybor;
- switch (wybor){
- case 1:
- cout << "Podaj imie osoby: ";
- cin >> imie;
- cout <<"Podaj nazwisko: ";
- cin >> nazwisko;
- cout <<"Podaj numer: ";
- cin >> numer;
- dodajOsobe(imie,nazwisko,numer);
- break;
- case 2:
- wyswietlKsiazke();
- break;
- case 3:
- cout <<"Po czym mam szukać: ";
- cin >> szuk;
- wyszukajOsobe(szuk);
- //funkcja3
- break;
- case 4:
- break;
- case 5:
- break;
- case 6:
- return 0;
- default:
- cout << "\n\n\nNIE MA TAKIEJ OPCJI!\n\n";
- //menu();
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement