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

...

2 Коммитов

Автор SHA1 Сообщение Дата
Alice (VasinaEY) 71d0c43a9b добавили svg
2 месяцев назад
lab34 (VasinaEY) 2e7e252bff добавили svg
2 месяцев назад

@ -1,6 +1,6 @@
#include "histogram.h"
void find_minmax(std::vector<double> vec, double& min, double& max) {
void find_minmax(vector<double> vec, double& min, double& max) {
min = vec[0];

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

@ -32,7 +32,13 @@
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<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>

@ -2,9 +2,9 @@
#include <vector>
#include "histogram.h"
#include "text.h"
#include "svg.h"
struct Input {
std::vector<double> numbers;
vector<double> numbers;
size_t bin_count{};
};
@ -12,18 +12,18 @@ Input input_data() {
Input in;
size_t number_count;
std::cerr << "Enter the number of elements: ";
std::cin >> number_count;
cerr << "Enter the number of elements: ";
cin >> number_count;
in.numbers.resize(number_count);
std::cerr << "\nEnter " << number_count << " elements:" << std::endl;
cerr << "\nEnter " << number_count << " elements:" << endl;
for (size_t i = 0; i < number_count; i++) {
std::cin >> in.numbers[i];
cin >> in.numbers[i];
}
std::cerr << "Enter the number of bins: ";
std::cin >> in.bin_count;
cerr << "Enter the number of bins: ";
cin >> in.bin_count;
return in;
}
@ -31,6 +31,6 @@ Input input_data() {
int main() {
auto in = input_data();
auto bins = make_histogram(in.bin_count, in.numbers);
show_histogram(bins);
show_histogram_svg(bins);
return 0;
}

@ -0,0 +1,73 @@
#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 stroke = "black", string fill = "black")
{
cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke='"<<stroke<<"' 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;
const auto YELLOW = "yellow";
const auto PURPLE = "purple";
const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
double top = 0;
double max_count = bins[0];
for (size_t i = 0; i < bins.size(); i++)
{
if (max_count<bins[i])
{
max_count=bins[i];
}
}
for (size_t bin : bins)
{
double bin_width = (MAX_WIDTH)*(bin/max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, YELLOW, PURPLE);
top += BIN_HEIGHT;
}
svg_end();
}

11
svg.h

@ -0,0 +1,11 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
void show_histogram_svg(const vector<size_t>& bins);
#endif // SVG_H_INCLUDED

@ -1,7 +1,7 @@
#include "text.h"
#include <iostream>
void show_histogram(const vector<size_t>& bins) {
void show_histogram(const std::vector<size_t>& bins) {
bool gigant = false;

@ -2,7 +2,7 @@
#define TEXT_H_INCLUDED
#include <vector>
void show_histogram(const vector<size_t>& bins);
using namespace std;
void show_histogram(const std::vector<size_t>& bins);
#endif // TEXT_H_INCLUDED

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

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

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

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

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

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

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

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

@ -31,6 +31,19 @@
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="../doctest.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="../histogram.cpp" />
<Unit filename="../histogram.h" />
<Unit filename="../marks.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="../svg.cpp" />
<Unit filename="../svg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="../unittest.cpp" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>

@ -1,12 +1,12 @@
# depslib dependency file v1.0
1748213255 source:c:\users\home\desktop\lab34\laba01\histogram.cpp
1748243702 source:c:\users\home\desktop\lab34\laba01\histogram.cpp
"histogram.h"
1748213210 c:\users\home\desktop\lab34\laba01\histogram.h
1748243652 c:\users\home\desktop\lab34\laba01\histogram.h
<vector>
<iostream>
1748213127 source:c:\users\home\desktop\lab34\laba01\unittest.cpp
1748213519 source:c:\users\home\desktop\lab34\laba01\unittest.cpp
"doctest.h"
"histogram_internal.h"
@ -55,5 +55,81 @@
<sys/time.h>
<unistd.h>
1748213259 c:\users\home\desktop\lab34\laba01\histogram_internal.h
1748243717 c:\users\home\desktop\lab34\laba01\histogram_internal.h
1748242437 source:c:\users\home\desktop\lab34\laba01\svg.cpp
"svg.h"
1748242437 c:\users\home\desktop\lab34\laba01\svg.h
<iostream>
<vector>
<string>
<math.h>
1748243704 source:c:\users\u111-15\desktop\lab34\laba01\histogram.cpp
"histogram.h"
1748243654 c:\users\u111-15\desktop\lab34\laba01\histogram.h
<vector>
<iostream>
1748386434 source:c:\users\u111-15\desktop\lab34\laba01\svg.cpp
"svg.h"
1748242438 c:\users\u111-15\desktop\lab34\laba01\svg.h
<iostream>
<vector>
<string>
<math.h>
1748213520 source:c:\users\u111-15\desktop\lab34\laba01\unittest.cpp
"doctest.h"
"histogram_internal.h"
1748430259 c:\users\u111-15\desktop\lab34\laba01\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>
1748243718 c:\users\u111-15\desktop\lab34\laba01\histogram_internal.h

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="..\histogram.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="227" topLine="0" />
</Cursor>
</File>
<File name="..\unittest.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1327" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Загрузка…
Отмена
Сохранить