Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.87 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<assert.h>
  4. using namespace std;
  5. struct id {
  6.     char ime[10];
  7.     char prezime[20];
  8. };
  9. struct radnik {
  10.     int ib;
  11.     id imeiprezime;
  12.     double dohodak;
  13.     int staz;
  14.     char spol[6];
  15. };
  16. void unos(radnik *&p, int x)
  17. {
  18.     for (int i = 0;i < x;i++)
  19.     {
  20.         cout << "Unesi ime i prezime: ";
  21.         cin >> p[i].imeiprezime.ime >> p[i].imeiprezime.prezime;
  22.         cout << "\nUnesi spol: ";
  23.         cin >> p[i].spol;
  24.         cout << "\nUnesi ib: ";
  25.         cin >> p[i].ib;
  26.         cout << "\nUnesi dohodak: ";
  27.         cin >> p[i].dohodak;
  28.         cout << "Unesi staz: ";
  29.         cin >> p[i].staz;
  30.     }
  31. }
  32. void ispis(radnik *p)
  33. {
  34.     cout << "Ime i prezime: " << p->imeiprezime.ime << " " << p->imeiprezime.prezime << endl;
  35.     cout << "Spol: " << p->spol << endl;
  36.     cout << "ib: " << p->ib << endl;
  37.     cout << "Dohodak: " << p->dohodak << endl;
  38.     cout << "Staz: " << p->staz << endl;
  39. }
  40. int prebroji_zene(radnik *p, int x, int &brojac)
  41. {
  42.     brojac = 0;
  43.     for (int i = 0;i < x;i++)
  44.     {
  45.         if (p[i].spol[0] == 'z' || p[i].spol[0] == 'Z')
  46.             brojac++;
  47.     }
  48.     return brojac;
  49. }
  50. void kopiraj_zene(radnik *p, radnik *z, int x)
  51. {
  52.     int j = 0;
  53.     for (int i = 0;i < x;i++)
  54.     {
  55.         if (p[i].spol[0] == 'z' || p[i].spol[0] == 'Z')
  56.         {
  57.             z[j] = p[i];
  58.             j++;
  59.         }
  60.     }
  61. }
  62. radnik *najduze_prezime(radnik *p, int x)
  63. {
  64.     int najduze_p = 0;
  65.     radnik *pok = p;
  66.     string prez;
  67.     for (int i = 0;i < x;i++)
  68.     {
  69.         prez = p[i].imeiprezime.prezime;
  70.         if (najduze_p < prez.length())
  71.         {
  72.             najduze_p = prez.length();
  73.             pok = &p[i];
  74.         }
  75.     }
  76.     return pok;
  77. }
  78. double prihod(radnik *p, int x, int nesta)
  79. {
  80.     double suma = 0;
  81.     for (int i = 0;i < x;i++)
  82.     {
  83.         if (i == nesta)
  84.         {
  85.             suma = (p[i].dohodak + p[i].dohodak*0.06) * 12;
  86.         }
  87.     }
  88.     return suma;
  89. }
  90. void pretraga_po_imenu(radnik *p, char *covjek, int x)
  91. {
  92.     for (int i = 0;i < x;i++)
  93.     {
  94.         if (*covjek == *p[i].imeiprezime.ime)
  95.         {
  96.             ispis(p);
  97.         }
  98.     }
  99. }
  100.  
  101. int main()
  102. {
  103.     radnik *p;
  104.     radnik *zenski_niz = nullptr;
  105.     int broj_ljudi;
  106.     char covjek[5];
  107.     int nesta;
  108.     int j;
  109.     radnik* pok;
  110.     cout << "Unesi broj ljudi " << endl;
  111.     cin >> broj_ljudi;
  112.     p = new radnik[broj_ljudi];
  113.     unos(p, broj_ljudi);
  114.     assert(p != nullptr);
  115.     for (int i = 0;i < broj_ljudi;i++)
  116.         ispis(p + i);
  117.     cout << "Medju radnicima ima " << prebroji_zene(p, broj_ljudi, j) << " zena" << endl;
  118.     zenski_niz = new radnik[j];
  119.     kopiraj_zene(p, zenski_niz, broj_ljudi);
  120.     assert(zenski_niz != nullptr);
  121.     cout << "Najduze prezime: ";
  122.     pok = najduze_prezime(p, broj_ljudi);
  123.     cout << pok->imeiprezime.prezime << endl;
  124.     cout << "Unesi ib nekog radnika" << endl;
  125.     cin >> nesta;
  126.     cout << "Prihod radnika je" << prihod(p, broj_ljudi, p[nesta].dohodak) << endl;
  127.     cout << "Pretraga po imenu: ";
  128.     cin >> covjek;
  129.     assert(covjek != nullptr);
  130.     pretraga_po_imenu(p, covjek, broj_ljudi);
  131.     delete[] zenski_niz;
  132.     zenski_niz = nullptr;
  133.     delete[] p;
  134.     p = nullptr;
  135.     delete pok;
  136.     pok = nullptr;
  137.     system("PAUSE");
  138.     return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement