Сравнить коммиты
3 Коммитов
f827c405aa
...
08fce6f3aa
Автор | SHA1 | Дата |
---|---|---|
|
08fce6f3aa | 2 лет назад |
|
865618e393 | 2 лет назад |
|
8f0cc94d7b | 2 лет назад |
@ -0,0 +1,2 @@
|
||||
/bin
|
||||
/obj
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -0,0 +1,9 @@
|
||||
#ifndef HEAD_H_INCLUDED
|
||||
#define HEAD_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
||||
|
||||
#endif // HEAD_H_INCLUDED
|
||||
|
@ -0,0 +1,8 @@
|
||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
void find_minmax(const std:: vector<double>& numbers, double& min, double& max)
|
||||
|
||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
@ -0,0 +1,101 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
using namespace std;
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
int main()
|
||||
{
|
||||
size_t i, j; //ԅ(≖‿≖ԅ)//
|
||||
size_t histo_height;
|
||||
size_t number_count;
|
||||
size_t bin_count;
|
||||
cerr << "Enter number count: ";
|
||||
cin >> number_count;
|
||||
vector<double> numbers(number_count);
|
||||
for (i = 0; i < number_count; i++)
|
||||
{
|
||||
cerr << "Number[" << i << "] is ";
|
||||
cin >> numbers[i];
|
||||
}
|
||||
|
||||
|
||||
double max = numbers[0];
|
||||
double min = numbers[0];
|
||||
for (i = 0; i < number_count; i++)
|
||||
{
|
||||
if (numbers[i] < min)
|
||||
min = numbers[i];
|
||||
|
||||
else if (numbers[i] > max)
|
||||
max = numbers[i];
|
||||
}
|
||||
cerr << "Enter bin count: ";
|
||||
cin >> bin_count;
|
||||
|
||||
cerr << "Enter histo height: ";
|
||||
cin >> histo_height;
|
||||
size_t table_height = histo_height / bin_count;
|
||||
|
||||
vector<size_t> bins(bin_count);
|
||||
double bin_size = (max - min) / bin_count;
|
||||
size_t max_count = 0;
|
||||
for (i = 0; i < number_count; i++)
|
||||
{
|
||||
bool found = false;
|
||||
for (j = 0; (j < bin_count - 1) && !found; j++)
|
||||
{
|
||||
double lo = min + j * bin_size;
|
||||
double hi = min + (j + 1) * bin_size;
|
||||
if ((lo <= numbers[i]) && (numbers[i] < hi))
|
||||
{
|
||||
bins[j]++;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
bins[bin_count - 1]++;
|
||||
}
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
if (bins[i] > max_count)
|
||||
max_count = bins[i];
|
||||
|
||||
}
|
||||
}
|
||||
size_t height = 0;
|
||||
for (i = 0; i < bin_count; i++)
|
||||
{
|
||||
|
||||
for (size_t a = 0; a < table_height; a++)
|
||||
{
|
||||
if (bins[i] < 100)
|
||||
cout << " ";
|
||||
if (bins[i] < 10)
|
||||
cout << " ";
|
||||
cout << bins[i] << "|";
|
||||
if (max_count > MAX_ASTERISK)
|
||||
{
|
||||
for (j = 0; j < (height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count)); j++)
|
||||
{
|
||||
cout << "*";
|
||||
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j = 0; j < bins[i]; j++)
|
||||
{
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include "head.h"
|
||||
#include "text.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
struct Input {
|
||||
vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
};
|
||||
|
||||
Input
|
||||
input_data() {
|
||||
size_t number_count;
|
||||
cin >> number_count;
|
||||
Input in;
|
||||
in.numbers.resize(number_count);
|
||||
|
||||
for (size_t i = 0; i < number_count; i++) {
|
||||
cin >> in.numbers[i];
|
||||
}
|
||||
|
||||
cout << "Enter number of bins";
|
||||
cin >> in.bin_count;
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
Input in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
show_histogram_text(bins, in.bin_count);
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include "text.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void show_histogram_text(vector <size_t> bins, size_t bin_count ) {
|
||||
|
||||
for (size_t i = 0; i < bin_count; i++) {
|
||||
if (bins[i] < 100) {
|
||||
cout << " ";
|
||||
}
|
||||
if (bins[i] < 10) {
|
||||
cout << " ";
|
||||
}
|
||||
cout << bins[i] << "|";
|
||||
for (size_t j = 0; j < bins[i]; j++) {
|
||||
cout << "*";
|
||||
}
|
||||
cout << "\n";
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
#ifndef TEXT_H_INCLUDED
|
||||
#define TEXT_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
void show_histogram_text(std::vector <size_t> bins, size_t bin_count);
|
||||
|
||||
#endif // TEXT_H_INCLUDED
|
Загрузка…
Ссылка в новой задаче