code: добавление всех функций
Этот коммит содержится в:
64
main.cpp
64
main.cpp
@@ -4,28 +4,31 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
struct Input
|
||||
{
|
||||
int i, j;
|
||||
size_t number_count;
|
||||
const size_t screen_width = 80;
|
||||
const size_t max_asterisk = screen_width - 3 - 1;
|
||||
vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
};
|
||||
|
||||
Input input_data()
|
||||
{
|
||||
size_t number_count;
|
||||
cerr<<"Enter number count: ";
|
||||
cin >> number_count;
|
||||
vector <double> numbers(number_count);
|
||||
cerr << "Enter numbers : " << endl;
|
||||
for (i = 0; i < number_count; i++)
|
||||
Input in;
|
||||
in.numbers.resize(number_count);
|
||||
for (size_t i =0; i < number_count; i++)
|
||||
{
|
||||
cin >> numbers[i];
|
||||
cin >> in.numbers[i];
|
||||
}
|
||||
size_t bin_count;
|
||||
cerr<< "Enter bin count: ";
|
||||
cin >> bin_count;
|
||||
vector <size_t> bins(bin_count);
|
||||
|
||||
double min = numbers[0];
|
||||
double max = numbers[0];
|
||||
cin >> in.bin_count;
|
||||
return in;
|
||||
}
|
||||
void find_minmax(const vector<double> &numbers, double &min, double &max)
|
||||
{
|
||||
min = numbers[0];
|
||||
max = numbers[0];
|
||||
for (double x : numbers)
|
||||
{
|
||||
if (x < min)
|
||||
@@ -37,10 +40,19 @@ int main()
|
||||
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;
|
||||
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;
|
||||
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
||||
@@ -53,12 +65,21 @@ int main()
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
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;
|
||||
max_count = bins[0];
|
||||
for (i=0; i< bin_count; i++)
|
||||
@@ -101,6 +122,15 @@ int main()
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user