Plot using c++

Hello everyone, I need your help. I want to plot results of my program. It calculates the Gauss Bell and the normal distribution. I tried with a lot of external libraries but I can't yet. I'm using Code::Blocks.
Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>

#define pi 3.14159265359
#define exponencial 2.71828182846

using namespace std;

int main()
{
    ofstream MyExcelFile;
	MyExcelFile.open("D:\\datos.csv");
	MyExcelFile << "DESVIACION ESTANDAR Y DISTRIBUCION NORMAL" << endl;
	MyExcelFile << "Num. Personas, Datos Est., Promedio, Desv. Estandar, Dist. Normal" << endl;

	int  personas = 0;
	int nDatos = 0;
	cout << "Ingrese la cantidad de personas: ";
	cin >> personas;
	cout << "Ingrese la cantidad de datos por persona a ingresar: ";
	cin >> nDatos;

	//Declaracion de variables
	float suma=0, promedio, desvia;
	pair <float, float> *people; people = new pair<float,float> [personas];
	vector<float> valores; valores.resize(personas);

	//Ingreso datos
	for(int i = 0; i < personas; i++)
	{
		cout << "Ingrese el(los) dato(s) de la persona " << i+1 << ": \n";
		float datos=0;
		for(int j=0; j<nDatos; j++)
		{
			cout << "Ingrese el dato " << j+1 << ": ";
			float aux;
			cin >> aux;
			datos = datos + aux;
		}
		float datoFinal = (datos / nDatos);
		valores[i] = datoFinal;
	}

	//Calculo de promedio
	for(int i=0; i<personas; i++)
	{
		suma = suma + valores[i];
	}
	promedio = suma / personas;
	cout << "\nMedia: " << promedio << "\n";

	//Calculo de desviacion estandar
	float sumaV = 0;
	for(int i=0; i<personas; i++)
	{
		float resta = valores[i] - promedio;
		float cuad = pow(resta, 2);
		sumaV = sumaV + cuad;
	}
	desvia = (sqrtf((sumaV)/(personas-1)));
	cout << "\nDesviacion: " << desvia << "\n\n";

	//calculo de distribucion normal
	cout << "\nDistribucion Normal: " << "\n\n";
	float parteA, parteB;
	vector<float> distN;
	distN.resize(personas);
	parteA = ((1)/(desvia*(sqrtf(2* pi))));
	int cont=0;
	for(int i=0; i<personas; i++)
	{
		parteB = pow(exponencial,(-((pow(((valores[i])-(promedio)),2))/(2*pow((desvia),2)))));
		distN[i] = parteA * parteB;
		people[i] = make_pair(valores[i], distN[i]);
		cout << "Valor:" << people[i].first << "\t" << "Dist. Normal: " << people[i].second << "\n";
		if(cont==0)
		{
			MyExcelFile << personas << "," << people[i].first << "," << promedio << "," << desvia << "," << people[i].second << endl;
			cont++;
		}
		else
			MyExcelFile <<"," << people[i].first << ",,," << people[i].second << endl;
	}
	//Ordenar
	sort(people, people + personas);
	cout << "\nCampana de Gauss: " << "\n\n";

	//Impresion de resultados
	for (int i=0; i<personas; ++i)
	{
		cout << int(people[i].first) << " - " << (int(people[i].first)+1) << "| ";
		cout << string(people[i].second*100,'*') << endl;
	}

	//Graficos

	//Fin de programa
	MyExcelFile.close();
	cin.get();
	cin.get();
	return 0;
}

Last edited on
Topic archived. No new replies allowed.