Advertisement
liza271099l

Untitled

Jun 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.82 KB | None | 0 0
  1. #pragma once
  2. #ifndef _ARRANGE_
  3. #define _ARRANGE_
  4. #include <iostream>
  5. #include <iomanip>
  6. using namespace std;
  7. template <typename T>
  8. class Arrange
  9. {
  10. private:
  11.     T * * ar;
  12.     int m;
  13.     int n;
  14.     T max;
  15.     T k;
  16. public:
  17.     Arrange();
  18.     void input();
  19.     void compare1();
  20.     void compare2();
  21.     ~Arrange();
  22. };
  23. #endif
  24. #include "Arrange.h"
  25. #include <iostream>
  26. #include <iomanip>
  27. using namespace std;
  28. template<typename T>
  29. Arrange::Arrange()
  30. {
  31.     m = 0;
  32.     n = 0;
  33.     T** ar = new T*[m];
  34.     for (int i = 0; i < m; i++)
  35.     {
  36.         ar[i] = new T[n];
  37.     }
  38.     max = 0;
  39.     k = 0;
  40. }
  41. template<typename T>
  42. void Arrange::input()
  43. {
  44.     cout << "vvedite kolichestvo strok" << endl;
  45.     cin >> m;
  46.     cout << "vvedite kolichestvo stolbcov" << endl;
  47.     cin >> n;
  48.     for (int i = 0; i < m; i++)
  49.     {
  50.         for (int j = 0; j < n; j++)
  51.         {
  52.             ar[i][j] = rand();
  53.  
  54.         }
  55.     }
  56.    
  57. }
  58. template<typename T>
  59. void Arrange::compare1()
  60. {
  61.     int ia = 0;
  62.     int ja = 0;
  63.     max = ar[1][0];
  64.     for (int i =1; i < m; i++)
  65.     {
  66.         for (int j = 0; j < n; j++)
  67.         {
  68.             if (i>=j)
  69.             {
  70.                 if (ar[i][j] > max)
  71.                 {
  72.                     max = ar[i][j];
  73.                     ia = i;
  74.                     ja = j;
  75.                 }
  76.                 else
  77.                 {
  78.                     max = ar[i + 1][j + 1];
  79.                     ia = i + 1;
  80.                     ja = j + 1;
  81.                 }
  82.  
  83.             }
  84.         }
  85.     }
  86.     cout << "max element" << max << "   " << "index" << ia << ";" << ja << endl;
  87. }
  88. template <typename T>
  89. void Arrange::compare2()
  90. {
  91.     int t = 1;
  92.     for (int j = 0; j < m; j++)
  93.     {
  94.         for (int i = 0; i < n;)
  95.         {
  96.             k = (k + ar[i][j]) / t;
  97.            
  98.             if (k[i] > k[i + 1])
  99.             {
  100.                 max = max + ar[i][j];
  101.             }
  102.             t++;
  103.             i++;
  104.  
  105.         }
  106.     }
  107.     cout << "max summ" << max << endl;
  108. }
  109. template <typename T>
  110. Arrange::~Arrange()
  111. {
  112. }
  113. #include <iostream>
  114. #include <iomanip>
  115. #include "Arrange.h"
  116. using namespace std;
  117. int main()
  118. {
  119.     Arrange<int> obg;
  120.     obg.input();
  121.     obg.compare1();
  122.     obg.compare2();
  123.     system("pause");
  124.     return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement