Xavistian

Untitled

May 30th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. // ConsoleApplication5.cpp : main project file.
  2.  
  3. #include "stdafx.h"
  4. #include <conio.h>
  5. #include <iostream>
  6. using namespace std;
  7. using namespace System;
  8.  
  9. struct Alumno
  10. {
  11.     int edad;
  12.     char genero;
  13.     float altura;
  14. };
  15. void Leer_Alumnos(Alumno * Arreglo, int n)
  16. {
  17.     for (int i = 0; i < n; i++)
  18.     {
  19.         cout << "Ingrese la edad: ";
  20.         cin >> Arreglo[i].edad;
  21.         cout << "Ingrese el genero: ";
  22.         cin >> Arreglo[i].genero;
  23.         Arreglo[i].genero = toupper(Arreglo[i].genero);
  24.         cout << "Ingrese la altura: ";
  25.         cin >> Arreglo[i].altura;
  26.     }
  27. }
  28. void Imprimir_Alumnos(Alumno*Arreglo, int n)
  29. {
  30.     for (int i = 0; i < n; i++)
  31.     {
  32.         cout << Arreglo[i].edad << ' ' << Arreglo[i].genero << ' ' << Arreglo[i].altura << endl;
  33.     }
  34. }
  35. void Ordenar_Estatura(Alumno*Arreglo, int n)
  36. {
  37.     Alumno aux;
  38.     for (int i = 0; i < n - 1; i++)
  39.     {
  40.         for (int j = i + 1; j < n;j++)
  41.         {
  42.             if (Arreglo[i].altura < Arreglo[j].altura)
  43.             {
  44.                 aux = Arreglo[i];
  45.                 Arreglo[i] = Arreglo[j];
  46.                 Arreglo[j]= aux;
  47.             }
  48.         }
  49.     }
  50. }
  51. void Imprime_Numero_Alumnos(Alumno*Arreglo, int n)
  52. {
  53.     int CMas = 0;
  54.     for (int i = 0; i < n; i++)
  55.     {
  56.         if (Arreglo[i].genero == 'M') CMas++;
  57.     }
  58.     cout << "Hay " << CMas << " alumnos " << (char)11 << '.'<<endl;
  59. }
  60. int main()
  61. {
  62.     int n;
  63.     cout << "Ingrese el numero de alumnos: ";
  64.     cin >> n;
  65.     Alumno *ArrAlu = new Alumno[n];
  66.     Leer_Alumnos(ArrAlu, n);
  67.     Imprimir_Alumnos(ArrAlu, n);
  68.     Imprime_Numero_Alumnos(ArrAlu, n);
  69.     Ordenar_Estatura(ArrAlu, n);
  70.     Imprimir_Alumnos(ArrAlu, n);
  71.     _getch();
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment