MaryK 2 лет назад
Родитель 0f6093a0a2
Сommit 70f5dd9f71

@ -0,0 +1,6 @@
142
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3
15

Двоичные данные
bin/Debug/devlab1.exe

Двоичный файл не отображается.

@ -1,4 +1,4 @@
10
3 3 3 4 4 4 4 4 5 5
3
12
16

@ -0,0 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<svg width='400' height='300' viewBox='0 0 400 300' xmlns='http://www.w3.org/2000/svg'>
<text x='20' y='20'>9</text><rect x='50' y='0' width='31.5' height='30' stroke='violet' fill='#101010' />
<text x='20' y='50'>33</text><rect x='50' y='30' width='115.5' height='30' stroke='violet' fill='#101010' />
<text x='20' y='80'>100</text><rect x='50' y='60' width='350' height='30' stroke='violet' fill='#101010' />
</svg>

После

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

Двоичные данные
bin/Debug/unittest.exe

Двоичный файл не отображается.

@ -1,5 +1,5 @@
# depslib dependency file v1.0
1681739567 source:c:\program files\codeblocks\devlab1\main.cpp
1682334548 source:c:\program files\codeblocks\devlab1\main.cpp
<iostream>
<vector>
<cmath>
@ -9,7 +9,7 @@
1681733870 c:\program files\codeblocks\devlab1\histogram.h
<vector>
1681738471 source:c:\program files\codeblocks\devlab1\histogram.cpp
1682342839 source:c:\program files\codeblocks\devlab1\histogram.cpp
"histogram.h"
<vector>
<iostream>
@ -21,10 +21,10 @@
1680530410 source:c:\program files\codeblocks\devlab1\text.cpp
"text.h"
1681734640 c:\program files\codeblocks\devlab1\svg.h
1682337558 c:\program files\codeblocks\devlab1\svg.h
<vector>
1681739461 source:c:\program files\codeblocks\devlab1\svg.cpp
1682339123 source:c:\program files\codeblocks\devlab1\svg.cpp
"svg.h"
<iostream>
<vector>

@ -2,44 +2,49 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="text.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="69" topLine="0" />
<Cursor1 position="145" topLine="0" />
</Cursor>
</File>
<File name="text.cpp" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="doctest.h" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="342" topLine="0" />
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="histogram.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="145" topLine="0" />
<Cursor1 position="2104" topLine="81" />
</Cursor>
</File>
<File name="histogram.cpp" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram_internal.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="876" topLine="13" />
<Cursor1 position="160" topLine="0" />
</Cursor>
</File>
<File name="svg.h" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="122" topLine="0" />
<Cursor1 position="139" topLine="0" />
</Cursor>
</File>
<File name="histogram_internal.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="text.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="69" topLine="0" />
</Cursor>
</File>
<File name="svg.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="1243" topLine="30" />
<Cursor1 position="544" topLine="17" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<File name="histogram.cpp" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1079" topLine="39" />
<Cursor1 position="876" topLine="13" />
</Cursor>
</File>
<File name="text.cpp" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="342" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -2,9 +2,12 @@
#include <vector>
#include <iostream>
using namespace std;
void
bool
find_minmax(const vector<double>& numbers, double& min, double& max)
{
if(numbers.empty())
return false;
min = numbers[0];
max = numbers[0];
for ( size_t i=0; i < numbers.size(); i++)
@ -12,15 +15,16 @@ find_minmax(const vector<double>& numbers, double& min, double& max)
if (numbers[i] > max) max=numbers[i];
if (numbers[i] < min) min=numbers[i];
}
};
return true;
};
std::vector<long long unsigned int>
make_histogram(const vector<double> &numbers,size_t bin_count)
{
float lo,hi,dif;
double min, max;
find_minmax(numbers, min, max);
//std::cout<<bin_count<<endl;
if(!find_minmax(numbers, min, max))
return 1;
vector <size_t> bins(bin_count) ;
dif=(max - min)/bin_count;
for(int i=0; i < numbers.size(); i++)
@ -35,19 +39,13 @@ make_histogram(const vector<double> &numbers,size_t bin_count)
bins[j]++;
found = true;
}
// std::cout<<bins[j]<<endl;
}
}
if (!found)
{
bins[bin_count - 1]++;
}
//if (i==0) break;
}
/*for (size_t j=0; j < bin_count; j++){
std::cout<<bins[j]<<endl;
}*/
return bins;
}

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

@ -5,37 +5,19 @@
#include "svg.h"
using namespace std;
int inbl()
{
int BLOCK_WIDTH;
cerr << "block width is";
cin>>BLOCK_WIDTH;
if (BLOCK_WIDTH>30)
{
cerr<< "too big, please make it smaller";
inbl;
}
else if (BLOCK_WIDTH<3)
{
cerr<< "too small, please make it bigger";
inbl;
}
else return BLOCK_WIDTH;
}
struct Input
{
vector<double> numbers;
int bin_count;
int BLOCK_WIDTH;
};
Input
input_data()
{
size_t number_count=0;
cerr<<"amount of numbers is";
cerr<<"amount of numbers is ";
cin >> number_count;
Input in;
Input in;
in.numbers.resize(number_count);
cerr<<"let's intro numbers ";
for (size_t i = 0; i < number_count; i++)
@ -43,9 +25,8 @@ Input in;
cin >> in.numbers[i];
}
size_t bin_count=0;
cerr<<"amount of bins is";
cerr<<"amount of bins is ";
cin >> in.bin_count;
int BLOCK_WIDTH = inbl();
return in;
}
//4199705
@ -62,7 +43,7 @@ int main()
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins,in.BLOCK_WIDTH);
show_histogram_svg(bins);
return 0;

