Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. struct TStudent
  9. {
  10. string meno,priez,znamka;
  11. int rodnecS; };
  12.  
  13.  
  14. int rok(int rc)
  15. {
  16. int RR;
  17. RR = (rc/10000);
  18. if (RR<12) return (RR + 2000);
  19.  
  20. else return (RR + 1900);
  21. }
  22.  
  23. void VypisDatum(int c)
  24. {
  25. cout << " ";
  26. cout << c % 100;
  27. cout << ". ";
  28. cout << (c / 100) % 50;
  29. cout << ". ";
  30. cout << rok(c);
  31. }
  32.  
  33.  
  34. int JeZena(int c)
  35. {
  36. if (c % 10000 > 5000)
  37. {
  38. return 1;
  39. }
  40. else
  41. {
  42. return 0;
  43. }
  44. }
  45.  
  46. int PorovnajStudentov(TStudent *s1, TStudent *s2)
  47. {
  48. if ((s1->priez) < (s2->priez))
  49.  
  50. return 1;
  51.  
  52. else
  53. if (s1->priez > s2->priez)
  54. return 0;
  55.  
  56. else if (s1->meno < s2->meno)
  57. return 1;
  58.  
  59. else if (s1->meno > s2->meno)
  60. return 0;
  61. else{
  62.  
  63. int r1 = rok(s1->rodnecS);
  64. int r2 = rok(s2->rodnecS);
  65.  
  66. if (r1<r2)
  67. return 1;
  68. else if (r1>r2)
  69. return 0;
  70. else
  71. return 0;}
  72.  
  73. }
  74.  
  75.  
  76. void InsertionSort(TStudent **pole, int pocet)
  77. {
  78. int i, j;
  79. TStudent* tmp;
  80. for (i = 1; i<pocet; i++)
  81. {
  82. for (j = i, tmp = pole[i]; (j>0) && PorovnajStudentov(tmp, pole[j - 1]); j--)
  83. pole[j] = pole[j - 1];
  84. pole[j] = tmp;
  85. }
  86. }
  87.  
  88.  
  89.  
  90. void vypis_studenta(TStudent *s)
  91. {
  92. cout << s->priez;
  93. cout <<" "<< s->meno << " ";
  94. cout << s->znamka ;
  95.  
  96. if (s->rodnecS >= 100000)
  97. {
  98. cout <<" "<< "rodne cislo" << " " << s->rodnecS << " ";
  99. }
  100. else
  101. {
  102. cout <<" "<< "rodnecilo" << " " << s->rodnecS << " ";
  103. }
  104.  
  105. if (JeZena(s->rodnecS) == 1)
  106. {
  107. cout << "zena, narodena" << " ";
  108. }
  109. else
  110. {
  111. cout << "muz, narodeny" << " ";
  112. }
  113. VypisDatum(s->rodnecS);
  114. cout << endl;
  115. }
  116.  
  117. void vypis_studentov(TStudent **st, int poc)
  118. {
  119. for (int i = 0; i < poc; i++)
  120. {
  121. vypis_studenta(st[i]);
  122. }
  123. }
  124.  
  125.  
  126. int main()
  127. {
  128. TStudent** studenti = new TStudent*[100];
  129. char pohlavie;
  130. int rodneM, pocet;
  131. string meno, priezvisko, znamka, znamka_vvv;
  132.  
  133. int hladany_rok;
  134.  
  135.  
  136. ifstream vstup;
  137. vstup.open("studenti.txt");
  138.  
  139.  
  140. for (pocet=0; vstup >> meno >> priezvisko >> znamka >> rodneM; pocet++)
  141. {
  142. studenti[pocet] = new TStudent();
  143. studenti[pocet]->meno = meno;
  144. studenti[pocet]->priez = priezvisko;
  145. studenti[pocet]->znamka = znamka;
  146. studenti[pocet]->rodnecS = rodneM;
  147. }
  148.  
  149. cout << " neusporiadany zoznam " << pocet << " studentov zo suboru 'studenti.txt'" << endl;
  150. vypis_studentov(studenti, pocet);
  151. cout << endl;
  152.  
  153. InsertionSort(studenti, pocet);
  154. cout << "USPORIADANY zozn. " << pocet << " studentov zo sub 'studenti.txt' funkciou 'insertionSort'" << endl;
  155. vypis_studentov(studenti, pocet);
  156. cout << endl;
  157.  
  158. cout << "---------------------------------------------------" << endl;
  159. cout << "vlozte rok narodenia hladanych studentov:";
  160. cin >> hladany_rok;
  161.  
  162.  
  163.  
  164. if (hladany_rok >= 1912 && hladany_rok <= 2011)
  165. {
  166. cout << "vlozte znamku, ktoru maju mat hladani studenti: ";
  167. cin >> znamka_vvv;
  168. cout << endl;
  169. TStudent** najdeni = new TStudent*[pocet];
  170.  
  171. int Najdeny_p = 0;
  172. for (int i = 0; i < pocet; i++)
  173. {
  174. if (rok(studenti[i]->rodnecS) == hladany_rok && studenti[i]->znamka == znamka_vvv)
  175. {
  176. najdeni[Najdeny_p] = studenti[i]; Najdeny_p++;
  177. }
  178. }
  179.  
  180. cout << "narodenie '";
  181. cout << hladany_rok;
  182. cout << "' so znamkou '";
  183. cout << znamka_vvv;
  184. cout << " ";
  185. cout << Najdeny_p;
  186. cout << endl;
  187. vypis_studentov(najdeni, Najdeny_p);
  188. }
  189.  
  190.  
  191. for (int i = 0; i <pocet; i++)
  192. delete studenti[i];
  193. delete[] studenti;
  194.  
  195. return 0;
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement