Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. using namespace System;
  5.  
  6. struct persona
  7. {
  8.     int voto;
  9.     int d1, d2, d3, d4, d5, d6, d7, d8;
  10.     long long dnis;
  11. };
  12.  
  13. void generar(persona *arreglo, int *n)
  14. {
  15.     for (int i = 0; i < *n; i++)
  16.     {
  17.         arreglo[i].voto = 1 + rand() % 3;
  18.     }
  19. }
  20.  
  21. void dni(persona *arreglo, int *n)
  22. {
  23.     for (int i = 0; i < *n; i++)
  24.     {
  25.         arreglo[i].d1 = 1 + rand() % 9;
  26.         arreglo[i].d2 = rand() % 10;
  27.         arreglo[i].d3 = rand() % 10;
  28.         arreglo[i].d4 = rand() % 10;
  29.         arreglo[i].d5 = rand() % 10;
  30.         arreglo[i].d6 = rand() % 10;
  31.         arreglo[i].d7 = rand() % 10;
  32.         arreglo[i].d8 = rand() % 10;
  33.  
  34.         arreglo[i].dnis = (arreglo[i].d1 * 10000000 + arreglo[i].d2 * 1000000 + arreglo[i].d3 * 100000 + arreglo[i].d4 * 10000 + arreglo[i].d5 * 1000 + arreglo[i].d6 * 100 + arreglo[i].d7 * 10 + arreglo[i].d8);
  35.     }
  36.  
  37. }
  38.  
  39. void dni_menor(persona*arreglo, int *n)
  40. {
  41.     int aux;
  42.     for (int i = 0; i < *n-1; i++)
  43.     {
  44.         for (int j = i + 1; j < *n; j++)
  45.         {
  46.             if (arreglo[i].dnis>arreglo[j].dnis)
  47.             {
  48.                 aux = arreglo[i].dnis;
  49.                 arreglo[i].dnis = arreglo[j].dnis;
  50.                 arreglo[j].dnis = aux;
  51.             }
  52.         }
  53.     }
  54.     cout << "el dni de la persona mas longeva es: " << arreglo[0].dnis;
  55. }
  56.  
  57. void mostrar(persona *arreglo, int *n)
  58. {
  59.     int contA = 0, contB = 0, contC = 0;
  60.     cout << "DNI: " << endl;
  61.     for (int i = 0; i < *n; i++)
  62.     {
  63.         cout << "Persona " << i + 1 << " : " << arreglo[i].dnis << " voto.....    " << arreglo[i].voto << endl;
  64.         if (arreglo[i].voto == 1)
  65.         {
  66.             contA++;
  67.         }
  68.         if (arreglo[i].voto == 2)
  69.         {
  70.             contB++;
  71.         }
  72.         if (arreglo[i].voto == 3)
  73.         {
  74.             contC++;
  75.         }
  76.     }
  77.     cout << contA << " votaron por el candidato A" << endl;
  78.     cout << contB << " votaron por el candidato B" << endl;
  79.     cout << contC << " votaron en blanco o tuvieron voto viciado" << endl;
  80.     dni_menor(arreglo, n);
  81. }
  82.  
  83. int main()
  84. {
  85.     int *n = new int;
  86.     persona*arreglo;
  87.     do {
  88.         cout << "Ingrese la cantidad de alumnos: ";     cin >> *n;
  89.     } while (*n < 1 || *n>100);
  90.     arreglo = new persona[*n];
  91.  
  92.     generar(arreglo, n);
  93.     dni(arreglo, n);
  94.     mostrar(arreglo, n);
  95.  
  96.     cout << endl;
  97.     system("pause");
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement