Created
April 30, 2015 03:57
-
-
Save samir96/89edc6be9cc2936097dd to your computer and use it in GitHub Desktop.
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
#include <iostream> | |
#include <cstdlib> | |
#include <string> | |
#include <fstream> | |
#include <cmath> | |
#include <vector> | |
using namespace std; | |
float desviacion( vector<int> v, int tam, int suma){ | |
float desviacion; | |
int i; | |
float Suma_dif =0.0; | |
float prom = promedio(suma, tam); | |
for (i=0; i < tam;i++ ){ | |
Suma_dif += ((v[i] -prom) *(v[i] - prom)); | |
} | |
desviacion = sqrt(Suma_dif/tam); | |
return desviacion; | |
} | |
float promedio(float sum, int lines){ | |
float promedio; | |
promedio=sum/(lines); | |
return promedio; | |
} | |
void readNumbers(string namefile){ | |
ifstream file (namefile); | |
string line; | |
vector<int> number; | |
int line_number=0, suma =0; | |
if (file.is_open()){ | |
while (getline(file, line)){ | |
int x = atoi(line.c_str()); | |
number.push_back(x); | |
suma += number [line_number]; | |
line_number++; | |
} | |
} | |
cout << "The total of the values is "<< suma << endl; | |
cout << "La suma total es: "<< line_number << endl; | |
cout << "El promedio es: "<< promedio(suma,line_number) << endl; | |
cout << "La desviacion estandar es " << desviacion(number, line_number, suma) << endl; | |
} | |
int main(){ | |
readNumbers("random_numbers.txt"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment