Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. using namespace std;
  7. struct students {
  8. string ime;
  9. string nomer;
  10. float srusp;
  11. int vuzrast;
  12. int pol;
  13. }per[30],M[30],F[30],temp[30],tempj[30];
  14. int broi;
  15. const int N = 30;
  16. int p;
  17. void create(struct students per[]);
  18. void sort(struct students per[],struct students M[],struct students F[]);
  19. void mladi(struct students per[],struct students F[], struct students temp[], struct students tempj[]);
  20. fstream fp;
  21. void main()
  22. {
  23. setlocale(LC_ALL, "bulgarian");
  24. struct students per[N];
  25. int menu;
  26. do{
  27. cout <<endl<<"1.Запис на студенти" << endl;
  28. cout << "2.Справка за мъже и жени!" << endl;
  29. cout << "3.Най-млада студентка и подреждане на данните във възходящ ред по възраст!" << endl;
  30. cout << "4.Изход!" << endl;
  31. cout << "Избери:" << endl;
  32. cin >> menu;
  33.  
  34. switch (menu)
  35. {
  36. case 1:create(per); break;
  37. case 2:sort(per,M,F); break;
  38. case 3:mladi(per, F, temp, tempj); break;
  39. }
  40. } while (menu != 4);
  41. system("pause");
  42. }
  43. void create(struct students per[])
  44. {
  45. fp.open("file.txt", ios::out);
  46. cout << endl << "Въведете брой студенти(0-30)!" << endl;
  47. do{
  48. cin >> broi;
  49. } while (broi < 1 || broi>30);
  50.  
  51. for (int i = 0; i < broi; i++)
  52. {
  53. cout << "Въведете данни за студент " << i + 1 << endl;
  54. cout << "Име:" << endl;
  55. getline(cin >> ws, per[i].ime);
  56. fp << "Име: " << per[i].ime << endl;
  57. cout << "Факултетен номер: " << endl;
  58. cin >> per[i].nomer;
  59. fp << "Факултетен номер: " << per[i].nomer << endl;
  60. do
  61. {
  62.  
  63. cout << "Среден успех(2-6): " << endl;
  64. cin >> per[i].srusp;
  65. } while (per[i].srusp > 6 || per[i].srusp < 2);
  66. fp << "Среден успех: " << per[i].srusp << endl;
  67. cout << "Възраст: " << endl;
  68. cin >> per[i].vuzrast;
  69. fp << "Възраст: " << per[i].vuzrast << endl;
  70. cout << "Въведете пол(1-мъж/0-жена): " << endl;
  71. cin >> per[i].pol;
  72. fp << "Пол(1-muj/0-jena): " << per[i].pol << endl;
  73. }
  74.  
  75. for (int i = 0; i < broi; i++)
  76. {
  77. cout << endl << "Име: " << per[i].ime;
  78. cout << endl << "Факултетен номер: " << per[i].nomer;
  79. cout << endl << "Среден успех: " << per[i].srusp;
  80. cout << endl << "Възраст: " << per[i].vuzrast;
  81. if (per[i].pol == 1)
  82. {
  83. cout << endl << "Пол: Мъж" << endl;
  84. }
  85. else
  86. {
  87. cout << endl << "Пол: Жена" << endl;
  88. }
  89. }
  90. fp.close();
  91. }
  92.  
  93. void sort(struct students per[],struct students M[],struct students F[])
  94. {
  95. int br = 0;
  96. int num = 0;
  97. float sr = 0;
  98. float srj = 0;
  99.  
  100. for (int i = 0; i < broi; i++)
  101. {
  102. if (per[i].pol == 1)
  103. {
  104. M[br] = per[i]; br++;
  105. }
  106. else
  107. {
  108. F[num] = per[i]; num++;
  109. }
  110. }
  111. cout << "Мъже: " << endl << endl;
  112.  
  113.  
  114. for (int i = 0; i < br; i++)
  115. {
  116. cout << "Име: " << M[i].ime << endl;
  117. cout << "Факултетен номер: " << M[i].nomer << endl;
  118. cout << "Среден успех: " << M[i].srusp << endl;
  119. cout << "Възраст: " << M[i].vuzrast << endl;
  120. cout << "Пол: Мъж " << endl << endl;
  121. sr += M[i].vuzrast;
  122. }
  123. cout << "Средна възраст на мъжете: " << sr / br << endl<<endl;
  124. cout << "Жени: " << endl;
  125. cout << "Брой на жените: " << num << endl;
  126. for (int i = 0; i < num; i++)
  127. {
  128. cout << "Име:" << F[i].ime << endl;
  129. cout << "Факултетен номер: " << F[i].nomer << endl;
  130. cout << "Среден успех: " << F[i].srusp << endl;
  131. cout << "Възраст: " << F[i].vuzrast << endl;
  132. cout << "Пол: Жена" << endl<<endl;
  133. srj += F[i].vuzrast;
  134. }
  135. cout << "Средна възраст на жените е: " << srj / num << endl;
  136. fp.close();
  137. }
  138. void mladi(struct students per[],struct students F[],struct students temp[], struct students tempj[])
  139. {
  140. int i;
  141. int x=0;
  142. int j;
  143. for (int i = 0; i < broi-1; i++)
  144. for (j = i + 1; j < broi;j++)
  145. if (per[i].vuzrast>per[j].vuzrast)
  146. {
  147. temp[x] = per[i];
  148. per[i] = per[j];
  149. per[j] = temp[x];
  150. }
  151. for (i = 0; i < p - 1; i++)
  152. for (j = i + 1; j < p;j++)
  153. if (F[i].vuzrast>F[j].vuzrast)
  154. {
  155. tempj[x] = F[i];
  156. F[i] = F[j];
  157. F[j] = tempj[x];
  158. }
  159. cout << "Най-млада студентка: " << endl;
  160. cout << "Име: " << F[0].ime << endl;
  161. cout << "Факултетен номер: " << F[0].nomer << endl;
  162. cout << "Среден успех: " << F[0].srusp << endl;
  163. cout << "Възраст: " << F[0].vuzrast << endl;
  164. cout << "Пол: Жена" << endl;
  165. cout <<endl<< "Възходящ ред по години:" << endl;
  166. for (int i = 0; i<broi; i++)
  167. {
  168. cout << "Име: " << per[i].ime << endl;
  169. cout << "Факултетен номер: " << per[i].nomer << endl;
  170. cout << "Среден успех: " << per[i].srusp << endl;
  171. cout << "Възраст: " << per[i].vuzrast << endl;
  172. if (per[i].pol == 1)
  173. {
  174. cout << "Пол: Мъж" << endl;
  175. }
  176. else
  177. {
  178. cout << "Пол: Жена" << endl<<endl;
  179. }
  180. }
  181.  
  182.  
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement