Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <conio.h>
  6.  
  7. using namespace std;
  8. FILE* f1;
  9. typedef struct
  10. {
  11. char imya[30];
  12. char familia[30];
  13. char otchestvo[30];
  14. char gorod[30];
  15. int ball;
  16.  
  17. } Tabitur;
  18.  
  19. Tabitur abitur[30];
  20. char name[20];
  21. int nst = 0;
  22. int menu();
  23. void nnf();
  24. void newf();
  25. void spisok();
  26. void opf();
  27. void resc();
  28. void resf();
  29.  
  30. int main()
  31. {
  32. while (true)
  33. {
  34. switch (menu())
  35. {
  36. case 1:nnf(); break;
  37. case 2:newf(); break;
  38. case 3:spisok(); break;
  39. case 4:opf(); break;
  40. case 5:resc(); break;
  41. case 6:resf(); break;
  42. case 7:bubble(); break;
  43. case 8:quicksort(); break;
  44. case 9:return 0;
  45. default:"Vibrano ne pravilno !";
  46. }
  47. puts("Press any key to continue");
  48. getch(); system("cls");
  49. }
  50. }
  51. int menu()
  52. {
  53. cout << "Viberite:" << endl;
  54. cout << "1.Vvod file name" << endl;
  55. cout << "2.New file" << endl;
  56. cout << "3.Vvesti spisok" << endl;
  57. cout << "4.Open file" << endl;
  58. cout << "5.Vivesti result" << endl;
  59. cout << "6.Vivesti v file" << endl;
  60. cout << "7.Exit" << endl;
  61. int i;
  62. cin >> i;
  63. return i;
  64. }
  65. void nnf()
  66. {
  67. cout << "Vvedite file name" << endl;
  68. cin >> name;
  69. }
  70. void newf()
  71. {
  72. if ((f1 = fopen(name, "wb")) == NULL)
  73. {
  74. cout << "Oshibka pri sozdanii" << endl;
  75. exit(1);
  76. }
  77. cout << "OK" << endl;
  78. fclose(f1);
  79. }
  80. void spisok()
  81. {
  82. if ((f1 = fopen(name, "rb+")) == NULL)
  83. {
  84. cout << "Oshibka pri sozdanii" << endl;
  85. exit(1);
  86. }
  87. cout << "Vvedite chislo abiturientov" << endl;
  88. cin >> nst;
  89. for (int i = 0; i < nst; i++)
  90. {
  91. cout << "Vvedite imya:";
  92. cin >> abitur[i].imya;
  93. cout << "Vvedite familiu:";
  94. cin >> abitur[i].familia;
  95. cout << "Vvedite otchestvo:";
  96. cin >> abitur[i].otchestvo;
  97. cout << "Vvedite gorod projivania:";
  98. cin >> abitur[i].gorod;
  99. cout << "Vvedite prohodnoi ball:";
  100. cin >> abitur[i].ball;
  101. fwrite(&abitur[i], sizeof(Tabitur), 1, f1);
  102. }
  103. fclose(f1);
  104. }
  105. void opf()
  106. {
  107. if ((f1 = fopen(name, "rb")) == NULL)
  108. {
  109. cout << "Oshibka pri otkritii" << endl;
  110. exit(1);
  111. }
  112. nst = 0; Tabitur std;
  113. while (true)
  114. {
  115. int nwrt = fread(&std, sizeof(Tabitur), 1, f1);
  116. if (nwrt != 1) break;
  117. abitur[nst] = std;
  118. cout << abitur[nst].imya << "" << abitur[nst].familia << "" << abitur[nst].otchestvo << "" << abitur[nst].gorod << "" << abitur[nst].ball << endl;
  119. nst++;
  120. }
  121. fclose(f1);
  122. }
  123. void resc()
  124. {
  125. int i;
  126. for (i = 0; i < nst; i++)
  127. if (abitur[i].ball > 220 && strcmp(abitur[i].gorod, "Minsk") == 0)
  128. cout << abitur[i].imya << "" << abitur[i].familia << "" << abitur[i].otchestvo << "" << abitur[i].gorod << "" << abitur[i].ball << endl;
  129. }
  130. void resf()
  131. {
  132. char namet[30];
  133. FILE* f1;
  134. cout << "Vvedite imya file" << endl;
  135. cin >> namet;
  136. if ((f1 = fopen(namet, "w")) == NULL)
  137. {
  138. cout << "Oshibka pri sozdanii" << endl;
  139. exit(1);
  140. }
  141. char s[80];
  142. for (int i = 0; i < nst; i++)
  143. if (abitur[i].ball > 220 && strcmp(abitur[i].gorod, "Minsk") == 0)
  144. {
  145. strcpy(s, abitur[i].imya);
  146. strcat(s, "");
  147. fputs(s, f1);
  148. strcpy(s, abitur[i].familia);
  149. strcat(s, "");
  150. fputs(s, f1);
  151. strcpy(s, abitur[i].otchestvo);
  152. strcat(s, "");
  153. fputs(s, f1);
  154. strcpy(s, abitur[i].gorod);
  155. strcat(s, "");
  156. fputs(s, f1);
  157. }
  158. fclose(f1);
  159. }
  160.  
  161. void bubble(int abitur[], int n)
  162. {
  163. int i, j, t;
  164. for (i=1; i<n; i++)
  165. {
  166. for(j=n-1; j=>i;j--)
  167. {
  168. if(a[j-1]>a[j])
  169. {
  170. t=a[j-1];
  171. a[j-1]=a[j];
  172. a[j]=t;
  173. }
  174. }
  175. }
  176. }
  177.  
  178. void quciksort(int abitur[], int n)
  179. {
  180. int imin, i, j, t;
  181. for (i=1; i<n; i++)
  182. {
  183. int imin=i;
  184. for (j=i+1; j<n; j++)
  185. {
  186. if(a[imin]>a[j])
  187. {
  188. imin=j;
  189. }
  190. if(imin != i)
  191. {
  192. t=a[imin];
  193. a[imin]=a[i];
  194. a[i]=t;
  195. }
  196. }
  197. }
  198.  
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement