main
TabolinIA 11 месяцев назад
Родитель 782babbc6d
Сommit 556ba51f81

Разница между файлами не показана из-за своего большого размера Загрузить разницу

@ -3,7 +3,6 @@
using namespace std; using namespace std;
static
void void
find_minmax(const vector<double>& numbers, double& min, double& max) { find_minmax(const vector<double>& numbers, double& min, double& max) {
min = numbers[0]; min = numbers[0];
@ -18,7 +17,7 @@ find_minmax(const vector<double>& numbers, double& min, double& max) {
} }
} }
vector <double> make_histogram(const vector<double> numbers, size_t bin_count){ vector <double> make_histogram(const vector<double>& numbers, size_t bin_count){
double min, max; double min, max;
find_minmax(numbers, min, max); find_minmax(numbers, min, max);

@ -1,5 +1,5 @@
#ifndef HISTOGRAM_H_INCLUDED #ifndef HISTOGRAM_H_INCLUDED
#define HISTOGRAM_H_INCLUDED #define HISTOGRAM_H_INCLUDED
std::vector<size_t> std::vector<double>
make_histogram(const std::vector<double>& numbers, const std::size_t bin_count); make_histogram(const std::vector<double>& numbers, const std::size_t bin_count);
#endif // HISTOGRAM_H_INCLUDED #endif // HISTOGRAM_H_INCLUDED

@ -0,0 +1,7 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
void
find_minmax(const std::vector<double>& numbers, double& min, double& max);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -1,11 +1,10 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "histogram.h" #include "histogram.h"
#include "text.h"
using namespace std; using namespace std;
const int max_length = 80; // ìàêñèìàëüíàÿ äëèíà
const int indent = 4; // îòñòóï
struct Input { struct Input {
vector<double> numbers; vector<double> numbers;
@ -28,45 +27,12 @@ input_data() {
return in; return in;
} }
void show_histogram(const vector<double> bins, size_t bin_count){
double max_bin = bins[0];
int k;
for (size_t i = 0; i < bin_count; i++) { // íàõîæäåíèå ìàêñ çíà÷åíèÿ bin[]
if (bins[i] > max_bin) {
max_bin = bins[i];
}
}
if (max_bin <= (max_length - indent)) { // ñðàâíåíèå äëèíû ñòðîêè "*" ñ ìàêñèìàëüíîé äëèíîé âûâîäèìîé ñòðîêè
k = 0;
}
else {
k = 1;
}
cerr << endl;
int out;
for (size_t i = 0; i < bin_count; i++) {
cout.width(3); // âûðàâíèâàíèå
cout.fill(' ');
cout << bins[i] << "|";
if (k == 0) { // ìàñøòàáèðîâàíèå
out = bins[i]; // îáû÷íûé âûâîä
}
else {
out = bins[i] * (max_length - indent) / max_bin; // ìàñøòàáèðîâàííûé âûâîä
}
for (int j = 0; j < out; j++) {
cout << "*";
}
cout << endl;
}
}
int int
main() main()
{ {
auto in = input_data(); auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count); auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram(bins, in.bin_count); show_histogram_text(bins, in.bin_count);
return 0; return 0;
} }

@ -0,0 +1,12 @@
#define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "histogram_internal.h"
TEST_CASE("distinct positive numbers") {
double min = 0;
double max = 0;
find_minmax({1, 2}, min, max);
CHECK(min == 1);
CHECK(max == 2);
}
Загрузка…
Отмена
Сохранить