Двоичные данные
obj/Debug/histogram.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/main.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/svg.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/unittest.o

Двоичный файл не отображается.

@ -4,6 +4,22 @@
using namespace std;
bool inbl(const int& BLOCK_WIDTH)
{
if (BLOCK_WIDTH>30)
{
cerr<< "too big, please make it smaller\n";
return false;
}
if (BLOCK_WIDTH<3)
{
cerr<< "too small, please make it bigger\n";
return false;
}
return true;
}
void
svg_begin(double width, double height)
{
@ -33,19 +49,17 @@ void svg_rect(double x, double y, double width, double height, string stroke = "
}
void
show_histogram_svg(vector<long long unsigned int> & bins, int BLOCK_WIDTH)
show_histogram_svg(vector<long long unsigned int> & bins)
{
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
const auto TEXT_BASELINE = 20;
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
BLOCK_WIDTH=BLOCK_WIDTH+12;
svg_begin(400, 300);
const auto MAX_ASTERISK1 = 30;
double top = 0;
const size_t MAX_ASTERISK = IMAGE_WIDTH - TEXT_WIDTH;
@ -56,10 +70,22 @@ BLOCK_WIDTH=BLOCK_WIDTH+12;
if (bins[j] > maxb) maxb = bins[j];
}
auto maxb1 = maxb * BLOCK_WIDTH;
int i = 0;
int BLOCK_WIDTH;
while (true){
cerr << "block width: ";
cin >> BLOCK_WIDTH;
if(inbl(BLOCK_WIDTH))
break;
}
auto maxb1 = maxb * BLOCK_WIDTH;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
for (size_t bin : bins)
{
@ -69,9 +95,13 @@ BLOCK_WIDTH=BLOCK_WIDTH+12;
if (maxb1 > MAX_ASTERISK)
{
bin_width = BLOCK_WIDTH * MAX_ASTERISK * (bin / maxb1);
bin_width = MAX_ASTERISK * (static_cast<double>(bin) / maxb);
}
else bin_width = BLOCK_WIDTH * bin;
else
bin_width = BLOCK_WIDTH * bin;
cerr << "\n" << bin_width << "\n";
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "violet", to_string(color));

@ -2,4 +2,5 @@
#include <vector>
void
show_histogram_svg(std::vector<long long unsigned int>& bins, int BLOCK_WIDTH);
show_histogram_svg(std::vector<long long unsigned int>& bins);
bool inbl(const int& BLOCK_WIDTH);

@ -34,6 +34,8 @@
<Unit filename="doctest.h" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram_internal.h" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Unit filename="unittest.cpp" />
<Extensions />
</Project>

@ -2,7 +2,20 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "histogram_internal.h"
#include "svg.h"
TEST_CASE("Too big") {
int BLOCKWIDTH =40;
CHECK(inbl(BLOCKWIDTH) == false);
}
TEST_CASE("Too small") {
int BLOCKWIDTH =1;
CHECK(inbl(BLOCKWIDTH) == false);
}
TEST_CASE("ok ") {
int BLOCKWIDTH =12;
CHECK(inbl(BLOCKWIDTH) == true);
}
TEST_CASE("distinct positive numbers") {
double min = 0;
double max = 0;
@ -34,3 +47,13 @@ TEST_CASE("distinct negative numbers") {
CHECK(min == -3);
CHECK(max == -1);
}
TEST_CASE("empty arr") {
double min = 0;
double max = 0;
CHECK(find_minmax({}, min, max) == false);
CHECK(find_minmax({3,4}, min, max) == true);
;
}

@ -1,14 +1,16 @@
# depslib dependency file v1.0
1680530029 source:c:\program files\codeblocks\devlab1\histogram.cpp
1682343064 source:c:\program files\codeblocks\devlab1\histogram.cpp
"histogram.h"
<vector>
<iostream>
1680530141 c:\program files\codeblocks\devlab1\histogram.h
1681733870 c:\program files\codeblocks\devlab1\histogram.h
<vector>
1681719645 source:c:\program files\codeblocks\devlab1\unittest.cpp
1682343068 source:c:\program files\codeblocks\devlab1\unittest.cpp
"doctest.h"
"histogram_internal.h"
"svg.h"
1681707623 c:\program files\codeblocks\devlab1\doctest.h
<signal.h>
@ -55,5 +57,13 @@
<sys/time.h>
<unistd.h>
1681730258 c:\program files\codeblocks\devlab1\histogram_internal.h
1682343113 c:\program files\codeblocks\devlab1\histogram_internal.h
1682339123 source:c:\program files\codeblocks\devlab1\svg.cpp
"svg.h"
<iostream>
<vector>
1682337558 c:\program files\codeblocks\devlab1\svg.h
<vector>

@ -2,19 +2,14 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="unittest.cpp" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="305" topLine="0" />
</Cursor>
</File>
<File name="doctest.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="94789" topLine="2177" />
<Cursor1 position="110023" topLine="2360" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="unittest.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="824" topLine="0" />
</Cursor>
</File>
<File name="histogram_internal.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -22,4 +17,9 @@
<Cursor1 position="160" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="86" topLine="20" />
</Cursor>
</File>
</CodeBlocks_layout_file>

Загрузка…
Отмена
Сохранить