Guest User

Untitled

a guest
Jan 15th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. #include "Matrice.h"
  2. #include <time.h>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. Matrice::Matrice(int _NbLignes, int _NbColonnes)
  7. {
  8.      int i;
  9.      int j;
  10.      srand (time(NULL));
  11.      NbLignes = _NbLignes;
  12.      NbColonnes = _NbColonnes;
  13.      Tableau = new int*[NbLignes];
  14.      if(!(Tableau == NULL))
  15.      {
  16.         for(i = 0; i < NbLignes; i++)
  17.         {
  18.             Tableau[i] = new int[NbColonnes];
  19.             if(!(Tableau[i] == NULL))
  20.             {
  21.                 for(j = 0; j < NbColonnes; j++)
  22.                 {
  23.                     Tableau[i][j] = rand() % 100 + 1;
  24.                 }
  25.             }
  26.         }
  27.      }
  28. }
  29.  
  30. Matrice::Matrice(void)
  31. {
  32. }
  33.  
  34.  
  35. Matrice::~Matrice(void)
  36. {
  37.      int i;
  38.      int j;
  39.      for(i = 0; i < NbLignes; i++)
  40.      {
  41.         delete[] Tableau[i];
  42.      }
  43.      delete[] Tableau;
  44. }
  45.  
  46.  
  47. bool Matrice::Null()
  48. {
  49.     for(int i = 0; i < NbLignes; i++)
  50.     {
  51.         for(int j = 0; j < NbColonnes; j++)
  52.         {
  53.             if (Tableau[i][j]!=0) return false;
  54.         }
  55.     }
  56.     return true;
  57. }
  58.  
  59. void Matrice::Afficher()
  60. {
  61.     for(int i = 0; i < NbLignes; i++)
  62.     {
  63.             for(int j = 0; j < NbColonnes; j++)
  64.             {
  65.                     printf("%d\t",Tableau[i][j]);
  66.             }  
  67.             printf("\n");
  68.     }
  69. }
  70.  
  71. bool Matrice::TriangulaireSup()
  72. {
  73.     return BasNull();
  74. }
  75.  
  76. bool Matrice::TriangulaireSrict()
  77. {
  78.     return (!Null && DiagoNul() && BasNull()); 
  79. }
  80.  
  81. bool Matrice::DiagoNul()
  82. {
  83.     for (int i = 0; i<NbLignes; i++)
  84.     {
  85.         if (Tableau [i][i] != 0) return false;
  86.     }
  87.     return true;
  88. }
  89.  
  90.  
  91. bool Matrice::Scalaire()
  92. {
  93.     int nb = Tableau[0][0];
  94.     for (int i = 0; i<NbLignes; i++)
  95.     {  
  96.         if (Tableau [i][i] != nb && HautNull() && BasNull()) return false;
  97.     }
  98.     return true;
  99. }
  100.  
  101. bool Matrice::BasNull()
  102. {
  103.     int k = 1 ;
  104.     for (int j = 0; j<NbColonnes; j++)
  105.     {
  106.         for (int i = k; i<NbLignes; i++)
  107.         {
  108.             if (Tableau [i][j] != 0) return false;
  109.         }
  110.         k++;
  111.     }
  112. }
  113.  
  114. bool Matrice::HautNull()
  115. {
  116.     int k = 0 ;
  117.     for (int j = 1; j<NbColonnes; j++)
  118.     {
  119.         for (int i = 0; i<k+1; i++)
  120.         {
  121.             if (Tableau [i][j] != 0) return false;
  122.         }
  123.         k++;
  124.     }
  125. }
  126.  
  127. bool Matrice::Diagonale()
  128. {
  129.     return (!DiagoNul() && HautNull() && BasNull());
  130. }
  131.  
  132. bool Matrice::Unite()
  133. {
  134.     for (int i = 0; i<NbLignes; i++)
  135.     {
  136.         if (Tableau [i][i] != 1) return false;
  137.     }
  138.     return true;
  139. }
  140.  
  141. bool Matrice::Symetrique()
  142. {
  143.     int i = 1;
  144.     int j = 0;
  145.     do
  146.     {
  147.         for(i; i < NbLignes; i++)
  148.         {
  149.             if(Tableau[i][j] != Tableau[j][i])return false;
  150.    
  151.         }
  152.         j++;
  153.         i = j;
  154.     }
  155.     while(j < NbLignes);
  156.     return true;
  157. }
Add Comment
Please, Sign In to add comment