Created
March 1, 2017 13:00
-
-
Save sebassdc/0b53bbcbc0690ccc4c1446b069ff4a65 to your computer and use it in GitHub Desktop.
Resuelto en clase (propio) 01/03/2017
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Guia 10 | |
El Consejo Nacional Electoral, organismo encargado de realizar los procesos | |
electorales a nivel nacional, requiere conocer cierta informacion estadistica | |
del mes de mayo, respecto al numero de inscritos. | |
Dicho organismo desea cuantificar: | |
-> El numero de personas inscritas en el mes | |
-> El numero de personas inscritas cada una de las semanas del mes. | |
-> Y por ultimo desea determinar cual de los dias de inscripcion resulta mas | |
efectivo, es decir, reporta mayor cantidad de inscritos | |
-> Los datos suministrados son: | |
LUNES MARTES MIERCOLES JUEVES VIERNES | |
1 2000 4000 3000 2500 5000 | |
2 2000 3000 2000 2500 4500 | |
3 1200 5000 3200 4000 3000 | |
4 3000 2500 7000 2000 2550 | |
El algoritmo debe trabajar tanto con estos datos como con otros. | |
*/ | |
#include <iostream> | |
#include <windows.h> | |
#define P(x) cout << #x << ": " << (x) << endl | |
using namespace std; | |
// Helper function para sumar array | |
int sum_arr(int arr[],int size){ | |
int acum = 0; | |
for (int i = 0; i < size; i++) { | |
acum += arr[i]; | |
} | |
return acum; | |
} | |
int mayor(int arr[], int size) { | |
int max = arr[0]; | |
for (int i = 1; i < size; i++) { | |
if(arr[i] > max) max = arr[i]; | |
} | |
return max; | |
} | |
int mayor_index(int arr[], int size) { | |
int i; | |
int max = 0; | |
for (i = 1; i < size; i++) { | |
if(arr[i] > arr[max]) max = i; | |
} | |
return max; | |
} | |
main(){ | |
// Declaracion de una matriz predeterminada | |
int n_f = 4, n_c = 5, i, j; | |
int default_data[4][5] = { | |
{2000, 4000, 3000, 2500, 5000}, | |
{2000, 3000, 2000, 2500, 4500}, | |
{1200, 5000, 3200, 4000, 3000}, | |
{3000, 2500, 7000, 2000, 2550} | |
}; | |
// Declaracion de un vector predeterminado | |
string dia[5] = {"LUNES", "MARTE", "MIERC", "JUEVES", "VIERNE"}; | |
// Imprimir matriz | |
cout << "{\n"; | |
for (i = 0; i < n_f; i++) { | |
cout << "\t"; | |
cout << "{"; | |
for (j = 0; j < n_c; j++) { | |
cout << default_data[i][j]; | |
if (j < n_c - 1) cout << ", "; | |
} | |
cout << "}"; | |
if (i < n_c - 1) cout << ", "; | |
cout << "\n"; | |
} | |
cout << "}\n"; | |
// Numero de personas inscritas en el mes | |
// int acum = 0; | |
// for (i = 0; i < n_f; i++) { | |
// for (j = 0; j < n_c; j++) { | |
// acum += default_data[i][j]; | |
// } | |
// } | |
int acum = 0; | |
for (i = 0; i < n_f; i++) { | |
acum += sum_arr(default_data[i], n_c); | |
} | |
cout << "La suma total es: " << acum << endl; | |
// El numero de personas inscritas cada una de las semanas del mes | |
for (i = 0; i < n_f; ++i) { | |
cout << "En la semana " << i+1 << " se inscibieron:" << endl; | |
cout << sum_arr(default_data[i], n_c) << " estudiantes" << endl; | |
} | |
// cual de los dias de inscripcion resulta mas efectivo | |
int sum_days[n_c]; | |
acum = 0; | |
for (i = 0; i < n_c; ++i) { | |
for (j = 0; j < n_f; ++j) { | |
acum += default_data[j][i]; | |
} | |
sum_days[i] = acum; | |
acum = 0; | |
} | |
int index_of_efective_day = mayor_index(sum_days, n_c); | |
cout << index_of_efective_day << endl; | |
cout << "El dia mas efectivo es el " << dia[index_of_efective_day]; | |
cout << " con: " << sum_days[index_of_efective_day] << " estudiantes" << endl; | |
system("PAUSE"); | |
}//main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment