Выполнена индивидуальная задача
Этот коммит содержится в:
@@ -32,7 +32,14 @@
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename=".gitignore" />
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h" />
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
|
||||
46
Lab_1.depend
Обычный файл
46
Lab_1.depend
Обычный файл
@@ -0,0 +1,46 @@
|
||||
# depslib dependency file v1.0
|
||||
1680527920 source:l:\i êóðñ\À-3-22\Êîìêîâ\lab_1\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1680527920 source:e:\ëàáà 1\lab_1\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1685970224 source:c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\histogram.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
"histogram.h"
|
||||
|
||||
1685968632 c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\histogram.h
|
||||
<vector>
|
||||
|
||||
1685971982 source:c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
<conio.h>
|
||||
"histogram.h"
|
||||
"text.h"
|
||||
"svg.h"
|
||||
|
||||
1685882625 c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\text.h
|
||||
<vector>
|
||||
|
||||
1685882527 source:c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\text.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
"text.h"
|
||||
|
||||
1685972025 source:c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\svg.cpp
|
||||
<math.h>
|
||||
<iostream>
|
||||
<conio.h>
|
||||
<vector>
|
||||
<string>
|
||||
"svg.h"
|
||||
|
||||
1685972059 c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\svg.h
|
||||
<vector>
|
||||
<iostream>
|
||||
<algorithm>
|
||||
|
||||
40
Lab_1.layout
Обычный файл
40
Lab_1.layout
Обычный файл
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="text.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="83" 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">
|
||||
<Cursor>
|
||||
<Cursor1 position="116" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="text.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="172" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="svg.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" 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">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="39" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
@@ -4,8 +4,9 @@
|
||||
#include "histogram.h"
|
||||
using namespace std;
|
||||
|
||||
void find_minmax(const vector<double> &numbers, double &min, double &max)
|
||||
{
|
||||
bool find_minmax(const vector<double> &numbers, double &min, double &max){
|
||||
if (numbers.empty())return false;
|
||||
else{
|
||||
max = numbers[0];
|
||||
min = numbers[1];
|
||||
for (double x: numbers)
|
||||
@@ -19,10 +20,9 @@ void find_minmax(const vector<double> &numbers, double &min, double &max)
|
||||
max = x;
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
||||
vector<size_t> make_histogram (vector<double> numbers, size_t bin_count)
|
||||
{
|
||||
|
||||
@@ -52,4 +52,14 @@ vector<size_t> make_histogram (vector<double> numbers, size_t bin_count)
|
||||
return bins;
|
||||
}
|
||||
|
||||
vector<double> make_borders(const vector<double>& numbers, size_t bin_count){
|
||||
double min, max;
|
||||
find_minmax(numbers, min, max);
|
||||
double diff = (max - min) / bin_count;
|
||||
std::vector <double> borders(bin_count - 1);
|
||||
for (size_t i = 0; i <= bin_count - 2; i++){
|
||||
borders[i] = min + (i + 1) * diff;
|
||||
}
|
||||
return borders;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,4 +5,7 @@
|
||||
std::vector<size_t>
|
||||
make_histogram(const std::vector<double> numbers, size_t bin_count);
|
||||
|
||||
std::vector<double>
|
||||
make_borders(const std::vector<double>& numbers, size_t bin_count);
|
||||
|
||||
#endif // HISTOGRAM_H_INCLUDED
|
||||
|
||||
4
main.cpp
4
main.cpp
@@ -4,6 +4,7 @@
|
||||
#include <conio.h>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
using namespace std;
|
||||
|
||||
struct Input {
|
||||
@@ -32,7 +33,8 @@ int main()
|
||||
{
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
show_histogram_text(bins, in.bin_count);
|
||||
auto borders = make_borders(in.numbers, in.bin_count);
|
||||
show_histogram_svg(bins, borders, in.bin_count);
|
||||
getch();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Двоичные данные
main.exe
Обычный файл
Двоичные данные
main.exe
Обычный файл
Двоичный файл не отображается.
Двоичные данные
main.o
Обычный файл
Двоичные данные
main.o
Обычный файл
Двоичный файл не отображается.
25
svg.cpp
25
svg.cpp
@@ -19,6 +19,7 @@ svg_begin(double width, double height)
|
||||
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
svg_end()
|
||||
{
|
||||
@@ -41,7 +42,7 @@ svg_rect(double x, double y, double width, double height, string stroke = "black
|
||||
|
||||
|
||||
void
|
||||
show_histogram_svg(const vector<size_t>& bins)
|
||||
show_histogram_svg(const vector<size_t>& bins, const vector<double>& borders, size_t bin_count)
|
||||
{
|
||||
const auto IMAGE_WIDTH = 400;
|
||||
const auto IMAGE_HEIGHT = 300;
|
||||
@@ -50,12 +51,14 @@ show_histogram_svg(const vector<size_t>& bins)
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
const auto BLACK = "black";
|
||||
const auto RED = "red";
|
||||
const auto COLOUR1 = "black";
|
||||
const auto COLOUR2 = "green";
|
||||
const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
|
||||
|
||||
size_t border = 0;
|
||||
size_t number_of_blocks;
|
||||
|
||||
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
|
||||
size_t max_bin = *max_element(bins.begin(), bins.end());
|
||||
|
||||
double top = 0;
|
||||
double max_count = bins[0];
|
||||
@@ -69,10 +72,20 @@ show_histogram_svg(const vector<size_t>& bins)
|
||||
|
||||
for (size_t bin : bins)
|
||||
{
|
||||
double bin_width = (MAX_WIDTH)*(bin/max_count);
|
||||
number_of_blocks = bin;
|
||||
if ((max_bin * BLOCK_WIDTH) > (IMAGE_WIDTH - TEXT_WIDTH)){
|
||||
number_of_blocks = ((IMAGE_WIDTH - TEXT_WIDTH)/10) * (static_cast<double>(bin) / max_bin);
|
||||
}
|
||||
const double bin_width = BLOCK_WIDTH * number_of_blocks;
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, BLACK, RED);
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, COLOUR1, COLOUR2);
|
||||
top += BIN_HEIGHT;
|
||||
if (border < bin_count - 1){
|
||||
top += BIN_HEIGHT;
|
||||
svg_text(TEXT_LEFT / 2, top + TEXT_BASELINE , to_string(borders[border]));
|
||||
border += 1;
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
svg_end();
|
||||
|
||||
4
svg.h
4
svg.h
@@ -1,9 +1,11 @@
|
||||
#ifndef SVG_H_INCLUDED
|
||||
#define SVG_H_INCLUDED
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
void
|
||||
show_histogram_svg(const std::vector<size_t>& bins);
|
||||
show_histogram_svg(const std::vector<size_t>& bins, const std::vector<double>& borders, size_t bin_count);
|
||||
|
||||
|
||||
#endif // SVG_H_INCLUDED
|
||||
|
||||
42
unittest.cbp
Обычный файл
42
unittest.cbp
Обычный файл
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="unittest" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/unittest" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/unittest" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
</Compiler>
|
||||
<Unit filename="doctest.h" />
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram_internal.h" />
|
||||
<Unit filename="unittest.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
@@ -25,5 +25,6 @@ TEST_CASE("vector of the same elements"){
|
||||
find_minmax({3,3,3}, min, max);
|
||||
CHECK(min == 3);
|
||||
CHECK(max == 3);
|
||||
|
||||
}
|
||||
|
||||
|
||||
61
unittest.depend
Обычный файл
61
unittest.depend
Обычный файл
@@ -0,0 +1,61 @@
|
||||
# depslib dependency file v1.0
|
||||
1685890713 source:c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\unittest.cpp
|
||||
"doctest.h"
|
||||
"histogram_internal.h"
|
||||
|
||||
1685890386 c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\doctest.h
|
||||
<signal.h>
|
||||
<ciso646>
|
||||
<cstddef>
|
||||
<ostream>
|
||||
<istream>
|
||||
<type_traits>
|
||||
"doctest_fwd.h"
|
||||
<ctime>
|
||||
<cmath>
|
||||
<climits>
|
||||
<math.h>
|
||||
<new>
|
||||
<cstdio>
|
||||
<cstdlib>
|
||||
<cstring>
|
||||
<limits>
|
||||
<utility>
|
||||
<fstream>
|
||||
<sstream>
|
||||
<iostream>
|
||||
<algorithm>
|
||||
<iomanip>
|
||||
<vector>
|
||||
<atomic>
|
||||
<mutex>
|
||||
<set>
|
||||
<map>
|
||||
<unordered_set>
|
||||
<exception>
|
||||
<stdexcept>
|
||||
<csignal>
|
||||
<cfloat>
|
||||
<cctype>
|
||||
<cstdint>
|
||||
<string>
|
||||
<sys/types.h>
|
||||
<unistd.h>
|
||||
<sys/sysctl.h>
|
||||
<AfxWin.h>
|
||||
<windows.h>
|
||||
<io.h>
|
||||
<sys/time.h>
|
||||
<unistd.h>
|
||||
|
||||
1685888788 c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1685970224 source:c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\histogram.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
"histogram.h"
|
||||
|
||||
1685968632 c:\users\æåñòêèé ï\desktop\ëàáà 1\lab_1\histogram.h
|
||||
<vector>
|
||||
|
||||
20
unittest.layout
Обычный файл
20
unittest.layout
Обычный файл
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="histogram_internal.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<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="227" topLine="3" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="doctest.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
Ссылка в новой задаче
Block a user