Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include <stdlib.h>
- #include <string>
- #include <fstream>
- using namespace std;
- void wymagajEnter();
- void dodajOsobe();
- void pokazOsoby();
- void zapiszOsobyDoPliku();
- void wczytajOsobyzPliku();
- void PrzeszukajBaze();
- void UsunOsobe();
- struct Czlowiek
- {
- string imie;
- string nazwisko;
- short wiek;
- string telefon;
- };
- short ileDodanoOsob;
- Czlowiek ludzie[20];
- int main()
- {
- char tescior;
- do
- {
- cout << "OS w bazie :" << ileDodanoOsob;
- cout << " MENU: " << endl;
- cout << " 1. Dodaj odobe" << endl;
- cout << " 2. Pokaz osoby" << endl;
- cout << " 3. Zapisz Osoby do pliku" << endl;
- cout << " 4. Wczyataj Osoby z pliku" << endl;
- cout << "5. Przeszukaj baze" << endl;
- cout << "6. Usun osobe z bazy danych" << endl;
- tescior = _getch();
- switch (tescior)
- {
- case '1':
- dodajOsobe();
- break;
- case '2':
- pokazOsoby(); break;
- case '3':
- zapiszOsobyDoPliku();
- break;
- case '4' :
- wczytajOsobyzPliku(); break;
- case '5' :
- PrzeszukajBaze(); break;
- case '6':
- UsunOsobe(); break;
- }
- wymagajEnter();
- system("cls");
- } while (tescior != 27);
- return 0;
- }
- void wymagajEnter()
- {
- cout << "Nacisnij ENTER aby kontnyowac" << endl;
- while (_getch() != 13);
- }
- void dodajOsobe()
- {
- cout << "Podaj imie:";
- cin >> ludzie[ileDodanoOsob].imie;
- cout << "Podaj nazwisko:";
- cin >> ludzie[ileDodanoOsob].nazwisko;
- cout << "Podaj wiek:";
- cin >> ludzie[ileDodanoOsob].wiek;
- cout << "Podaj nr_tel:";
- cin >> ludzie[ileDodanoOsob].telefon;
- ileDodanoOsob++;
- }
- void pokazOsoby()
- {
- if (ileDodanoOsob > 0)
- {
- for (int j = 0; j < ileDodanoOsob; j++)
- {
- cout << "Osoba nr:" << (j+1) << endl;
- cout << "Imie: " << ludzie[j].imie << endl;
- cout << "Nazwisko:" << ludzie[j].nazwisko << endl;
- cout << "Wiek: " << ludzie[j].wiek << endl;
- cout << "Nr_tel:" << ludzie[j].telefon << endl << endl;
- }
- }
- }
- void zapiszOsobyDoPliku()
- {
- ofstream file("baza.txt");
- if (file.is_open())
- {
- file << ileDodanoOsob << endl;
- for (int j = 0; j < ileDodanoOsob; j++)
- {
- file << ludzie[j].imie << endl;
- file << ludzie[j].nazwisko << endl;
- file << ludzie[j].wiek << endl;
- file << ludzie[j].telefon << endl;
- }
- file.close();
- }
- else
- cout << "Plik nie zostal otwarty poprawnie" << endl;
- }
- void wczytajOsobyzPliku()
- {
- ifstream file("baza.txt");
- if (file.is_open())
- {
- file >> ileDodanoOsob;
- for (int j = 0; j < ileDodanoOsob; j++)
- {
- file >> ludzie[j].imie;
- file >> ludzie[j].nazwisko;
- file >> ludzie[j].wiek;
- file >> ludzie[j].telefon ;
- }
- file.close();
- }
- else cout << "Nie udalo sie otworzyc pliku";
- }
- void PrzeszukajBaze()
- {
- if (ileDodanoOsob != 0)
- {
- string imie;
- cout << "Podaj imie, a podam ci wiecej danych uzytkownika";
- cin >> imie;
- for (int j = 0; j < ileDodanoOsob; j++)
- {
- if (imie == ludzie[j].imie)
- {
- cout << "Osoba nr: " << (j + 1) << endl;
- cout << "Imie: " << ludzie[j].imie << endl;
- cout << "Nazwisko: " << ludzie[j].nazwisko << endl;
- cout << "Wiek: " << ludzie[j].wiek << endl;
- cout << "Telefon: " << ludzie[j].telefon << endl;
- }
- }
- }
- else cout << "Baza danych jest pusta";
- }
- void UsunOsobe()
- {
- if (ileDodanoOsob != 0)
- {
- short indeks;
- cout << "Podaj indeks osoby ktorej chcesz usunac" << endl;
- cin >> indeks;
- for (short k = indeks; k > ileDodanoOsob; k++)
- {
- ludzie[k - 1].imie = ludzie[k].imie;
- ludzie[k - 1].nazwisko = ludzie[k].nazwisko;
- ludzie[k - 1].wiek = ludzie[k].wiek;
- ludzie[k - 1].telefon = ludzie[k].telefon;
- }
- ileDodanoOsob--;
- zapiszOsobyDoPliku();
- cout << "Uzytkownik o indeksie" << indeks << "zostala usunieta" << endl;
- }
- else
- cout << "Pusta baza danych" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement