Advertisement
Guest User

struct

a guest
Nov 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct algo
  6. {
  7.     string apellido;
  8.     char sexo;
  9.     int edad;
  10.  
  11. }personas[5];
  12.  
  13. int main()
  14. {
  15.     int aux;
  16.     string auxS;
  17.     char auxChar;
  18.  
  19.     for ( int i = 0 ; i< 5 ; i++)
  20.     {
  21.         cin >> personas[i].apellido;
  22.  
  23.         cin >> personas[i].sexo;
  24.  
  25.         cin >> personas[i].edad;
  26.     }
  27.  
  28.     for ( int i = 0 ; i < 5 ; i++)
  29.     {
  30.         if (personas[i].edad >= 20 && personas[i].edad <= 40)
  31.         {
  32.             cout << "EDAD: " << personas[i].edad <<endl << "APELLIDO: " << personas[i].apellido <<endl << "SEXO: " << personas[i].sexo <<endl;
  33.         }
  34.     }
  35.  
  36.     for ( int i = 4 ; i >= 0 ; i--)
  37.     {
  38.         for ( int j = 0 ; j < i ; j++)
  39.         {
  40.             if ( personas[j].edad > personas[j + 1].edad)
  41.             {
  42.                 aux = personas[j].edad;
  43.                 personas[j].edad = personas[j + 1].edad;
  44.                 personas[j + 1].edad = aux;
  45.                 auxChar = personas[j].sexo;
  46.                 personas[j].sexo = personas[j + 1].sexo;
  47.                 personas[j + 1].sexo = auxChar;
  48.                 auxS = personas[j].apellido;
  49.                 personas[j].apellido = personas[j + 1].apellido;
  50.                 personas[j + 1].apellido = auxS;
  51.             }
  52.         }
  53.     }
  54.  
  55.     for ( int i = 0 ; i < 5 ; i++)
  56.     {
  57.         cout << personas[i].edad <<endl;
  58.  
  59.         cout << personas[i].sexo <<endl;
  60.  
  61.         cout << personas[i].apellido <<endl;
  62.     }
  63.  
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement