Created
June 2, 2016 05:56
-
-
Save RicardoLara/6ea0602096ff0c0bdedf98de88e8af50 to your computer and use it in GitHub Desktop.
Para Crispin
This file contains hidden or 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
| #include <bits/stdc++.h> | |
| using namespace std; | |
| FILE *fp; | |
| struct datos{ | |
| float media,varianza; | |
| }; | |
| int stoi (const string &str) { | |
| stringstream ss(str); | |
| int num; | |
| if((ss >> num).fail()){ /*ERROR*/ } | |
| return num; | |
| } | |
| int t_file(){ | |
| int n = 0; | |
| char buff[255]; | |
| fp = fopen("BD_Vivienda.txt", "r"); | |
| fscanf(fp, "%s", buff); n++; | |
| while(fgets(buff, 255, (FILE*)fp) != NULL) n++; | |
| return --n; | |
| } | |
| int valN(int n){ | |
| char buff[255]; | |
| fp = fopen("BD_Vivienda.txt", "r"); | |
| fscanf(fp, "%s", buff); | |
| if(n == 1) return stoi(buff); | |
| while(n--) fgets(buff, 255, (FILE*)fp); | |
| return stoi(buff); | |
| } | |
| int main(){ | |
| int n_rep, t_muestra; | |
| cout << "Num de Repeticiones pls -> "; cin >> n_rep; | |
| cout << "Num de Datos de las Muestras pls ->"; cin >> t_muestra; | |
| datos data[n_rep]; | |
| int f_len = t_file(); | |
| for(int i=0; i<n_rep; i++){ | |
| cout << endl << "-----------------" << endl; | |
| cout << "MUESTRA [" << i+1 << "]" << endl; | |
| cout << "-----------------" << endl; | |
| float varnz[t_muestra]; | |
| float prom = 0.0; | |
| for(int j=0; j<t_muestra; j++){ | |
| int r = rand() % f_len + 1; | |
| cout << "Dato en " << r << " es: " << valN(r) << endl; | |
| varnz[j] = valN(r); prom += varnz[j]; | |
| } | |
| data[i].media = prom/(float)t_muestra; | |
| float varfin = 0.0; | |
| for(int j=0; j<t_muestra; j++) | |
| varfin += pow(2,(varnz[j] - data[i].media)); | |
| data[i].varianza = varfin/(float)t_muestra; | |
| } | |
| cout << endl << "Datos:" << endl; | |
| for(int i=0; i<n_rep; i++){ | |
| cout << "Media de Muestra (" << i+1 << "): " << data[i].media << endl; | |
| cout << "Varianza de Muestra (" << i+1 << "): " << data[i].varianza << endl; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment