Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. /*Sviluppare una suite per la manipolazione di matrici e vettori.
  2. In particolare sviluppare un programma chiamante che richiami le funzioni:
  3. - prodotto scalare
  4. - prodotto matrice per vettore
  5. - prodotto matrice per matrice
  6. - trasposto di una matrice
  7. con documentazione esterna e interna.
  8. */
  9.  
  10. #include <iostream>
  11.  
  12. using namespace std;
  13.  
  14. int **crea_matrice(int m, int n);
  15. void carica_matrice(int **matrice, int m, int n);
  16. void stampa_matrice( int **matrice, int m, int n);
  17. void dealloca_matrice(int **matrice, int m, int n);
  18.  
  19.  
  20. int main()
  21. {
  22.     int m=0, n=0;
  23.     int **matrice;
  24.  
  25.  
  26.     cout<<"Inserire il numero di righe della matrice: ";
  27.     cin>>m;
  28.     cout<<"Inserire il numero di colonne della matrice: ";
  29.     cin>>n;
  30.  
  31.     matrice= crea_matrice(m, n);
  32.     carica_matrice(matrice, m, n);
  33.     stampa_matrice(matrice, m, n);
  34.     dealloca_matrice(matrice, m, n);
  35.  
  36.     cout<<endl<<matrice[2][2]<<endl;
  37.  
  38.     return 0;
  39. }
  40.  
  41. int **crea_matrice(int m, int n)
  42. {
  43.     int **matrice;
  44.  
  45.     matrice = new int*[m];
  46.     for(int i=0;i<m; i++)
  47.         matrice[i] = new int[n];
  48.  
  49.     return matrice;
  50. }
  51.  
  52. void carica_matrice(int **matrice, int m, int n)
  53. {
  54.     for(int i=0;i<m;i++)
  55.     {
  56.         for(int j=0; j<n; j++)
  57.         {
  58.             cout<<"Inserire elemento ["<<i<<";"<<j<<"]: ";
  59.             cin>>matrice[i][j];
  60.         }
  61.     }
  62. }
  63.  
  64. void stampa_matrice( int **matrice, int m, int n)
  65. {
  66.     for(int i=0;i<m;i++)
  67.     {
  68.         cout<<endl;
  69.         for(int j=0;j<n;j++)
  70.         {
  71.             cout<<matrice[i][j]<<" - ";
  72.         }
  73.     }
  74. }
  75.  
  76. void dealloca_matrice(int **matrice, int m, int n)
  77. {
  78.     for(int i=0;i<m;i++)
  79.         delete matrice[i];
  80.     delete *matrice;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement