Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Zadanie5_ZAPIS()
- {
- student temp;
- int ile = 0;
- //ZAPIS
- std::ofstream zapis;
- zapis.open("studentBAZA.txt", std::ios::app | std::ios::out);
- if (zapis)
- {
- std::cout << "Zadanie5. Baza danych - student.\nPodaj ile chcesz wprowadzic studentow do bazy: ";
- std::cin >> ile;
- std::cout << "Podaj dane " << ile << " studentow w kolejnosci: nr_indeksu, imie, nazwisko, wiek, plec(M/K):\n";
- for (int i = 0; i < ile; i++)
- {
- std::cin >> temp;
- zapis << temp;
- }
- }
- zapis.close();
- }
- void Zadanie5_ODCZYT_INDEKS()
- {
- std::ifstream odczyt;
- student student_temp;
- odczyt.open("studentBAZA.txt", std::ios::in);
- std::vector<student> student_vec;
- if (odczyt)
- {
- while (!odczyt.eof())
- {
- odczyt >> student_temp;
- student_vec.push_back(student_temp);
- }
- }
- student_vec.pop_back();
- odczyt.close();
- int indeks;
- student temp;
- std::cout << "Podaj indeks szukanego studenta: ";
- std::cin >> indeks;
- for (int i = 0; i < student_vec.size(); i++)
- {
- if (indeks == student_vec[i].nr_indeksu)
- {
- temp = student_vec[i];
- std::cout << temp;
- }
- }
- }
- void zadanie5_ODCZYT_WSZYSTKICH_STUDENTOW()
- {
- std::ifstream odczyt;
- student student_temp;
- odczyt.open("studentBAZA.txt", std::ios::in);
- std::vector<student> student_vec_all;
- if (odczyt)
- {
- while (!odczyt.eof())
- {
- odczyt >> student_temp;
- student_vec_all.push_back(student_temp);
- }
- }
- student_vec_all.pop_back();
- odczyt.close();
- student temp;
- for (int i = 0; i < student_vec_all.size(); i++)
- {
- temp = student_vec_all[i];
- std::cout << temp;
- }
- }
- void zadanie5_USUWANIE_STUDENTA_Z_LISTY()
- {
- std::ifstream odczyt;
- student student_temp;
- odczyt.open("studentBAZA.txt", std::ios::in);
- std::vector<student> student_vec_all;
- if (odczyt)
- {
- while (!odczyt.eof())
- {
- odczyt >> student_temp;
- student_vec_all.push_back(student_temp);
- }
- }
- student_vec_all.pop_back();
- odczyt.close();
- student temp;
- for (int i = 0; i < student_vec_all.size(); i++)
- {
- temp = student_vec_all[i];
- std::cout << temp;
- }
- int indeks;
- std::cout << "\nPodaj indeks ucznia, ktorego chcesz usunac z listy: ";
- std::cin >> indeks;
- std::ofstream zapis;
- zapis.open("studentBAZA.txt", std::ios::trunc | std::ios::out);
- if (zapis)
- {
- for (int i = 0; i < student_vec_all.size(); i++)
- {
- if (student_vec_all[i].nr_indeksu != indeks)
- {
- zapis << student_vec_all[i] << "\n";
- }
- }
- }
- }
- void zadanie5()
- {
- int wybor;
- do
- {
- std::cout << "\nZadanie 5. Wybierz co chcesz zrobic:\n1. Dodanie nowego studenta\n2. Odczyt danych po indeksie\n3. Sprawdzenie danych wszystkich studentow\n4. Usuwanie studenta z listy\n0. Koniec\nPodaj numer zadani: ";
- std::cin >> wybor;
- switch (wybor)
- {
- std::cout << "\n";
- case 1:
- Zadanie5_ZAPIS();
- break;
- case 2:
- Zadanie5_ODCZYT_INDEKS();
- break;
- case 3:
- zadanie5_ODCZYT_WSZYSTKICH_STUDENTOW();
- break;
- case 4:
- zadanie5_USUWANIE_STUDENTA_Z_LISTY();
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement