Beruflich Dokumente
Kultur Dokumente
#include<vector>
#include<algorithm>
using std::cout;
using std::cin;
unsigned mode_t;
std::vector<double> v =
{
35.0,
19.0,
18.0,
13.0,
13.0,
30.0,
25.0,
22.0,
27.0,
7.0,
9.0,
17.0,
17.0,
9.0,
19.0,
21.0,
10.0,
25.0,
11.0,
13.0,
35.0,
18.0,
13.0,
17.0,
9.0,
17.0,
22.0,
7.0,
11.0,
9.0
};
//Moda Aritmética
void mode(const std::vector<double>& v)
{
for(const double& n : v)
cout << n << " -> " << count(v.cbegin(), v.cend(), n) << '\n';
}
//Ordenar
void sort(std::vector<double>& v)
{
for (std::size_t a = 0; a < v.size(); ++a)
{
for (std::size_t b = a+1; b < v.size(); ++b)
{
if (v[b] < v[a])
std::swap(v[a], v[b]);
}
}
}
//Frecuencia de Intervalos
void range_frec(std::vector<double>& v, unsigned int begin, unsigned int end,
unsigned int stride)
{
std::size_t count = 0;
while (begin < end)
{
for (const double& n : v)
{
if (n >= begin && n <= begin+stride) ++count;
}
cout << count << " Elementos en rango " << begin << " --- " << begin +
stride << '\n';
begin += stride+1; count = 0;
}
}
int main()
{
cout << "Introduce Inicio, Fin e Incremento del Intervalo:" << '\n';
unsigned int inicio, fin, inc;
cin >> inicio >> fin >> inc;
cout << "X: 1\n";
cout << "Intervalo: 2\n";
cout << " ";
cin >> mode_t;
if (mode_t == 2){
cout << "\n\nIntervalo:\n";
}
//MODO INTERVALO
if (mode_t == 2)
{
std::vector<double> r;
double n;
do
{
cin >> n;
if (n != -1)
r.push_back(n);
}
while (n != -1);
while (r.size())
{
n = ((r[0] + r[1])/2);
cout << n << '\n';
v.push_back(n);
r.erase(r.begin(),r.begin()+2);
}
}
//MODO X
/*if (mode_t == 1)
{
double n;
do
{
cin >> n;
if (n != -1)
v.push_back(n);
}
while (n != -1);
}*/
MA = sum/data_q;
cout << "Media (PROMEDIO) = " << MA << '\n' << "{";
cout << '\n';
cout << "Suma de valores:\n";
sum = 0;
for (const double& n : v)
cout << (sum += n) << '\n';
//MEDIANA
sort(v);
if (v.size()%2 == 0)// Par
cout << "\n\n\nMediana (Dato X Central) = " << (v[(v.size()/2)-1] +
v[v.size()/2])/2 << '\n';
else// Impar
cout << "\n\n\nMediana (Dato X Central) = " << v[(v.size()-1)/2] <<
'\n';
//MODA
cout << "\n\n\nModa" << '\n';
mode(v);
}