Advertisement
Mastercpp

suma y resta Matrices POO

Mar 13th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5.  
  6. class Matrices{
  7. public:
  8.     /*int suma[50][50];
  9.     int resta[50][50];*/
  10.     void rellenar(int matriz[50][50],int filas,int columnas){
  11.         for (int i = 0; i<filas; i++){
  12.             for (int j = 0; j<columnas; j++){
  13.                 cout << "ingrese numero: ";
  14.                 cin>>matriz[i][j];
  15.             }
  16.         }
  17.     }
  18. int suma[50][50];
  19.     int resta[50][50];
  20.     void imprimir(int matriz[50][50],int filas,int columnas ){
  21.         for (int i = 0; i<filas; i++){
  22.             for (int j = 0; j<columnas; j++){
  23.                 cout << matriz[i][j] << " ";
  24.             }
  25.             cout << endl;
  26.         }
  27.     }
  28.  
  29.     void restarMatriz(int A[50][50], int B[50][50], int resta[50][50],int filas,int columnas){
  30.         for (int i = 0; i<filas; i++){
  31.             for (int j = 0; j<columnas; j++){
  32.                 resta[i][j] = A[i][j]-B[i][j];
  33.             }
  34.         }
  35.     }
  36.  
  37.     void sumarMatriz(int A[50][50], int B[50][50],int suma[50][50], int filas,int columnas){
  38.         for (int i = 0; i<filas; i++){
  39.             for (int j = 0; j<columnas; j++){
  40.                 suma[i][j] = A[i][j]+B[i][j];
  41.             }
  42.         }
  43.     }
  44. };
  45.  
  46. int main(){
  47.     Matrices * ma = new Matrices();
  48.     int A[50][50],
  49.         B[50][50],
  50.         suma[50][50],
  51.         resta[50][50];
  52.  
  53.     int fil,col;
  54.     cout << "Ingrese el numero de filas: ";
  55.     cin>>fil;
  56.     cout << "ingrese el numero de columnas: ";
  57.     cin>>col;
  58.  
  59.     cout << "Rellenando matriz A\n";
  60.     ma->rellenar(A,fil,col);
  61.     cout << "Rellenando matriz B: " << endl;
  62.     ma->rellenar(B,fil,col);
  63.  
  64.     cout << "\n\nMostrando matriz A" << endl;
  65.     ma->imprimir(A,fil,col);
  66.     cout << "\n\nMostrando Matriz B" << endl;
  67.     ma->imprimir(B,fil,col);
  68.  
  69.     cout << "Suma de La matriz A y B: " << endl;
  70.     ma->sumarMatriz(A,B,suma,fil,col);
  71.     ma->imprimir(suma,fil,col);
  72.  
  73.     cout << "\n\nResta de La matriz A y B: " << endl;
  74.     ma->restarMatriz(A,B,resta,fil,col);
  75.     ma->imprimir(resta,fil,col);
  76.     //cout <<
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement