bult: создал все функции

main
Alice (KasimovAM) 2 лет назад
Родитель 854b079777
Сommit 0ab75c06f5

@ -4,28 +4,29 @@
using namespace std; using namespace std;
int main() struct Input {
{ vector<double> numbers;
int i, j; size_t bin_count{};
size_t number_count; };
const size_t screen_width = 80;
const size_t max_asterisk = screen_width - 3 - 1;
cerr << "Enter number count : "; Input
input_data() {
size_t number_count;
cin >> number_count; cin >> number_count;
vector <double> numbers(number_count); Input in;
cerr << "Enter numbers : " << endl; in.numbers.resize(number_count);
for (i = 0; i < number_count; i++) for (size_t i = 0; i < number_count; i++) {
{ cin >> in.numbers[i];
cin >> numbers[i];
} }
size_t bin_count;
cerr<< "Enter bin count: "; cerr<< "Enter bin count: ";
cin >> bin_count; cin >> in.bin_count;
vector <size_t> bins(bin_count); return in;
}
double min = numbers[0]; void
double max = numbers[0]; find_minmax(vector<double> &numbers, double& min, double& max) {
min = numbers[0];
max = numbers[0];
for (double x : numbers) for (double x : numbers)
{ {
if (x < min) if (x < min)
@ -37,10 +38,16 @@ int main()
max = x; max = x;
} }
} }
return;
}
vector<size_t> make_histogram (vector<double> numbers, size_t bin_count)
{
double min;
double max;
find_minmax (numbers, min, max);
double bin_size = (max - min) / bin_count; double bin_size = (max - min) / bin_count;
vector<size_t> bins(bin_count);
for (size_t i = 0; i < number_count; i++) for (size_t i = 0; i < numbers.size(); i++)
{ {
bool found = false; bool found = false;
for (size_t j = 0; (j < bin_count - 1) && !found; j++) for (size_t j = 0; (j < bin_count - 1) && !found; j++)
@ -58,7 +65,14 @@ int main()
bins[bin_count - 1]++; bins[bin_count - 1]++;
} }
} }
return bins;
}
void show_histogram_text(vector<size_t> 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< bin_count; i++) for (i=0; i< bin_count; i++)
@ -101,6 +115,14 @@ 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;
} }

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