Xavistian

Ejercicio examen final

Jun 15th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. // ConsoleApplication6.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 Alumnos
  10. {
  11.     char gripe;
  12.     char tos;
  13.     float peso;
  14. };
  15. void GenerayLista_Paralelos(Alumnos *a, int n)
  16. {
  17.     int g, t;
  18.     Random x;
  19.     for (int i = 0; i < n; i++)
  20.     {
  21.         g = x.Next(0, 2);
  22.         if (g == 0) a[i].gripe = 'S'; else a[i].gripe = 'N';
  23.         t = x.Next(0, 2);
  24.         if (t == 0) a[i].tos = 'S'; else a[i].tos = 'N';
  25.         a[i].peso = x.Next(30, 61) + x.Next(0, 100)*0.01;
  26.         cout << "Alumno " << i + 1 << endl << "Gripe: " << a[i].gripe << endl << "Tos: " << a[i].tos << endl << "Peso: " << a[i].peso << endl << endl;
  27.     }
  28. }
  29. void Porcentaje_gripe_tos(Alumnos *a, int n)
  30. {
  31.     float PGyT;
  32.     int cpgyt = 0;
  33.     for (int i = 0; i < n; i++)
  34.         {
  35.         if (a[i].gripe == 'S'&&a[i].tos == 'S') cpgyt++;
  36.         }
  37.     PGyT = cpgyt*100.0 / n;
  38.     cout << "Porcentaje de almunos(as) que tienen gripe y tos: " << PGyT << "%." << endl;
  39. }
  40. void Promedio_pesos(Alumnos *a, int n)
  41. {
  42.     float suma=0;
  43.     float cenf = 0;
  44.     float pesoprom;
  45.     for (int i = 0; i < n; i++)
  46.     {
  47.         if (a[i].gripe == 'S' || a[i].tos == 'S')
  48.         {
  49.             suma += a[i].peso; cenf++;
  50.         }
  51.     }
  52.     pesoprom = suma*1.0 / cenf;
  53.     cout << "Promedio de pesos de los alumnos con alguna enfermedad: " << pesoprom << " kg." << endl;
  54. }
  55. void Listado_ordenado(Alumnos *a, int n)
  56. {
  57.     Alumnos aux;
  58.     cout << "Peso \t" << "Gripe \t" << "Tos \t"<<endl<<"-------------------------"<<endl;
  59.     float aux1, aux2, aux3;
  60.     for (int i = 0; i < n-1; i++)
  61.     {
  62.         for (int j = i + 1; j < n; j++)
  63.         {
  64.             if (a[i].peso < a[j].peso)
  65.             {
  66.                 aux = a[i];
  67.                 a[i]= a[j];
  68.                 a[j]= aux;
  69.             }
  70.         }
  71.     }
  72.     for (int i = 0; i < n; i++)
  73.     {
  74.         cout << a[i].peso << "\t" << a[i].gripe << "\t" << a[i].tos << "\t" << endl;
  75.     }
  76. }
  77. int main()
  78. {
  79.     Console::WindowHeight = 50;
  80.     int n;
  81.     Alumnos *a = new Alumnos[n];
  82.     do {
  83.         cout << "Ingrese el numero de alumnos: " << endl;
  84.         cin >> n;
  85.     } while (n < 1 || n>20);
  86.     cout << endl;
  87.     GenerayLista_Paralelos(a, n);
  88.     Porcentaje_gripe_tos(a, n);
  89.     cout << endl;
  90.     Promedio_pesos(a, n);
  91.     cout << endl;
  92.     Listado_ordenado(a, n);
  93.     _getch();
  94.     return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment