Родитель
17cda0871e
Сommit
ddd75f3b11
@ -1,102 +1,42 @@
|
|||||||
#include <iostream>
|
#include "histogram.h"
|
||||||
#include <vector>
|
#include "svg.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main()
|
struct Input {
|
||||||
{
|
vector<double> numbers;
|
||||||
size_t numbers, columns, count;
|
size_t bin_count{};
|
||||||
float minn, maxx, diff, lo, hi;
|
};
|
||||||
|
|
||||||
cerr << "Quantity of numbers = "; cin >> numbers;
|
|
||||||
vector<float> xs(numbers);
|
|
||||||
cerr << "Enter your numbers: ";
|
|
||||||
|
|
||||||
for (int i = 0; i < numbers; ++i)
|
Input
|
||||||
|
input_data(istream& inn, bool prompt)
|
||||||
{
|
{
|
||||||
cin >> xs[i];
|
size_t number_count;
|
||||||
}
|
if (prompt == true)
|
||||||
|
cerr << "number_count = ";
|
||||||
|
inn >> number_count;
|
||||||
|
|
||||||
cerr << "Columns = "; cin >> columns;
|
Input in;
|
||||||
vector<size_t> a(columns);
|
in.numbers.resize(number_count);
|
||||||
|
|
||||||
maxx = xs[0];
|
if (prompt == true)
|
||||||
minn = xs[0];
|
cerr << "numbers:";
|
||||||
for (int i = 0; i < numbers; i++)
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
{
|
inn >> in.numbers[i];
|
||||||
if (xs[i] > maxx)
|
|
||||||
maxx = xs[i];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (xs[i] < minn)
|
|
||||||
minn = xs[i];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cerr << "columns = ";
|
||||||
diff = (maxx - minn) / columns;
|
cin >> in.bin_count;
|
||||||
lo = minn;
|
return in;
|
||||||
|
|
||||||
size_t max_count = 0;
|
|
||||||
for (int i = 0; i < columns; ++i)
|
|
||||||
{
|
|
||||||
count = 0;
|
|
||||||
|
|
||||||
if (i != columns - 1)
|
|
||||||
{
|
|
||||||
hi = lo + diff;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hi = maxx;
|
|
||||||
}
|
|
||||||
for (int j = 0; j < numbers; j++)
|
|
||||||
{
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
if ((xs[j] >= lo) && (xs[j] <= hi))
|
|
||||||
count++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
int
|
||||||
|
main()
|
||||||
{
|
{
|
||||||
if ((xs[j] > lo) && (xs[j] <= hi))
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
a[i] = count;
|
|
||||||
lo = hi;
|
|
||||||
|
|
||||||
if (max_count < a[i])
|
auto in = input_data(cin, true);
|
||||||
max_count = a[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
const size_t SCREEN_WIDTH = 80;
|
|
||||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
||||||
size_t height;
|
|
||||||
for (int i = 0; i < columns; i++)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (a[i] == 0)
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
continue;
|
|
||||||
|
|
||||||
if (a[i] < 10)
|
show_histogram_svg(bins);
|
||||||
cout << " ";
|
|
||||||
else
|
|
||||||
if (a[i] < 100)
|
|
||||||
cout << " ";
|
|
||||||
|
|
||||||
cout << a[i] << "|";
|
|
||||||
|
|
||||||
if (max_count > MAX_ASTERISK)
|
|
||||||
height = MAX_ASTERISK * (static_cast<double>(a[i]) / max_count);
|
|
||||||
else
|
|
||||||
height = a[i];
|
|
||||||
|
|
||||||
for (int j = 0; j < height; j++)
|
|
||||||
{
|
|
||||||
cout << "*";
|
|
||||||
}
|
|
||||||
cout << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Загрузка…
Ссылка в новой задаче