Advertisement
MrEfendi

Struktury w <vector> ATH Bielsko-Biała C++

Jan 11th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. struct TOsoba {
  10.     int id;
  11.     string imie;
  12.     string nazwisko;
  13. };
  14.  
  15. TOsoba* TworzOsobe(int id, string imie, string nazwisko) {
  16.     TOsoba *nowa_osoba = new TOsoba;
  17.  
  18.     nowa_osoba->id = id;
  19.     nowa_osoba->imie = imie;
  20.     nowa_osoba->nazwisko = nazwisko;
  21.  
  22.     return nowa_osoba;
  23. }
  24.  
  25. void DodajElementDoTablicy(TOsoba obiekt, vector <TOsoba> &tab) {
  26.     tab.push_back(obiekt);
  27. }
  28.  
  29. void WyczyscTablice(vector <TOsoba> &tab) {
  30.     tab.clear();
  31. }
  32.  
  33. void UsunTablice(vector <TOsoba> **tab) {
  34.     delete[] tab;
  35. }
  36.  
  37. void WyswietlOsobe(int i, vector <TOsoba> &tab) {
  38.      cout << "ID = " << tab[i].id << " i:" << tab[i].imie << " n:" << tab[i].nazwisko << endl;
  39. }
  40.  
  41. int getTabSize(vector <TOsoba> &tab) {
  42.     return tab.size();
  43. }
  44.  
  45. int main() {
  46.  
  47.     vector <TOsoba> baza;
  48.  
  49.     int wielksc_bazy = 10;
  50.  
  51.     for (int i = 0; i < wielksc_bazy; i++) {
  52.         DodajElementDoTablicy(*TworzOsobe(i, "Andrzej", "Kowalski0"), baza);
  53.     }
  54.  
  55.     for (int i = 0; i < getTabSize(baza); i++) {
  56.         WyswietlOsobe(i, baza);
  57.     }
  58.  
  59.     cout << "nowe prz." << endl;
  60.  
  61.     WyczyscTablice(baza);
  62.     DodajElementDoTablicy(*TworzOsobe(0, "Andrzej", "Kowalski0"), baza);
  63.     DodajElementDoTablicy(*TworzOsobe(1, "Andrzej", "Kowalski0"), baza);
  64.  
  65.     for (int i = 0; i < getTabSize(baza); i++) {
  66.         WyswietlOsobe(i, baza);
  67.     }
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement