|
|
@ -44,53 +44,46 @@ find_minmax(vector<double> numbers, double& min, double& max)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto make_histogram (vector<double> numbers, size_t bin_count)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
const size_t screen_width = 80;
|
|
|
|
|
|
|
|
const size_t max_asterisk = screen_width - 3 - 1;
|
|
|
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Input in = input_data();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vector <size_t> bins(in.bin_count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double min;
|
|
|
|
double min;
|
|
|
|
double max;
|
|
|
|
double max;
|
|
|
|
find_minmax (in.numbers, min, max);
|
|
|
|
find_minmax (numbers, min, max);
|
|
|
|
|
|
|
|
double bin_size = (max - min) / bin_count;
|
|
|
|
double bin_size = (max - min) / in.bin_count;
|
|
|
|
vector<size_t> bins(bin_count);
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < in.numbers.size(); i++)
|
|
|
|
for (size_t i = 0; i < numbers.size(); i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
bool found = false;
|
|
|
|
for (size_t j = 0; (j < in.bin_count - 1) && !found; j++)
|
|
|
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto lo = min + j * bin_size;
|
|
|
|
auto lo = min + j * bin_size;
|
|
|
|
auto hi = min + (j + 1) * bin_size;
|
|
|
|
auto hi = min + (j + 1) * bin_size;
|
|
|
|
if ((lo <= in.numbers[i]) && (in.numbers[i] < hi))
|
|
|
|
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bins[j] ++;
|
|
|
|
bins[j]++;
|
|
|
|
found = true;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bins[in.bin_count - 1]++;
|
|
|
|
bins[bin_count - 1]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return bins;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void show_histogram_text(auto bins, size_t bin_count)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
const size_t screen_width = 80;
|
|
|
|
|
|
|
|
const size_t max_asterisk = screen_width - 3 - 1;
|
|
|
|
|
|
|
|
size_t i,j;
|
|
|
|
double max_count;
|
|
|
|
double max_count;
|
|
|
|
max_count = bins[0];
|
|
|
|
max_count = bins[0];
|
|
|
|
for (i=0; i< in.bin_count; i++)
|
|
|
|
for (i=0; i< bin_count; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (max_count<bins[i])
|
|
|
|
if (max_count<bins[i])
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -104,7 +97,7 @@ int main()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
flag=true;
|
|
|
|
flag=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (j = 0; j < in.bin_count; j++)
|
|
|
|
for (j = 0; j < bin_count; j++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (bins[j] < 100)
|
|
|
|
if (bins[j] < 100)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -130,6 +123,18 @@ int main()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_getch();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto in = input_data();
|
|
|
|
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
|
|
|
show_histogram_text(bins, in.bin_count);
|
|
|
|
|
|
|
|
getch();
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|