исправленные тесты + защита 8
Этот коммит содержится в:
7106
doctest.h.txt
7106
doctest.h.txt
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -2,7 +2,10 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
static void find_minmax(const vector<double>& numbers, double& minN, double& maxN){
|
||||
bool find_minmax(vector<double> numbers, double& minN, double& maxN){
|
||||
if (numbers.empty()){
|
||||
return false;
|
||||
}
|
||||
minN = numbers[0];
|
||||
maxN = numbers[0];
|
||||
for (double x : numbers){
|
||||
@@ -13,6 +16,7 @@ static void find_minmax(const vector<double>& numbers, double& minN, double& max
|
||||
maxN = x;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count){
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
std::vector<size_t>
|
||||
make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
||||
bool find_minmax(std::vector<double> numbers, double& minN, double& maxN);
|
||||
|
||||
|
||||
|
||||
|
||||
7
histogram_internal.h
Обычный файл
7
histogram_internal.h
Обычный файл
@@ -0,0 +1,7 @@
|
||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
bool find_minmax(std::vector<double> numbers, double& minN, double& maxN);
|
||||
|
||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
15
lab03.cbp
15
lab03.cbp
@@ -32,7 +32,22 @@
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="histogram_internal.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
|
||||
32
lab03.depend
Обычный файл
32
lab03.depend
Обычный файл
@@ -0,0 +1,32 @@
|
||||
# depslib dependency file v1.0
|
||||
1746452588 source:c:\users\koldinad\desktop\lab03\histogram.cpp
|
||||
"histogram.h"
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1746451370 c:\users\koldinad\desktop\lab03\histogram.h
|
||||
<vector>
|
||||
|
||||
1746452830 source:c:\users\koldinad\desktop\lab03\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
"histogram.h"
|
||||
"text.h"
|
||||
"svg.h"
|
||||
|
||||
1745846054 c:\users\koldinad\desktop\lab03\text.h
|
||||
<vector>
|
||||
|
||||
1745846055 source:c:\users\koldinad\desktop\lab03\text.cpp
|
||||
"text.h"
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1746452588 c:\users\koldinad\desktop\lab03\svg.h
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1746452790 source:c:\users\koldinad\desktop\lab03\svg.cpp
|
||||
"svg.h"
|
||||
<string>
|
||||
|
||||
13
main.cpp
13
main.cpp
@@ -2,11 +2,13 @@
|
||||
#include <vector>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
using namespace std;
|
||||
|
||||
struct Input{
|
||||
vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
size_t font_size{};
|
||||
};
|
||||
Input
|
||||
input_data()
|
||||
@@ -21,6 +23,15 @@ input_data()
|
||||
cin >> in.numbers[i];
|
||||
}
|
||||
cin >> in.bin_count;
|
||||
|
||||
size_t font_size_input = 0;
|
||||
while (font_size_input < 8 || font_size_input > 32) {
|
||||
cerr << "Enter font size (8–32, default is 12): ";
|
||||
cin >> font_size_input;
|
||||
cerr << "Invalid font size. Must be between 8 and 32.\n";
|
||||
}
|
||||
in.font_size = font_size_input;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
@@ -29,5 +40,5 @@ int main()
|
||||
size_t max_count;
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
show_histogram_text(bins, in.bin_count, max_count);
|
||||
show_histogram_svg(bins, in.font_size);
|
||||
}
|
||||
|
||||
11
svg.cpp
11
svg.cpp
@@ -19,8 +19,10 @@ svg_end() {
|
||||
|
||||
//Ïîäïèñè ê ñòîëáöàì
|
||||
void
|
||||
svg_text(double left, double baseline, string text) {
|
||||
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>\n";
|
||||
svg_text(double left, double baseline, string text, size_t font_size) {
|
||||
cout << "<text x='" << left << "' y='" << baseline
|
||||
<< "' font-size='" << font_size
|
||||
<< "'>" << text << "</text>\n";
|
||||
}
|
||||
|
||||
//Âûâîä ïðÿìîóãîëüíèêà
|
||||
@@ -32,7 +34,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, size_t font_size) {
|
||||
const auto IMAGE_WIDTH = 400;
|
||||
const auto IMAGE_HEIGHT = 300;
|
||||
const auto TEXT_LEFT = 20;
|
||||
@@ -41,6 +43,7 @@ show_histogram_svg(const vector<size_t>& bins) {
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
vector<string> colors = {
|
||||
"#F4F2A9",
|
||||
"#ECE1AC",
|
||||
"#ECACD6",
|
||||
"#CEACEC"
|
||||
@@ -50,7 +53,7 @@ show_histogram_svg(const vector<size_t>& bins) {
|
||||
for (size_t i = 0; i < bins.size(); i++) {
|
||||
string color = colors[i];
|
||||
const double bin_width = BLOCK_WIDTH * bins[i];
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i])); //âûâîä ïîäïèñåé
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i]), font_size); //âûâîä ïîäïèñåé
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "#ACB0EC", color); //âûâîä ñòîëáöîâ
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
|
||||
2
svg.h
2
svg.h
@@ -3,5 +3,5 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
void show_histogram_svg(const std::vector<size_t>& bins);
|
||||
void show_histogram_svg(const std::vector<size_t>& bins, size_t font_size);
|
||||
#endif // SVG_H_INCLUDED
|
||||
|
||||
@@ -36,9 +36,7 @@ TEST_CASE("distinct equals numbers")
|
||||
CHECK(max == 1);
|
||||
}
|
||||
TEST_CASE("distinct equals numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1, 2}, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
double min = -1;
|
||||
double max = -1;
|
||||
CHECK(!find_minmax({}, min, max));
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# depslib dependency file v1.0
|
||||
1745847481 source:c:\users\koldinad\desktop\lab03\histogram.cpp
|
||||
1746452588 source:c:\users\koldinad\desktop\lab03\histogram.cpp
|
||||
"histogram.h"
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1745847606 c:\users\koldinad\desktop\lab03\histogram.h
|
||||
1746451370 c:\users\koldinad\desktop\lab03\histogram.h
|
||||
<vector>
|
||||
|
||||
1745847891 source:c:\users\koldinad\desktop\lab03\unittest.cpp
|
||||
1746451448 source:c:\users\koldinad\desktop\lab03\unittest.cpp
|
||||
"doctest.h"
|
||||
"histogram_internal.h"
|
||||
|
||||
@@ -56,6 +56,6 @@
|
||||
<sys/time.h>
|
||||
<unistd.h>
|
||||
|
||||
1745847614 c:\users\koldinad\desktop\lab03\histogram_internal.h
|
||||
1746451281 c:\users\koldinad\desktop\lab03\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user