Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<assert.h>
- using namespace std;
- struct id {
- char ime[10];
- char prezime[20];
- };
- struct radnik {
- int ib;
- id imeiprezime;
- double dohodak;
- int staz;
- char spol[6];
- };
- void unos(radnik *&p, int x)
- {
- for (int i = 0;i < x;i++)
- {
- cout << "Unesi ime i prezime: ";
- cin >> p[i].imeiprezime.ime >> p[i].imeiprezime.prezime;
- cout << "\nUnesi spol: ";
- cin >> p[i].spol;
- cout << "\nUnesi ib: ";
- cin >> p[i].ib;
- cout << "\nUnesi dohodak: ";
- cin >> p[i].dohodak;
- cout << "Unesi staz: ";
- cin >> p[i].staz;
- }
- }
- void ispis(radnik *p)
- {
- cout << "Ime i prezime: " << p->imeiprezime.ime << " " << p->imeiprezime.prezime << endl;
- cout << "Spol: " << p->spol << endl;
- cout << "ib: " << p->ib << endl;
- cout << "Dohodak: " << p->dohodak << endl;
- cout << "Staz: " << p->staz << endl;
- }
- int prebroji_zene(radnik *p, int x, int &brojac)
- {
- brojac = 0;
- for (int i = 0;i < x;i++)
- {
- if (p[i].spol[0] == 'z' || p[i].spol[0] == 'Z')
- brojac++;
- }
- return brojac;
- }
- void kopiraj_zene(radnik *p, radnik *z, int x)
- {
- int j = 0;
- for (int i = 0;i < x;i++)
- {
- if (p[i].spol[0] == 'z' || p[i].spol[0] == 'Z')
- {
- z[j] = p[i];
- j++;
- }
- }
- }
- radnik *najduze_prezime(radnik *p, int x)
- {
- int najduze_p = 0;
- radnik *pok = p;
- string prez;
- for (int i = 0;i < x;i++)
- {
- prez = p[i].imeiprezime.prezime;
- if (najduze_p < prez.length())
- {
- najduze_p = prez.length();
- pok = &p[i];
- }
- }
- return pok;
- }
- double prihod(radnik *p, int x, int nesta)
- {
- double suma = 0;
- for (int i = 0;i < x;i++)
- {
- if (i == nesta)
- {
- suma = (p[i].dohodak + p[i].dohodak*0.06) * 12;
- }
- }
- return suma;
- }
- void pretraga_po_imenu(radnik *p, char *covjek, int x)
- {
- for (int i = 0;i < x;i++)
- {
- if (*covjek == *p[i].imeiprezime.ime)
- {
- ispis(p);
- }
- }
- }
- int main()
- {
- radnik *p;
- radnik *zenski_niz = nullptr;
- int broj_ljudi;
- char covjek[5];
- int nesta;
- int j;
- radnik* pok;
- cout << "Unesi broj ljudi " << endl;
- cin >> broj_ljudi;
- p = new radnik[broj_ljudi];
- unos(p, broj_ljudi);
- assert(p != nullptr);
- for (int i = 0;i < broj_ljudi;i++)
- ispis(p + i);
- cout << "Medju radnicima ima " << prebroji_zene(p, broj_ljudi, j) << " zena" << endl;
- zenski_niz = new radnik[j];
- kopiraj_zene(p, zenski_niz, broj_ljudi);
- assert(zenski_niz != nullptr);
- cout << "Najduze prezime: ";
- pok = najduze_prezime(p, broj_ljudi);
- cout << pok->imeiprezime.prezime << endl;
- cout << "Unesi ib nekog radnika" << endl;
- cin >> nesta;
- cout << "Prihod radnika je" << prihod(p, broj_ljudi, p[nesta].dohodak) << endl;
- cout << "Pretraga po imenu: ";
- cin >> covjek;
- assert(covjek != nullptr);
- pretraga_po_imenu(p, covjek, broj_ljudi);
- delete[] zenski_niz;
- zenski_niz = nullptr;
- delete[] p;
- p = nullptr;
- delete pok;
- pok = nullptr;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement