Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "iostream"
- #include "time.h"
- using namespace std;
- struct Bank
- {
- char name[15];
- int inc[4];
- };
- class TBank
- {
- private:
- Bank * mass;//
- int n;
- public:
- TBank(int);
- ~TBank();
- void input();
- void output();
- int Max(int Bank);
- int Sum(int Bank);
- void rnd();
- };
- TBank::TBank(int N)
- {
- n = N;
- mass = new Bank[n];
- }
- TBank::~TBank()
- {
- delete[]mass;
- }
- 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++)
- {
- cout << "Введите название банка:" << endl;
- cin >> mass[i].name;
- 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);
- 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;
- cout << "Введите количество банков в городе:" << endl;
- cin >> k;
- TBank a(k);
- cout << "1-random , 0 нет" << endl;
- cin >> x;
- if (x == 1)a.rnd();
- else a.input();
- a.output();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement