Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- using namespace System;
- struct persona
- {
- int voto;
- int d1, d2, d3, d4, d5, d6, d7, d8;
- long long dnis;
- };
- void generar(persona *arreglo, int *n)
- {
- for (int i = 0; i < *n; i++)
- {
- arreglo[i].voto = 1 + rand() % 3;
- }
- }
- void dni(persona *arreglo, int *n)
- {
- for (int i = 0; i < *n; i++)
- {
- arreglo[i].d1 = 1 + rand() % 9;
- arreglo[i].d2 = rand() % 10;
- arreglo[i].d3 = rand() % 10;
- arreglo[i].d4 = rand() % 10;
- arreglo[i].d5 = rand() % 10;
- arreglo[i].d6 = rand() % 10;
- arreglo[i].d7 = rand() % 10;
- arreglo[i].d8 = rand() % 10;
- 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);
- }
- }
- void dni_menor(persona*arreglo, int *n)
- {
- int aux;
- for (int i = 0; i < *n-1; i++)
- {
- for (int j = i + 1; j < *n; j++)
- {
- if (arreglo[i].dnis>arreglo[j].dnis)
- {
- aux = arreglo[i].dnis;
- arreglo[i].dnis = arreglo[j].dnis;
- arreglo[j].dnis = aux;
- }
- }
- }
- cout << "el dni de la persona mas longeva es: " << arreglo[0].dnis;
- }
- void mostrar(persona *arreglo, int *n)
- {
- int contA = 0, contB = 0, contC = 0;
- cout << "DNI: " << endl;
- for (int i = 0; i < *n; i++)
- {
- cout << "Persona " << i + 1 << " : " << arreglo[i].dnis << " voto..... " << arreglo[i].voto << endl;
- if (arreglo[i].voto == 1)
- {
- contA++;
- }
- if (arreglo[i].voto == 2)
- {
- contB++;
- }
- if (arreglo[i].voto == 3)
- {
- contC++;
- }
- }
- cout << contA << " votaron por el candidato A" << endl;
- cout << contB << " votaron por el candidato B" << endl;
- cout << contC << " votaron en blanco o tuvieron voto viciado" << endl;
- dni_menor(arreglo, n);
- }
- int main()
- {
- int *n = new int;
- persona*arreglo;
- do {
- cout << "Ingrese la cantidad de alumnos: "; cin >> *n;
- } while (*n < 1 || *n>100);
- arreglo = new persona[*n];
- generar(arreglo, n);
- dni(arreglo, n);
- mostrar(arreglo, n);
- cout << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement