Advertisement
Smudla

Cpp_CV1_cpp

Oct 8th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include "Matrix.h"
  2. using namespace std;
  3.  
  4. int main(int argc, char *argv[]){
  5.     srand(time(NULL));
  6.     Matrix testMatrix(5, 5);
  7.     cout << "Max vallue of matrix is: " << testMatrix.findMaxVallue() << endl;
  8.     cout << "Min vallue of matrix is: " << testMatrix.findMinVallue() << endl;
  9.     system("pause");
  10.     return 0;
  11. }
  12.  
  13. Matrix::Matrix(mySize_T rowCount=3, mySize_T colCount=3)
  14. {  
  15.     _colCount = colCount;
  16.     _rowCount = rowCount;
  17.     matrix = new mySize_T*[colCount];
  18.  
  19.     for (int i = 0; i < colCount; i++)
  20.     {
  21.         matrix[i] = new mySize_T[rowCount];
  22.     }
  23.    
  24.     for (int i = 0; i < colCount; i++){
  25.         for (int j = 0; j < rowCount; j++){
  26.             matrix[i][j] = rand() % 10000;
  27.         }
  28.     }
  29.  
  30. }
  31.  
  32. Matrix::~Matrix()
  33. {
  34. }
  35.  
  36. int  Matrix::sumUpAllValues()
  37. {
  38.     int sum = 0;
  39.     for (mySize_T i = 0; i < _rowCount; i++)
  40.     {
  41.         for (mySize_T j = 0; j < _colCount; j++)
  42.         {
  43.             sum += matrix[i][j];
  44.         }
  45.     }
  46.     return sum;
  47. }
  48.  
  49. int Matrix::findMaxVallue()
  50. {
  51.     int max = 0;
  52.     for (mySize_T i = 0; i < _rowCount; i++)
  53.     {
  54.         for (mySize_T j = 0; j < _colCount; j++)
  55.         {
  56.             if (matrix[i][j]>max)
  57.             {
  58.                 max = matrix[i][j];
  59.             }
  60.         }
  61.     }
  62.     return max;
  63. }
  64.  
  65. int Matrix::findMinVallue()
  66. {
  67.     int min = 0;
  68.     for (mySize_T i = 0; i < _rowCount; i++)
  69.     {
  70.         for (mySize_T j = 0; j < _colCount; j++)
  71.         {
  72.             if (matrix[i][j]<min)
  73.             {
  74.                 min = matrix[i][j];
  75.             }
  76.         }
  77.     }
  78.     return min;
  79. }
  80.  
  81. void Matrix::executeOverAllElements(func_t ptr)
  82. {
  83. //do smth
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement