Advertisement
Guest User

Student zad5

a guest
Dec 12th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.01 KB | None | 0 0
  1. void Zadanie5_ZAPIS()
  2. {
  3.     student temp;
  4.     int ile = 0;
  5.     //ZAPIS
  6.     std::ofstream zapis;
  7.     zapis.open("studentBAZA.txt", std::ios::app | std::ios::out);
  8.     if (zapis)
  9.     {
  10.         std::cout << "Zadanie5. Baza danych - student.\nPodaj ile chcesz wprowadzic studentow do bazy: ";
  11.         std::cin >> ile;
  12.         std::cout << "Podaj dane " << ile << " studentow w kolejnosci: nr_indeksu, imie, nazwisko, wiek, plec(M/K):\n";
  13.         for (int i = 0; i < ile; i++)
  14.         {
  15.             std::cin >> temp;
  16.             zapis << temp;
  17.         }
  18.     }
  19.     zapis.close();
  20. }
  21.  
  22. void Zadanie5_ODCZYT_INDEKS()
  23. {
  24.     std::ifstream odczyt;
  25.     student student_temp;
  26.     odczyt.open("studentBAZA.txt", std::ios::in);
  27.     std::vector<student> student_vec;
  28.  
  29.     if (odczyt)
  30.     {
  31.         while (!odczyt.eof())
  32.         {
  33.             odczyt >> student_temp;
  34.             student_vec.push_back(student_temp);
  35.         }
  36.     }
  37.     student_vec.pop_back();
  38.     odczyt.close();
  39.     int indeks;
  40.     student temp;
  41.     std::cout << "Podaj indeks szukanego studenta: ";
  42.     std::cin >> indeks;
  43.     for (int i = 0; i < student_vec.size(); i++)
  44.     {
  45.         if (indeks == student_vec[i].nr_indeksu)
  46.         {
  47.             temp = student_vec[i];
  48.             std::cout << temp;
  49.         }
  50.     }
  51. }
  52.  
  53. void zadanie5_ODCZYT_WSZYSTKICH_STUDENTOW()
  54. {
  55.     std::ifstream odczyt;
  56.     student student_temp;
  57.     odczyt.open("studentBAZA.txt", std::ios::in);
  58.     std::vector<student> student_vec_all;
  59.  
  60.     if (odczyt)
  61.     {
  62.         while (!odczyt.eof())
  63.         {
  64.  
  65.             odczyt >> student_temp;
  66.             student_vec_all.push_back(student_temp);
  67.         }
  68.     }
  69.     student_vec_all.pop_back();
  70.     odczyt.close();
  71.     student temp;
  72.  
  73.     for (int i = 0; i < student_vec_all.size(); i++)
  74.     {
  75.         temp = student_vec_all[i];
  76.         std::cout << temp;
  77.     }
  78. }
  79.  
  80. void zadanie5_USUWANIE_STUDENTA_Z_LISTY()
  81. {
  82.     std::ifstream odczyt;
  83.     student student_temp;
  84.     odczyt.open("studentBAZA.txt", std::ios::in);
  85.     std::vector<student> student_vec_all;
  86.  
  87.     if (odczyt)
  88.     {
  89.         while (!odczyt.eof())
  90.         {
  91.  
  92.             odczyt >> student_temp;
  93.             student_vec_all.push_back(student_temp);
  94.         }
  95.     }
  96.     student_vec_all.pop_back();
  97.     odczyt.close();
  98.     student temp;
  99.  
  100.     for (int i = 0; i < student_vec_all.size(); i++)
  101.     {
  102.         temp = student_vec_all[i];
  103.         std::cout << temp;
  104.     }
  105.  
  106.     int indeks;
  107.     std::cout << "\nPodaj indeks ucznia, ktorego chcesz usunac z listy: ";
  108.     std::cin >> indeks;
  109.     std::ofstream zapis;
  110.     zapis.open("studentBAZA.txt", std::ios::trunc | std::ios::out);
  111.     if (zapis)
  112.     {
  113.         for (int i = 0; i < student_vec_all.size(); i++)
  114.         {
  115.             if (student_vec_all[i].nr_indeksu != indeks)
  116.             {
  117.                 zapis << student_vec_all[i] << "\n";
  118.             }
  119.         }
  120.     }
  121.  
  122. }
  123. void zadanie5()
  124. {
  125.     int wybor;
  126.     do
  127.     {
  128.         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:  ";
  129.         std::cin >> wybor;
  130.         switch (wybor)
  131.         {
  132.             std::cout << "\n";
  133.             case 1:
  134.                 Zadanie5_ZAPIS();
  135.                 break;
  136.             case 2:
  137.                 Zadanie5_ODCZYT_INDEKS();
  138.                 break;
  139.             case 3:
  140.                 zadanie5_ODCZYT_WSZYSTKICH_STUDENTOW();
  141.                 break;
  142.             case 4:
  143.                 zadanie5_USUWANIE_STUDENTA_Z_LISTY();
  144.                 break;
  145.  
  146.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement