include iostream include math using namespace std struct Var int xi in

  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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include <iostream>
#include <math.h>
using namespace std;
struct Var {
int xi;
int mi;
float vi;
};
int main() {
int n = 50;
int stat[n] = {
16, 14, 17, 15, 20, 16, 17, 18, 15, 13,
18, 16, 14, 17, 12, 19, 16, 15, 17, 18,
14, 19, 16, 18, 15, 17, 13, 16, 20, 15,
21, 17, 15, 16, 13, 16, 19, 18, 14, 15,
15, 16, 17, 14, 16, 19, 21, 15, 17, 18
};
cout << "Entered static row:" << endl << "[";
for (int k = 0; k < n; ++k) {
cout << stat[k];
if(k != n - 1) {
cout << ", ";
}
}
cout << "]" << endl;
int variation[n];
for (int j = 0; j < n; ++j) {
variation[j] = 0;
}
for (int i = 0; i < n; ++i) {
variation[stat[i]] += 1;
}
int count = 0;
for (int i = 0; i < n; ++i) {
if(variation[i] != 0) {
count++;
}
}
Var variative[count];
int j = 0;
int min = 9999999, max = 0;
for (int i = 0; i < n; ++i) {
if(variation[i] != 0) {
variative[j].xi = i;
variative[j].mi = variation[i];
variative[j].vi = (float) variation[i] / n;
if(min > variative[j].xi) {
min = variative[j].xi;
}
if(max < variative[j].xi) {
max = variative[j].xi;
}
j++;
}
}
cout << "Extended variation row:" << endl;
for(int i = 0; i < count; ++i) {
cout << i << " => Xi = " << variative[i].xi << ", Vi = " << variative[i].vi << ", mi = " << variative[i].mi << endl;
}
cout << "Interval variation row:" << endl;
double deltax = (double) (max - min) / (1.0 + 3.32 * log10(50));
deltax = ceil(deltax);
int dimension = ceil((max - min) / deltax);
Var x[dimension];
for (int i = 0; i < dimension; ++i) {
if(i == 0) {
x[i].xi = min - deltax / 2;
} else {
x[i].xi = x[i - 1].xi + 2;
}
x[i].mi = variative[i * 2].mi + variative[i * 2 + 1].mi;
x[i].vi = variative[i * 2].vi + variative[i * 2 + 1].vi;
}
for (int i = 0; i < dimension; ++i) {
cout << i << " => Xi = " << x[i].xi << ", Vi = " << x[i].vi << ", mi = " << x[i].mi << endl;
}
cout << "cumulate: " << endl;
Var cumulate[dimension];
float vi = 1;
for (int i = dimension; i > 0; i--) {
vi -= x[i].vi;
cumulate[i - 1].vi = vi;
}
for (int i = 0; i < dimension; ++i) {
cout << "Vi = " << cumulate[i].vi << ", Xi = " << x[i].xi + 1 << endl;
}
cout << "ogiva: " << endl;
for (int i = 0; i < dimension; ++i) {
cout << "Xi = " << x[i].xi + 1 << ", Vi = " << cumulate[i].vi << endl;
}
return 0;
}