изменение программы

main
Raniya (ShabanovaRR) 2 дней назад
Родитель ae83d550ce befb13cc15
Сommit 313a4fa565

@ -1,106 +1,37 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
using namespace std; #include "histogram.h"
int main() #include "text.h"
{
setlocale(LC_ALL, "rus");
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
size_t number_count,bin_count;
cerr << "Ââåäèòå êîëè÷åñòâî çíà÷åíèé: "; cin >> number_count;
vector<double> number(number_count); using namespace std;
for (int i = 0; i < number_count; i++) struct Input
{
cerr << "Ââåäèòå ÷èñëî ïîä íîìåðîì " << i + 1 << " "; cin >> number[i];
}
cerr << "Ââåäèòå êîëè÷åñòâî êîðçèí: "; cin >> bin_count;
vector<size_t> bins(bin_count);
double min = number[0];
double max = number[0];
size_t Maxbins = bins[0];
for (double x : number)
{
if (x < min)
{
min = x;
}
else if (x > max)
{
max = x;
}
}
double bin_size = (max - min) / bin_count;
for (size_t i = 0; i < number_count; i++)
{ {
bool found = false; vector<double> numbers;
size_t bin_count{};
};
for (size_t j = 0; (j < bin_count - 1) && !found; j++) Input
{ input_data()
auto lo = min + j * bin_size;
auto hi = min + (j + 1) * bin_size;
if ((lo <= number[i]) && (number[i] < hi))
{ {
bins[j]++; Input in;
found = true; size_t number_count;
} cin >> number_count;
in.numbers.resize(number_count);
} vector<double> numbers(number_count);
if (!found) for (size_t i = 0; i < number_count; i++)
{
bins[bin_count - 1]++;
}
}
for (int i = 0; i < bin_count; i++)
{
if (bins[i] > Maxbins)
{
Maxbins = bins[i];
}
}
if (Maxbins <= 76)
{
for (int i = 0; i < bins.size(); i++)
{
if (bins[i] < 10)
{
cout << " ";
}
cout << " " << bins[i] << "|";
for (int j = 0; j < bins[i]; j++)
{ {
cout << "*"; cin >> in.numbers[i];
} }
cout << endl;
cin >> in.bin_count;
return in;
}
}
else
{
for (int i = 0; i < bins.size(); i++)
{
size_t height = MAX_ASTERISK * (static_cast<double>(bins[i]) / Maxbins);
if (bins[i] < 100)
{
cout << " ";
}
if (bins[i] < 10)
{
cout << " ";
} }
cout << bins[i] << "|"; int main()
for (int j = 0; j < height; j++)
{ {
cout << "*"; size_t max_count;
} auto in = input_data();
cout << endl; auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins, in.bin_count, max_count);
}
}
} }

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