Vitaliy (SamashovVV) 2 лет назад
Родитель d70342b86c
Сommit ea387ac0b3

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

@ -2,6 +2,7 @@
#include <vector>
#include "histogram.h"
using namespace std;
void
find_minmax(vector<double> numbers, double& min, double& max) {
min = numbers[0];
@ -18,7 +19,7 @@ find_minmax(vector<double> numbers, double& min, double& max) {
vector<size_t>
make_histogram(vector<double> numbers, size_t bin_count) {
vector <size_t> bins(bin_count);
vector <size_t> bins(bin_count, 0);
double min, max;
find_minmax(numbers, min, max);
size_t countt;

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

@ -3,10 +3,12 @@
#include "histogram.h"
#include "text.h"
#include "svg.h"
using namespace std;
struct Input {
vector<double> numbers;
size_t bin_count{};
size_t bin_count;
};
Input
@ -18,14 +20,17 @@ input_data(){
in.numbers.resize(number_count);
for(int i;i<number_count;i++)
{
cerr << i + 1 << ": ";
cin >> in.numbers[i];
}
cerr << "Enter bin count: ";
cin >> in.bin_count;
getchar();
return in;
}
int main()
{ Input in = input_data();
{
Input in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
return 0;

@ -1,6 +1,7 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
#include <vector>
void
show_histogram_svg(const std::vector<size_t>& bins);

@ -0,0 +1,3 @@
<?xml version='1.0' encoding='UTF-8'?>
<svg width='400' height='300' viewBox='0 0 400 300' xmlns='http://www.w3.org/2000/svg'>
<rect x='0' y='0' width='175' height='30' stroke='white' fill='#ffffff' /><text x='360' y='20'>1</text><rect x='175' y='0' width='175' height='30' stroke='red' fill='#aaffaa' /><rect x='0' y='30' width='175' height='30' stroke='white' fill='#ffffff' /><text x='360' y='50'>1</text><rect x='175' y='30' width='175' height='30' stroke='red' fill='#aaffaa' /><rect x='0' y='60' width='0' height='30' stroke='white' fill='#ffffff' /><text x='360' y='80'>2</text><rect x='0' y='60' width='350' height='30' stroke='red' fill='#aaffaa' /></svg>

После

Ширина:  |  Высота:  |  Размер: 665 B

@ -2,7 +2,9 @@
#include <vector>
#include "text.h"
#include "histogram.h"
using namespace std;
void
show_histogram_text(vector<size_t> bins, size_t bin_count){
const size_t SCREEN_WIDTH = 80;

@ -1,5 +1,6 @@
#ifndef TEXT_H_INCLUDED
#define TEXT_H_INCLUDED
#include <vector>
void
show_histogram_text(std::vector<size_t> bins, size_t bin_count);

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