code: добавлены SVG файлы и измененый код до индивидуальных заданий
Этот коммит содержится в:
@@ -36,7 +36,7 @@ vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count){
|
|||||||
if (!found)
|
if (!found)
|
||||||
bins[bin_count - 1]++;
|
bins[bin_count - 1]++;
|
||||||
}
|
}
|
||||||
int max_count = bins[0];
|
/*int max_count = bins[0];
|
||||||
for (size_t i = 0; i < bin_count; i++) {
|
for (size_t i = 0; i < bin_count; i++) {
|
||||||
if (bins[i] > max_count)
|
if (bins[i] > max_count)
|
||||||
max_count = bins[i];
|
max_count = bins[i];
|
||||||
@@ -47,6 +47,6 @@ vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count){
|
|||||||
size_t height = 76 * (static_cast<double>(count) / max_count);
|
size_t height = 76 * (static_cast<double>(count) / max_count);
|
||||||
bins[i] = height;
|
bins[i] = height;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
return bins;
|
return bins;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,10 @@
|
|||||||
<Option target="<{~None~}>" />
|
<Option target="<{~None~}>" />
|
||||||
</Unit>
|
</Unit>
|
||||||
<Unit filename="main.cpp" />
|
<Unit filename="main.cpp" />
|
||||||
|
<Unit filename="svg.cpp" />
|
||||||
|
<Unit filename="svg.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
<Unit filename="text.cpp" />
|
<Unit filename="text.cpp" />
|
||||||
<Unit filename="text.h">
|
<Unit filename="text.h">
|
||||||
<Option target="<{~None~}>" />
|
<Option target="<{~None~}>" />
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1682090855 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.cpp
|
1682156265 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.cpp
|
||||||
<math.h>
|
<math.h>
|
||||||
<iostream>
|
<iostream>
|
||||||
<conio.h>
|
<conio.h>
|
||||||
<vector>
|
<vector>
|
||||||
"histogram.h"
|
"histogram.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
|
||||||
1681931103 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.h
|
1681931103 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.h
|
||||||
<vector>
|
<vector>
|
||||||
|
|
||||||
1681931332 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\main.cpp
|
1682152541 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\main.cpp
|
||||||
<math.h>
|
<math.h>
|
||||||
<iostream>
|
<iostream>
|
||||||
<conio.h>
|
<conio.h>
|
||||||
<vector>
|
<vector>
|
||||||
"histogram.h"
|
"histogram.h"
|
||||||
"text.h"
|
"text.h"
|
||||||
|
"svg.h"
|
||||||
|
|
||||||
1681931523 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\text.h
|
1681931523 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\text.h
|
||||||
<vector>
|
<vector>
|
||||||
@@ -27,3 +29,16 @@
|
|||||||
<vector>
|
<vector>
|
||||||
"text.h"
|
"text.h"
|
||||||
|
|
||||||
|
1682091658 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram_internal.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1682108195 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\svg.h
|
||||||
|
|
||||||
|
1682156695 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\svg.cpp
|
||||||
|
<math.h>
|
||||||
|
<iostream>
|
||||||
|
<conio.h>
|
||||||
|
<vector>
|
||||||
|
<string>
|
||||||
|
"svg.h"
|
||||||
|
|
||||||
|
|||||||
@@ -2,34 +2,39 @@
|
|||||||
<CodeBlocks_layout_file>
|
<CodeBlocks_layout_file>
|
||||||
<FileVersion major="1" minor="0" />
|
<FileVersion major="1" minor="0" />
|
||||||
<ActiveTarget name="Debug" />
|
<ActiveTarget name="Debug" />
|
||||||
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="text.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="564" topLine="0" />
|
<Cursor1 position="73" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<File name="histogram.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="histogram.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="0" topLine="0" />
|
<Cursor1 position="0" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
|
<File name="histogram.cpp" open="1" top="0" tabpos="6" 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="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="484" topLine="3" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="svg.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="0" topLine="4" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
<File name="text.cpp" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="text.cpp" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="362" topLine="0" />
|
<Cursor1 position="362" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<File name="histogram_internal.h" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="0" topLine="0" />
|
<Cursor1 position="0" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<File name="histogram.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="0" topLine="0" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="text.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="73" topLine="0" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
</CodeBlocks_layout_file>
|
</CodeBlocks_layout_file>
|
||||||
|
|||||||
3
main.cpp
3
main.cpp
@@ -4,6 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
#include "svg.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
struct Input {
|
struct Input {
|
||||||
@@ -31,6 +32,6 @@ input_data(){
|
|||||||
int main() {
|
int main() {
|
||||||
Input in = input_data();
|
Input in = input_data();
|
||||||
auto bins = make_histogramm(in.numbers, in.bin_count);
|
auto bins = make_histogramm(in.numbers, in.bin_count);
|
||||||
show_histogramm(bins);
|
show_histogram_svg(bins);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
56
svg.cpp
Обычный файл
56
svg.cpp
Обычный файл
@@ -0,0 +1,56 @@
|
|||||||
|
#include <math.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <conio.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#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
|
||||||
|
svg_text(double left, double baseline, string text) {
|
||||||
|
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
|
||||||
|
}
|
||||||
|
|
||||||
|
void svg_rect(double x, double y, double width, double height, string colour = "black", string fill = "black"){
|
||||||
|
cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke = '"<<colour <<"' fill = '"<<fill<<"' />";
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
show_histogram_svg(const vector<size_t>& 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;
|
||||||
|
const auto BLOCK_WIDTH = 10;
|
||||||
|
double top = 0;
|
||||||
|
double max_count = bins[0];
|
||||||
|
for (size_t i = 0; i < bins.size(); i++) {
|
||||||
|
if (bins[i] > max_count)
|
||||||
|
max_count = bins[i];
|
||||||
|
}
|
||||||
|
svg_begin(400, 300);
|
||||||
|
for (size_t bin : bins) {
|
||||||
|
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH)*(bin/max_count);
|
||||||
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||||
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#FF00FF");
|
||||||
|
top += BIN_HEIGHT;
|
||||||
|
}
|
||||||
|
svg_end();
|
||||||
|
}
|
||||||
7
svg.h
Обычный файл
7
svg.h
Обычный файл
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef SVG_H_INCLUDED
|
||||||
|
#define SVG_H_INCLUDED
|
||||||
|
|
||||||
|
void
|
||||||
|
show_histogram_svg(const std::vector<size_t>& bins);
|
||||||
|
|
||||||
|
#endif // SVG_H_INCLUDED
|
||||||
@@ -2,16 +2,6 @@
|
|||||||
<CodeBlocks_layout_file>
|
<CodeBlocks_layout_file>
|
||||||
<FileVersion major="1" minor="0" />
|
<FileVersion major="1" minor="0" />
|
||||||
<ActiveTarget name="Debug" />
|
<ActiveTarget name="Debug" />
|
||||||
<File name="doctest.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="histogram_internal.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="97" 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">
|
<File name="histogram.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="0" topLine="23" />
|
<Cursor1 position="0" topLine="23" />
|
||||||
@@ -22,4 +12,14 @@
|
|||||||
<Cursor1 position="414" topLine="0" />
|
<Cursor1 position="414" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
|
<File name="histogram_internal.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="97" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="doctest.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>
|
||||||
</CodeBlocks_layout_file>
|
</CodeBlocks_layout_file>
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user