DenisovPS 2 лет назад
Родитель 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)
{
cin >> xs[i];
}
cerr << "Columns = "; cin >> columns;
vector<size_t> a(columns);
maxx = xs[0];
minn = xs[0];
for (int i = 0; i < numbers; i++)
{
if (xs[i] > maxx)
maxx = xs[i];
else
{
if (xs[i] < minn)
minn = xs[i];
}
}
diff = (maxx - minn) / columns;
lo = minn;
size_t max_count = 0;
for (int i = 0; i < columns; ++i)
{
count = 0;
if (i != columns - 1) Input
{ input_data(istream& inn, bool prompt)
hi = lo + diff; {
} size_t number_count;
else if (prompt == true)
{ cerr << "number_count = ";
hi = maxx; inn >> number_count;
}
for (int j = 0; j < numbers; j++)
{
if (i == 0)
{
if ((xs[j] >= lo) && (xs[j] <= hi))
count++;
}
else Input in;
{ in.numbers.resize(number_count);
if ((xs[j] > lo) && (xs[j] <= hi))
count++;
}
}
a[i] = count;
lo = hi;
if (max_count < a[i]) if (prompt == true)
max_count = a[i]; cerr << "numbers:";
for (size_t i = 0; i < number_count; i++) {
inn >> in.numbers[i];
} }
const size_t SCREEN_WIDTH = 80; cerr << "columns = ";
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; cin >> in.bin_count;
size_t height; return in;
for (int i = 0; i < columns; i++) }
{
if (a[i] == 0)
continue;
if (a[i] < 10) int
cout << " "; main()
else {
if (a[i] < 100)
cout << " ";
cout << a[i] << "|"; auto in = input_data(cin, true);
if (max_count > MAX_ASTERISK) auto bins = make_histogram(in.numbers, in.bin_count);
height = MAX_ASTERISK * (static_cast<double>(a[i]) / max_count);
else
height = a[i];
for (int j = 0; j < height; j++) show_histogram_svg(bins);
{
cout << "*";
}
cout << endl;
}
} }

Загрузка…
Отмена
Сохранить