Сравнить коммиты

...

8 Коммитов

Автор SHA1 Сообщение Дата
Алёна Аулова aee4e114a9 :
2 лет назад
Алёна Аулова d6a0b071e4 :
2 лет назад
Алёна Аулова 6aa080491d :
2 лет назад
Алёна Аулова d9834d985a :
2 лет назад
Алёна Аулова f7b44c17a2 :
2 лет назад
Алёна Аулова b9aa3c81d4 :
2 лет назад
Алёна Аулова 43a6b254fa ggg
2 лет назад
Алёна Аулова 810a9fe67d :
2 лет назад

@ -0,0 +1,52 @@
#include <iostream>
#include <vector>
#include "histogram.h"
//std::vector<size_t>
void
find_minmax(const std::vector<double> numbers, double& min, double& max)
{
/*/double/*/ min = numbers[0];//ïîèñê ìèí è ìàêñ
/*/ double/*/ max = numbers[0];
for (double x : numbers)
{
if (x < min)
{
min = x;
}
else if (x > max)
{
max = x;
}
}
}
std::vector<size_t>
make_histogram(const std::vector<double> numbers, size_t bin_count)
{
std::vector <size_t> bins(bin_count);
double min, max;
find_minmax(numbers, min, max);
double bin_size = (max-min)/bin_count;//ðàçìåð êîðçèíû
for (size_t i = 0; i < numbers.size(); i++)//çàïîëíåíèå
{
bool found = false;
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
{
auto lo = min + j * bin_size;
auto hi = min + (j + 1) * bin_size;
if ((lo <= numbers[i]) && (numbers[i] < hi))
{
bins[j]++;
found = true;
}
}
if (!found)
{
bins[bin_count - 1]++;
}
}
return bins;
}

@ -0,0 +1,9 @@
#ifndef HISTOGRAM_H_INCLUDED
#define HISTOGRAM_H_INCLUDED
#include <vector>
#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

@ -0,0 +1,25 @@
#include <iostream>
#include <vector>
#include "svg.h"
using namespace std;
void
svg_begin(double width, double height) {
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
cout << "<svg ";
cout << "width='" << width << "' ";
cout << "height='" << height << "' ";
cout << "viewBox='0 0 " << width << " " << height << "' ";
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
}
void
svg_end() {
cout << "</svg>\n";
}
void
show_histogram_svg(const vector<size_t> &bins) {
svg_begin(400, 300);
svg_end();
}

@ -0,0 +1,7 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
void
svg_begin(double width, double height)
#endif // SVG_H_INCLUDED

@ -0,0 +1,67 @@
#include <iostream>
#include <vector>
#include "text.h"
using namespace std;
void
show_histogram_text(vector<size_t> bins, size_t bin_count)
{
size_t max_count=0;
for (size_t i =0; i<bin_count; i++)
{
if (max_count <bins[i])
{
max_count=bins[i];
}
}
float procent;
for(size_t i=0; i<bin_count; i++)
{
int procent =(float)bins[i];
if (procent<10)
{
cout<<" "<<procent<<" | ";
}
if ((procent<100)&&(procent>=10))
{
cout<<" "<<procent<<" | ";
}
size_t height = 0;
if (max_count>76)
{
size_t height = 76 * (static_cast<double>(bins[i]) / max_count);
for(size_t j=0; j<=height; j++)
{
cout<<"*";
}
}
else
{
for(size_t j=0; j<=bins[i]-1; j++)
{
cout<<"*";
}
}
cout<<endl;
}
return;
}

@ -0,0 +1,8 @@
#ifndef TEXT_H_INCLUDED
#define TEXT_H_INCLUDED
std::vector<size_t>
void
show_histogram_text(std::vector<size_t> bins, size_t bin_count);
#endif // TEXT_H_INCLUDED

@ -0,0 +1,39 @@
#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);
}
TEST_CASE("vector 1 element")
{
double min = 0;
double max = 0;
find_minmax({1}, min, max);
CHECK(min == 1);
CHECK(max == 1);
}
TEST_CASE("distinct negativ numbers")
{
double min = 0;
double max = 0;
find_minmax({-1, -2}, min, max);
CHECK(min == -2);
CHECK(max == -1);
}
TEST_CASE("distinct positive numbers")
{
double min = 0;
double max = 0;
find_minmax({2, 2}, min, max);
CHECK(min == 2);
CHECK(max == 2);
}
Загрузка…
Отмена
Сохранить