Advertisement
Jopa322

Untitled

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