Advertisement
Jopa322

Untitled

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