Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication6.cpp : main project file.
- #include "stdafx.h"
- #include <conio.h>
- #include <iostream>
- using namespace std;
- using namespace System;
- struct Alumnos
- {
- char gripe;
- char tos;
- float peso;
- };
- void GenerayLista_Paralelos(Alumnos *a, int n)
- {
- int g, t;
- Random x;
- for (int i = 0; i < n; i++)
- {
- g = x.Next(0, 2);
- if (g == 0) a[i].gripe = 'S'; else a[i].gripe = 'N';
- t = x.Next(0, 2);
- if (t == 0) a[i].tos = 'S'; else a[i].tos = 'N';
- a[i].peso = x.Next(30, 61) + x.Next(0, 100)*0.01;
- cout << "Alumno " << i + 1 << endl << "Gripe: " << a[i].gripe << endl << "Tos: " << a[i].tos << endl << "Peso: " << a[i].peso << endl << endl;
- }
- }
- void Porcentaje_gripe_tos(Alumnos *a, int n)
- {
- float PGyT;
- int cpgyt = 0;
- for (int i = 0; i < n; i++)
- {
- if (a[i].gripe == 'S'&&a[i].tos == 'S') cpgyt++;
- }
- PGyT = cpgyt*100.0 / n;
- cout << "Porcentaje de almunos(as) que tienen gripe y tos: " << PGyT << "%." << endl;
- }
- void Promedio_pesos(Alumnos *a, int n)
- {
- float suma=0;
- float cenf = 0;
- float pesoprom;
- for (int i = 0; i < n; i++)
- {
- if (a[i].gripe == 'S' || a[i].tos == 'S')
- {
- suma += a[i].peso; cenf++;
- }
- }
- pesoprom = suma*1.0 / cenf;
- cout << "Promedio de pesos de los alumnos con alguna enfermedad: " << pesoprom << " kg." << endl;
- }
- void Listado_ordenado(Alumnos *a, int n)
- {
- Alumnos aux;
- cout << "Peso \t" << "Gripe \t" << "Tos \t"<<endl<<"-------------------------"<<endl;
- float aux1, aux2, aux3;
- for (int i = 0; i < n-1; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- if (a[i].peso < a[j].peso)
- {
- aux = a[i];
- a[i]= a[j];
- a[j]= aux;
- }
- }
- }
- for (int i = 0; i < n; i++)
- {
- cout << a[i].peso << "\t" << a[i].gripe << "\t" << a[i].tos << "\t" << endl;
- }
- }
- int main()
- {
- Console::WindowHeight = 50;
- int n;
- Alumnos *a = new Alumnos[n];
- do {
- cout << "Ingrese el numero de alumnos: " << endl;
- cin >> n;
- } while (n < 1 || n>20);
- cout << endl;
- GenerayLista_Paralelos(a, n);
- Porcentaje_gripe_tos(a, n);
- cout << endl;
- Promedio_pesos(a, n);
- cout << endl;
- Listado_ordenado(a, n);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment