LABORATORIO NÚMERO 3

ORDENAMIENTO


#include<iostream>
#include<math.h>
using namespace std;

const int m=3, n=2, z=20;
int i, j, sumatoria, Busca, YY, XX, R, ZZ, Elementos, AUX;

int M[n][m];
int V[z];

void LeerMatriz();
void EscribirMatriz();
void Buscar(int YY);
int SumarElementos();
void LeerVector(int XX);
void EscribirVector(int XX);
void OrdenaVector(int XX);



int main ()
{
 int opcion;
 do
 {      //INICIO DEL DO - WHILE
  cout<<"********* MENU DE UNA MATRIZ **********\n\n";
  cout<<" 1) LECTURA DE LA MATRIZ p * q \n";
  cout<<" 2) ESCRITURA DE LA MATRIZ p * q\n";
  cout<<" 3) ENCONTRAR EL ELEMENTO \n";  
  cout<<" 4) SUMAR ELEMENTOS EN LA MATRIZ p * q \n";
  cout<<" 5) LECTURA DE UN VECTOR[z] \n";
  cout<<" 6) ESCRITURA DE UN VECTOR[z] \n";
  cout<<" 7) ORDENAR EL VECTOR[z] \n";
  cout<<"       DIGITE <0> PARA SALIR \n";
  cout<<"       Elija una Opcion < > \n\n";
  cout<<"*************************************\n\n";
  cout<<"   ELIJA UNA OPCION : "; cin>>opcion;
    //2)ASIGNACION
    switch (opcion)
    { //INICIO DEL CASO 1
    case 1:
     {// CONTENIDO 1 (INICO)
       cout<<"******* LECTURA DE LA MATRIZ ******\n\n";
       LeerMatriz();
       cout<<"************************************\n\n";
    } //FIN DEL CASO 1
     break;    
  case 2:
     {//INICIO DEL CASO 2
       cout<<"******* ESCRITURA DE LA MATRIZ ******\n\n";
       EscribirMatriz();
       cout<<"*********************************\n\n";
     } //FIN DEL CASO 2
    break;

  case 3:
     {//INICIO DEL CASO 3
       cout<<"******* ENCONTRAR UN ELEMENTO DE LA MATRIZ ******\n\n";
       cout<<"Ingrese el e-nesimo elemento a Buscar: "; cin>> Busca;    
       Buscar(Busca);
       cout<<"*********************************\n\n";
     } //FIN DEL CASO 2
    break;

  case 4:
     {//INICIO DEL CASO 4
       cout<<"******* SUMAR ELEMENTOS EN LA MATRIZ ******\n\n";
       R = SumarElementos();
       cout<<"LA SUMA DE LOS ELEMENTOS DE LA MATRIZ ES:"<< R<< endl;
       cout<<"\n******************************************\n\n";
     } //FIN DEL CASO 2
    break;

   case 5:
     {//INICIO DEL CASO 5
      cout<<"******* LECTURA DE UN VECTOR[z] ******\n\n";
      cout<<"Ingrese el número de elementos del V[z]"; cin>>Elementos;
      LeerVector(Elementos);
      cout<<"\n******************************************\n\n";
     } //FIN DEL CASO 2
    break;
 
   case 6:
     {//INICIO DEL CASO 6
      cout<<"*******   ESCRITURA DE UN VECTOR[z] ******\n\n";
      EscribirVector(Elementos);
      cout<<"\n******************************************\n\n";
     } //FIN DEL CASO 2
    break;

   case 7:
     {//INICIO DEL CASO 7
      cout<<"******* ORDENAR EL VECTOR[z] ******\n\n";
      OrdenaVector(Elementos);
      cout<<"\n******************************************\n\n";
     } //FIN DEL CASO 2
    break;




   }// FIN DE SWITCH
 }while (opcion !=0); // FIN DEL DO - WHILE

  cout<<endl;cout<<"\n";
  system("pause");
  return 0;
} //FIN DEL PROGRAMA

// ZONA DE DESARROLLO DE FUNCIONES

void LeerMatriz()
{
  cout<<endl;
  cout<<"LECTURA DE LA MATRIZ M "<<endl;
  for(i=1; i<=n; i++)
    for(j=1; j<=m; j++)
     {
     cout<<"ingrese valor del elemento M["<<i<<"]["<<j<<"] = "; cin>>M[i][j];
     }    
  cout<<endl;
}

void EscribirMatriz()
{
  cout<<endl;
  cout<<"ESCRITURA DE LA MATRIZ M "<<endl;
  for(i=1; i<=n; i++)
    for(j=1; j<=m; j++)
     {
     cout<<"El elemento M["<<i<<"]["<<j<<"] = "<<M[i][j]<<endl;
     }    
  cout<<endl;
}

void Buscar(int YY)
{
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)  
   {
     if (M[i][j]==YY)      
     cout<<" Encontrmos al elemento M["<<i<<"]["<<j<<"] = "<<M[i][j] <<endl;
   }    
} // FIN DE BUSCAR

int SumarElementos()
{
 sumatoria = 0;
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
   {
    sumatoria = sumatoria + M[i][j];
   }
   return sumatoria;
} // FIN DE SUMAR

void LeerVector(int XX)
{
 cout<<endl;
 cout<<"LECTURA DEL VECTOR V[z] "<<endl<<endl;
  for(i=1; i<=XX; i++)
   {
   cout<<"Ingrese valor del elemento V["<<i<<"] = "; cin>>V[i];
   }    
 cout<<endl;
}

void EscribirVector(int XX)
{
 cout<<endl;
 cout<<"ESCRITURA DEL VECTOR V[z] "<<endl<<endl;
  for(i=1; i<=XX; i++)
   {
   cout<<"Elemento V["<<i<<"] = "<< V[i]<< endl;
   }    
 cout<<endl;
} // FIN DEL ESCRIBIR

void OrdenaVector(int XX)
{

 for(i=1; i<=XX; i++)
  for(j=1; j<=XX-1; j++)
   {
    if(V[j] > V[j+1])
     {
       AUX = V[j];
       V[j] = V[j+1];
       V[j+1] = AUX;
     }
   }
   EscribirVector(XX);
} // FIN DE ORDENA

void Vectorizando(int ZZ)
{
 int k;  
 k=1;  
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
   {
     V[k]=M[i][j];
     k++;
   }
}

void Matriceando(int ZZ)
{
 int k;  
 k=1;  
 for(i=1; i<=n; i++)
  for(j=1; j<=m; j++)
   {
    M[i][j] = V[k];
     k++;
   }
}



No hay comentarios:

Publicar un comentario