Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Datum {
  5.  
  6. int _dan;
  7. int _mjesec;
  8. int _godina;
  9.  
  10. void unos(int d, int m, int g){
  11.  
  12. _dan = d;
  13. _mjesec = m;
  14. _godina = g;
  15.  
  16. }
  17.  
  18.  
  19.  
  20. void ispis(){
  21.  
  22. cout << _dan << "/" << _mjesec << "/" << _godina << endl;
  23. }
  24. };
  25.  
  26. void unos(Datum &datum){
  27.  
  28. cout << "Unesite dan: ";
  29. cin >> datum._dan;
  30. cout << "Unesite mjesec: ";
  31. cin >> datum._mjesec;
  32. cout << "Unesite godinu: ";
  33. cin >> datum._godina;
  34. }
  35.  
  36. void ispis(Datum datum){
  37.  
  38. cout << datum._dan << "/" << datum._mjesec << "/" << datum._godina << endl;
  39. }
  40.  
  41. struct Student
  42. {
  43. char _IB[9];
  44. char _ime[10];
  45. char _prezime[15];
  46. Datum _datumRodjenja;
  47.  
  48. void unos(char ime[], char prezime[], Datum datum){
  49.  
  50. strcpy_s(_ime, strlen(ime)+1, ime);
  51. strcpy_s(_prezime, strlen(prezime) + 1, prezime);
  52. _datumRodjenja = datum;
  53.  
  54.  
  55. }
  56.  
  57. void ispis(){
  58.  
  59. cout << "Ime studenta: " << _ime << endl;
  60. cout << "Prezime studenta: " << _prezime << endl;
  61. cout << "IB: " << _IB << endl;
  62. _datumRodjenja.ispis();
  63.  
  64. }
  65. };
  66.  
  67. void unos(Student &s){
  68.  
  69.  
  70.  
  71. char tmpIme[10], tmpPrez[15];
  72. cout << "Unesite ime studenta: ";
  73. cin.ignore();
  74. cin.getline(tmpIme, 10);
  75. int velIme = strlen(tmpIme)+1;
  76. strcpy_s(s._ime, velIme, tmpIme);
  77.  
  78. cout << "Unesite prezime studenta: ";
  79. cin.getline(tmpPrez, 15);
  80. int velPrez = strlen(tmpPrez) + 1;
  81. strcpy_s(s._prezime, velPrez, tmpPrez);
  82.  
  83. //cin.ignore()
  84. cout << "Unesite dan, mjesec i godinu za datum rodjenja studenta" << endl;
  85. unos(s._datumRodjenja);
  86. //int d, m, g;
  87. //
  88. //cin >> d >> m >> g;
  89. //unos(d,m,g)
  90.  
  91.  
  92.  
  93.  
  94. }
  95.  
  96. void ispis(Student s){
  97.  
  98.  
  99. cout << "Ime studenta: " << s._ime << endl;
  100. cout << "Prezime studenta: " << s._prezime << endl;
  101. cout << "IB studenta; " << s._IB << endl;
  102. cout << "Datum rodjenja studenta: ";
  103. ispis(s._datumRodjenja);
  104. //s._datumRodjenja.ispis();
  105. }
  106.  
  107. //• prilikom incijalizacije IB za svakog studenata upotrijebite funkciju : (prvi IB je 170001)
  108. //char * naredniBrojIndeksa(char * posljednji); funkcija vraća naredni IB, a šaljete joj zadnji iskorišteni IB;
  109.  
  110. int brojIndeksaGlobal = 180000;
  111. char * naredniBrojIndeksa(char * posljednji){
  112.  
  113.  
  114. int size = 9;
  115.  
  116. char *noviIndeks = new char[size];
  117.  
  118. strcpy_s(noviIndeks, size, "IB");
  119.  
  120. char temp[10];
  121.  
  122. _itoa_s(brojIndeksaGlobal, temp, 10);
  123. strcat_s(noviIndeks, size, temp);
  124.  
  125. brojIndeksaGlobal++;
  126. return noviIndeks;
  127.  
  128. }
  129.  
  130. //• pronaći i ispisati studenta koji je rođen na datum kojeg zada korisnik; upotrijebite funkciju :
  131. //Student * pretragaPoDatumuRodjenja(Student *, int, Datum); funkcija vraća pokazivač na studenta koji zadovoljava traženi uvjet;
  132.  
  133.  
  134. bool IstiDatum(Datum d1, Datum d2)
  135. {
  136.  
  137. if (d1._godina == d2._godina && d1._mjesec == d2._mjesec && d1._dan == d2._dan)
  138. return true;
  139.  
  140. return false;
  141.  
  142.  
  143. }
  144.  
  145. Student* pretragaPoDatumuRodjenja(Student *n, int vel, Datum datum){
  146.  
  147. Student temp;
  148. int lok = -1;
  149. bool pronadjeni = false;
  150. for (size_t i = 0; i < vel; i++)
  151. {
  152.  
  153. if (IstiDatum(n[i]._datumRodjenja, datum)) {
  154.  
  155. lok = i;
  156. return&n[lok];
  157. pronadjeni = true;
  158.  
  159.  
  160. }
  161.  
  162. }
  163.  
  164. if(pronadjeni==false){
  165. cout << "Nije pronadjen student s tim datumom..." << endl;
  166. return nullptr;
  167. }
  168. }
  169.  
  170.  
  171. void main(){
  172.  
  173. //Datum danas;
  174. //danas.unos(14, 4, 2018);
  175.  
  176.  
  177.  
  178.  
  179. //Student s1;
  180. //s1.unos("Emir", "Sator", danas);
  181. //strcpy_s(s1._IB, 10, naredniBrojIndeksa(""));
  182. //s1.ispis();
  183. //Student s2;
  184.  
  185. //s1.unos("Emir", "Pajic", danas);
  186. //strcpy_s(s2._IB, 10, naredniBrojIndeksa(""));
  187. //s2.ispis();
  188.  
  189.  
  190.  
  191.  
  192. int v;
  193. cout << "Unesite velicinu niza" << endl;
  194. cin >> v;
  195. Student *niz = new Student[v];
  196.  
  197. for (int i = 0; i < v; i++)
  198. {
  199. unos(niz[i]);
  200. }
  201.  
  202.  
  203. for (int i = 0; i < v; i++)
  204. {
  205. strcpy_s(niz[i]._IB, 10, naredniBrojIndeksa(""));
  206. }
  207. for (int i = 0; i < v; i++)
  208. {
  209. ispis(niz[i]);
  210. }
  211.  
  212.  
  213. Datum jucer;
  214. int d, m, g;
  215. cout << "Unesite dan, mjesec i godinzu za pretragu" << endl;
  216. cin >> d >> m >> g;
  217. jucer.unos(d, m, g);
  218.  
  219.  
  220. if (pretragaPoDatumuRodjenja(niz,v,jucer) != nullptr){
  221. cout << "Studenti rodjeni na datum kojeg je korinisk unio je: " << endl;
  222. ispis(*(pretragaPoDatumuRodjenja(niz, v, jucer)));
  223. }
  224.  
  225.  
  226.  
  227.  
  228. system("pause>0");
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement