DilyaraL

Семестровая

Apr 2nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <iomanip>
  5. #include <cstring>
  6. #include <string>
  7. #include < math.h >
  8. using namespace std;
  9.  
  10. struct date
  11. {
  12. char day[3];
  13. char mon[3];
  14. char year[5];
  15. };
  16.  
  17. struct place
  18. {
  19. char city[30];
  20. char street[30];
  21. int house;
  22. int flat;
  23. int nomber;
  24. };
  25.  
  26. struct list
  27. {
  28. char fam[30];
  29. char name[30];
  30. char ot[30];
  31. date birth;
  32. char edu;
  33. char marst;
  34. int child;
  35. char job;
  36. place adress;
  37. };
  38.  
  39.  
  40. void show(ifstream&f1)
  41. {
  42. list a;
  43. while (f1.peek() != EOF)
  44. {
  45. f1.read((char*)&a, sizeof(list));
  46. cout << a.fam <<' '<< a.name << ' ' << a.ot << ' ' << a.birth.day << ' ' << a.birth.mon << ' ' << a.birth.year<< ' ' << a.edu << ' ' << a.marst << ' '<<a.child<<' ' << a.job << ' ' << a.adress.city << ' ' << a.adress.street << ' ' << a.adress.house << ' ' << a.adress.flat << ' ' << a.adress.nomber<<endl;
  47. }
  48. }
  49.  
  50. int* creat_array(int n)
  51. {
  52. int *a = new int[n];
  53. for (int i = 0; i < n; i++)
  54. a[i] = 0;
  55. return a;
  56. }
  57.  
  58. void MAX(ifstream&in1, int*max, int n)
  59. {
  60. list a;
  61. char b[9];
  62. while (in1.peek() != EOF)
  63. {
  64. in1 >> a.fam >> a.name >> a.ot >> b >> a.edu >> a.marst >> a.child >> a.job >> a.adress.city >> a.adress.street >> a.adress.house >> a.adress.flat >> a.adress.nomber;
  65.  
  66. if (a.job == 'A')
  67. {
  68. if (max[0] < a.child)
  69. max[0] = a.child;
  70. }
  71. else
  72. {
  73. if (a.job == 'B')
  74. {
  75. if (max[1] < a.child)
  76. max[1] = a.child;
  77. }
  78. else
  79. {
  80. if (a.job == 'C')
  81. {
  82. if (max[2] < a.child)
  83. max[2] = a.child;
  84. }
  85. else
  86. {
  87. if (a.job == 'D')
  88. {
  89. if (max[3] < a.child)
  90. max[3] = a.child;
  91. }
  92. else
  93. {
  94. if (a.job == 'E')
  95. {
  96. if (max[4] < a.child)
  97. max[4] = a.child;
  98. }
  99. else
  100. {
  101. if (a.job == 'F')
  102. if (max[5] < a.child)
  103. max[5] = a.child;
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. in1.close();
  111. }
  112.  
  113. void writebin(ifstream&in1,ofstream&outbin, int *max,int n)
  114. {
  115. list a;
  116. char b[9];
  117.  
  118. while (in1.peek() != EOF)
  119. {
  120. in1 >> a.fam >> a.name >> a.ot >> b >> a.edu >> a.marst >> a.child >> a.job >> a.adress.city >> a.adress.street >> a.adress.house >> a.adress.flat >> a.adress.nomber;
  121. a.birth.day[0] = b[0];
  122. a.birth.day[1] = b[1];
  123. a.birth.day[2] = '\0';
  124. a.birth.mon[0] = b[2];
  125. a.birth.mon[1] = b[3];
  126. a.birth.mon[2] = '\0';
  127. a.birth.year[0] = b[4];
  128. a.birth.year[1] = b[5];
  129. a.birth.year[2] = b[6];
  130. a.birth.year[3] = b[7];
  131. a.birth.year[4] = '\0';
  132.  
  133. if (a.job == 'A'&&max[0] == a.child)
  134. outbin.write((char*)&a, sizeof(list));
  135. else
  136. {
  137. if (a.job == 'B'&&max[1] == a.child)
  138. outbin.write((char*)&a, sizeof(list));
  139. else
  140. {
  141. if (a.job == 'C'&&max[2] == a.child)
  142. outbin.write((char*)&a, sizeof(list));
  143. else
  144. {
  145. if (a.job == 'D'&&max[3] == a.child)
  146. outbin.write((char*)&a, sizeof(list));
  147. else
  148. {
  149. if (a.job == 'E'&&max[4] == a.child)
  150. outbin.write((char*)&a, sizeof(list));
  151. else
  152. {
  153. if (a.job == 'F'&&max[5] == a.child)
  154. outbin.write((char*)&a, sizeof(list));
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. in1.close();
  162. outbin.close();
  163. }
  164.  
  165. void count( ifstream&inbin, int *k, int n)
  166. {
  167. list a;
  168. while (inbin.peek() != EOF)
  169. {
  170. inbin.read((char*)&a, sizeof(list));
  171.  
  172. if (a.job == 'A')
  173. k[0]++;
  174. else
  175. {
  176. if (a.job == 'B')
  177. k[1]++;
  178. else
  179. {
  180. if (a.job == 'C')
  181. k[2]++;
  182. else
  183. {
  184. if (a.job == 'D')
  185. k[3]++;
  186. else
  187. {
  188. if (a.job == 'E')
  189. k[4]++;
  190. else
  191. {
  192. if (a.job == 'F')
  193. k[5]++;
  194. }
  195. }
  196. }
  197. }
  198. }
  199. }
  200. inbin.close();
  201. }
  202.  
  203. void show_tabl(int* k, int n)
  204. {
  205. int Max = 0;
  206. for (int i = 0; i < 6; i++)
  207. if (Max < k[i])
  208. Max = k[i];
  209. double perc;
  210. for (int i = 0; i < 6; i++)
  211. {
  212. switch (i)
  213. {
  214. case 0: cout << 'A' << ' ';
  215. break;
  216. case 1: cout << 'B' << ' ';
  217. break;
  218. case 2: cout << 'C' << ' ';
  219. break;
  220. case 3: cout << 'D' << ' ';
  221. break;
  222. case 4: cout << 'E' << ' ';
  223. break;
  224. case 5: cout << 'F' << ' ';
  225. break;
  226. }
  227. perc = 10.0*k[i] / Max;
  228. perc = round(perc);
  229. for (int i = 0; i < perc; i++)
  230. cout << '*' << ' ';
  231. cout << endl;
  232.  
  233. }
  234. }
  235.  
  236. int main()
  237. {
  238. setlocale(LC_ALL, "Russian");
  239. ifstream in1("Text.txt");
  240. ofstream outbin("Abit.bin", ios::binary);
  241.  
  242. list a;
  243. char b[9];
  244. int n = 6;
  245.  
  246. int *max = creat_array(n);
  247.  
  248. MAX(in1, max, n);
  249.  
  250. in1.open("Text.txt");
  251.  
  252. writebin(in1, outbin, max, n);
  253.  
  254. int *k = creat_array(n);
  255.  
  256. ifstream inbin("Abit.bin", ios::binary);
  257.  
  258. count(inbin, k, n);
  259.  
  260. show_tabl(k, n);
  261.  
  262. system("pause");
  263. return 0;
  264. }
Advertisement
Add Comment
Please, Sign In to add comment