Lab 4






















#include <iostream>
using namespace std;
// DECLARACIONES DE VARIABLES Y FUNCIONES PUBLICO
int may, men;
const int n=2, m=2;
int i, j, SUMA, prom;
int Matriz[n][m], A[n][m], B[n][m];
int LeerMatriz();
int SumaElementos();
int ImprimeElementos();
int ElementosCentrales();
int LeoMatrizA();
int LeoMatrizB();
int SumaMatrices();
float PromedioMatriz();
int CuantosElementos();
int MatrizTramapuesta();

int main()
{
 // 1) DECLARACION
 int Opcion;
 do
 {
  cout<<"*************** MENU MATRIZ ********************** \n\n";
  cout<<" ............... 1) LEER ELEMENTOS DE LA MATRIZ \n";
  cout<<" .............. .2) SUMAR \n";
  cout<<" .............. .3) IMPRIMIR LOS ELEMENTOS DE LA MATRIZ \n";
  cout<<" ............... 4) MATRIZ IDENTIDAD S/N \n";     
  cout<<" ............... 5) ELEMENTOS CENTRALES \n";     
  cout<<" ............. ..6) LECTURA MATRIZ A[n][m] \n";     
  cout<<"  ...............7) LECTURA MATRIZ B[n][m] \n";       
  cout<<" ............... 8) SUMA MATRIZ A[n][m] + B[n][m] \n"; 
  cout<<" ................9) PROMEDIO DE LA MATRIZ [n][m] \n"; 
  cout<<"****************************************** \n\n";
  cout<<"          Digite <0> para Salir \n\n";
  cout<<"          ELIJA UNA OPCION: ";
  cin>>Opcion; // 2) ASIGNACION

switch (Opcion)
{
  case 1:
  {
   cout<<"******** LEER ELEMENTOS DE LA MATRIZ ****** \n";
   LeerMatriz(); //INVOCACION
   cout<<"*************************************** \n";   
  }; break;
  case 2:
  {
   cout<<"***** SUMAR LOS ELEMENTOS DE LA MATRIZ ***** \n";
   SumaElementos();
   cout<<"*************************************** \n";
  }; break;
  case 3:
  {
   cout<<"***IMPRIMIR LOS ELEMENTOS DE LA MATRIZ *** \n";
   ImprimeElementos();
  cout<<"*************************************** \n";
  }; break;
  case 4:
  {
   cout<<"*********** La matriz identiddad *** \n";
   ImprimeElementos();
   cout<<"*************************************** \n";
  }; break;

  case 5:
  {
   cout<<"********* ELEMENTOS CENTRALES *** \n";
   ElementosCentrales();
   cout<<"*************************************** \n";
  }; break;

  case 6:
  {
   cout<<"********* LECTURA DE LA MATRIZ A[n][m]****** \n";
   LeoMatrizA();
   cout<<"*************************************** \n";
  }; break;

  case 7:
  {
   cout<<"********* LECTURA DE LA MATRIZ B[n][m]****** \n";
   LeoMatrizB();
   cout<<"*************************************** \n";
  }; break;

  case 8:
  {
   cout<<"***** SUMAR LOS ELEMENTOS DE LA MATRIZ ***** \n";
   SumaMatrices();
   cout<<"*************************************** \n";
  }; break;

  case 9:
  {
   cout<<"**********PROMEDIO DE LA MATRIZ**** \n";   
   PromedioMatriz();
    cout<<"*************************************** \n";
  }; break;

  case 10:
  {
         cout<<"******ELEMENTOS MAYORES Y MENORES DEL PROMEDIO ******* \n";   
  CuantosElementos();
    cout<<"*************************************** \n";
  }; break; 
          
} // FIN DEL CASE
} while (Opcion !=0);

system ("pause");
return 0;
}

// DESARROLLO DE LAS FUNCIONES
int LeerMatriz()
{
 cout<<"Ingrese los elementos\n ";
 cout<<"---------------------\n\n ";   
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
   {
    cout<<"M["<<i<<"]["<<j<<"]= "; cin>>Matriz[i][j];
    }
}

int SumaElementos()
{
 SUMA=0;
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
  {
   SUMA = SUMA + Matriz[i][j];
  }
 cout<<"La suma de los elementos es: "<<SUMA<< endl;

}

int ImprimeElementos()
{
 cout<<"Los elementos son: \n ";
 cout<<"------------------\n\n ";   
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
  {
   cout<<"M["<<i<<"]["<<j<<"]= "<< Matriz[i][j] <<endl;
  }
}

int ElementosCentrales()
{
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
  {
   if (i==j)
   cout<<"M["<<i<<"]["<<j<<"]= "<< Matriz[i][j] <<endl;
  }
}

int LeoMatrizA()
{
 cout<<"Ingrese los elementos de la Matriz A[n][m] \n ";
 cout<<"--------------------------------------------\n\n ";   
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
   {
    cout<<"A["<<i<<"]["<<j<<"]= "; cin>>A[i][j];
    }
}

int LeoMatrizB()
{
 cout<<"Ingrese los elementos de la Matriz B[n][m] \n ";
 cout<<"--------------------------------------------\n\n ";   
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
   {
    cout<<"B["<<i<<"]["<<j<<"]= "; cin>>B[i][j];
    }
}
int SumaMatrices()
{
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
  {
   Matriz[i][j] = A[i][j] + B[i][j];
  }
}
float  PromedioMatriz()
{
   SUMA=0;
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
  {
   SUMA = SUMA + Matriz[i][j];
   prom = SUMA/(n*m);
  }
  cout<<"El promedio de los elementos es: "<<prom<< endl;
}
  int CuantosElementos()
  {
   may=0;
   men=0;
  
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
  {
  if(Matriz[i][j] > prom)
  may = may+1;

  if(Matriz[i][j] < prom)
  men = men+1;
  }
 cout<<"EXISTEN"<<may <<" MAYORES  ELEMENTO: "<< endl;   
 cout<<"EXISTEN"<<men <<" MENORES  ELEMENTO: "<< endl; 
}

No comments:

Post a Comment