Advertisement
Jopa322

Untitled

Oct 23rd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #include "iostream"
  4. #include "time.h"
  5. #include <string>
  6. using namespace std;
  7.  
  8. const int autismos = 5;
  9. const string Names[5] = {
  10. "Aest1",
  11. "Best2",
  12. "Cest3",
  13. "Dest4",
  14. "Fest5",
  15. };
  16.  
  17. struct Bank
  18. {
  19. string name;
  20. int inc[4];
  21. };
  22. class TBank
  23. {
  24. private:
  25. Bank * mass;//
  26. int n;
  27.  
  28. public:
  29.  
  30. TBank(int nn=5);
  31.  
  32. ~TBank();
  33.  
  34. void input();
  35. void output();
  36. int Max(int Bank);
  37. int Sum(int Bank);
  38. void rnd();
  39. void sort(int POLE, int pr);
  40. };
  41.  
  42. TBank::TBank(int nn)
  43.  
  44. {
  45. n = nn;
  46. mass = new Bank[n];
  47. }
  48.  
  49. TBank::~TBank()
  50. {
  51. delete[]mass;
  52. }
  53.  
  54.  
  55. void TBank::sort(int POLE,int pr)
  56. {
  57. Bank x;
  58. int i, j, b;
  59. for (i = 0; i < n - 1; i++)
  60. {
  61. for (j = i + 1; j < n; j++)
  62. {
  63. switch (POLE)
  64. {
  65.  
  66. case 1:
  67. b = strcmp(mass[i].name.c_str(), mass[j].name.c_str()) > 0;
  68. break;
  69. case 2: case 3: case 4: case 5:
  70. b = mass[i].inc[POLE - 2] > mass[j].inc[POLE - 2];
  71. break;
  72. case 6:
  73. b = Max(i) > Max(j);
  74. break;
  75. case 7:
  76. b = Sum(i) > Sum(j);
  77. break;
  78.  
  79. }
  80. if (pr) b = !b;
  81. if (b)
  82. {
  83. x = mass[i];
  84. mass[i] = mass[j];
  85. mass[j] = x;
  86. }
  87. }
  88. }
  89. }
  90. void TBank::input()
  91. {
  92. for (int i = 0; i < n; i++)
  93. {
  94. cout << "Введите название банка:" << endl;
  95. cin >> mass[i].name;
  96. for (int j = 0; j < 4; j++)
  97. {
  98. cout << "Введите денежные поступления за квартал " << j + 1 << endl;
  99. cin >> mass[i].inc[j];
  100. }
  101. }
  102. }
  103.  
  104. void TBank::rnd()
  105. {
  106.  
  107. for (int i = 0; i < n; i++)
  108. {
  109. mass[i].name = Names[rand() % autismos];
  110. for (int j = 0; j < 4; j++)
  111. {
  112. mass[i].inc[j] = rand() % 1000 + 1;
  113. }
  114. }
  115. }
  116.  
  117. int TBank::Max(int Bank)
  118. {
  119. int max = 0;
  120. for (int j = 0; j < 4; j++)
  121. {
  122. if (mass[Bank].inc[j] > max)
  123. {
  124. max = mass[Bank].inc[j];
  125. }
  126. }
  127. return max;
  128. }
  129.  
  130. int TBank::Sum(int Bank)
  131. {
  132. int sum = 0;
  133. for (int j = 0; j < 4; j++)
  134. {
  135. sum += mass[Bank].inc[j];
  136. }
  137. return sum;
  138. }
  139.  
  140. void TBank::output()
  141. {
  142. printf("%-12s", "Банк");
  143. printf("%-12s", "1й квартал");
  144. printf("%-12s", "2й квартал");
  145. printf("%-12s", "3й квартал");
  146. printf("%-12s", "4й квартал");
  147. printf("%-12s", "Максимум");
  148. printf("%-12s", "Сумма");
  149. printf("\n");
  150.  
  151. for (int i = 0; i < n; i++)
  152. {
  153. printf("%-12s", mass[i].name.c_str());
  154. printf("%-12d", mass[i].inc[0]);
  155. printf("%-12d", mass[i].inc[1]);
  156. printf("%-12d", mass[i].inc[2]);
  157. printf("%-12d", mass[i].inc[3]);
  158. printf("%-12d", Max(i));
  159. printf("%-12d", Sum(i));
  160. cout << endl;
  161. }
  162. }
  163.  
  164. int main()
  165. {
  166. srand(time(0));
  167. setlocale(LC_ALL, "RUS");
  168. int x;
  169. int k;
  170. int qq, wqwqw;
  171. cout << "Введите количество банков в городе:" << endl;
  172. cin >> k;
  173.  
  174. TBank a(k);
  175. cout << "1-random , 0 нет" << endl;
  176. cin >> x;
  177. if (x == 1)a.rnd();
  178. else a.input();
  179. a.output();
  180. cout << "Введите номер по жопе 1 2 3 4 5 6 7" << endl;
  181. cin >> qq;
  182. cin >> wqwqw;
  183. a.sort(qq, wqwqw);
  184. a.output();
  185. system("pause");
  186. return 0;
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement