Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "iostream"
- #include "time.h"
- #include <string>
- using namespace std;
- const int autismos = 5;
- const string Names[5] = {
- "Aest1",
- "Best2",
- "Cest3",
- "Dest4",
- "Fest5",
- };
- struct Bank
- {
- string name;
- int inc[4];
- };
- class TBank
- {
- private:
- Bank * mass;//
- int n;
- public:
- TBank(int nn=5);
- ~TBank();
- void input();
- void output();
- int Max(int Bank);
- int Sum(int Bank);
- void rnd();
- void sort(int POLE, int pr);
- };
- TBank::TBank(int nn)
- {
- n = nn;
- mass = new Bank[n];
- }
- TBank::~TBank()
- {
- delete[]mass;
- }
- void TBank::sort(int POLE,int pr)
- {
- Bank x;
- int i, j, b;
- for (i = 0; i < n - 1; i++)
- {
- for (j = i + 1; j < n; j++)
- {
- switch (POLE)
- {
- case 1:
- b = strcmp(mass[i].name.c_str(), mass[j].name.c_str()) > 0;
- break;
- case 2: case 3: case 4: case 5:
- b = mass[i].inc[POLE - 2] > mass[j].inc[POLE - 2];
- break;
- case 6:
- b = Max(i) > Max(j);
- break;
- case 7:
- b = Sum(i) > Sum(j);
- break;
- }
- if (pr) b = !b;
- if (b)
- {
- x = mass[i];
- mass[i] = mass[j];
- mass[j] = x;
- }
- }
- }
- }
- void TBank::input()
- {
- for (int i = 0; i < n; i++)
- {
- cout << "Введите название банка:" << endl;
- cin >> mass[i].name;
- for (int j = 0; j < 4; j++)
- {
- cout << "Введите денежные поступления за квартал " << j + 1 << endl;
- cin >> mass[i].inc[j];
- }
- }
- }
- void TBank::rnd()
- {
- for (int i = 0; i < n; i++)
- {
- mass[i].name = Names[rand() % autismos];
- for (int j = 0; j < 4; j++)
- {
- mass[i].inc[j] = rand() % 1000 + 1;
- }
- }
- }
- int TBank::Max(int Bank)
- {
- int max = 0;
- for (int j = 0; j < 4; j++)
- {
- if (mass[Bank].inc[j] > max)
- {
- max = mass[Bank].inc[j];
- }
- }
- return max;
- }
- int TBank::Sum(int Bank)
- {
- int sum = 0;
- for (int j = 0; j < 4; j++)
- {
- sum += mass[Bank].inc[j];
- }
- return sum;
- }
- void TBank::output()
- {
- printf("%-12s", "Банк");
- printf("%-12s", "1й квартал");
- printf("%-12s", "2й квартал");
- printf("%-12s", "3й квартал");
- printf("%-12s", "4й квартал");
- printf("%-12s", "Максимум");
- printf("%-12s", "Сумма");
- printf("\n");
- for (int i = 0; i < n; i++)
- {
- printf("%-12s", mass[i].name.c_str());
- printf("%-12d", mass[i].inc[0]);
- printf("%-12d", mass[i].inc[1]);
- printf("%-12d", mass[i].inc[2]);
- printf("%-12d", mass[i].inc[3]);
- printf("%-12d", Max(i));
- printf("%-12d", Sum(i));
- cout << endl;
- }
- }
- int main()
- {
- srand(time(0));
- setlocale(LC_ALL, "RUS");
- int x;
- int k;
- int qq, wqwqw;
- cout << "Введите количество банков в городе:" << endl;
- cin >> k;
- TBank a(k);
- cout << "1-random , 0 нет" << endl;
- cin >> x;
- if (x == 1)a.rnd();
- else a.input();
- a.output();
- cout << "Введите номер по жопе 1 2 3 4 5 6 7" << endl;
- cin >> qq;
- cin >> wqwqw;
- a.sort(qq, wqwqw);
- a.output();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement