Сравнить коммиты
7 Коммитов
133ecfbbb6
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 703a7496c9 | |||
| fd47eaab64 | |||
| d11a01d781 | |||
| 40cc4f7fe1 | |||
| 8296a5cc4e | |||
| 82a8d9f469 | |||
| 72c1e547fe |
1
.gitignore
поставляемый
1
.gitignore
поставляемый
@@ -1,2 +1,3 @@
|
||||
/bin
|
||||
/obj
|
||||
/curl
|
||||
|
||||
8
7112
8
7112
@@ -1,8 +0,0 @@
|
||||
-----BEGIN OPENSSH PRIVATE KEY-----
|
||||
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABAqjR8VKL
|
||||
iXqwsebTTkYzLtAAAAGAAAAAEAAAAzAAAAC3NzaC1lZDI1NTE5AAAAIAMVcWMSwkHQ796Q
|
||||
v12uM1/L9QSqCC1guyCtw8nZgqYaAAAAoAX6y1g+sl014TmIQ7zX/gv2ngRTEKBcujJq8O
|
||||
UqkMywAQC10aGheZuBego39vP3S84Tf+kKNzxIUWu+kRpbgi4x2bIc5/kYbYh76DGK+o9z
|
||||
zCGU6ju3j1fNVHknGYkR0aw2SSu9/Q8GjU+xMd5Rdqj567rbHY/w7Qt8ZYImEKVvYoO/6G
|
||||
BenNIJk2c3S/lY26lh51GG9DF9PKMrnWNhZIY=
|
||||
-----END OPENSSH PRIVATE KEY-----
|
||||
1
7112.pub
1
7112.pub
@@ -1 +0,0 @@
|
||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAMVcWMSwkHQ796Qv12uM1/L9QSqCC1guyCtw8nZgqYa aleks@DESKTOP-3A8L66V
|
||||
@@ -2,19 +2,21 @@
|
||||
#include "histogram_internal.h"
|
||||
#include <vector>
|
||||
using std::vector;
|
||||
void find_minmax(const std::vector<double>& numbers, double& min, double& max) {
|
||||
min = numbers[0];
|
||||
void find_minmax(const vector<double>& numbers, double& min, double& max) {
|
||||
if (numbers.empty())
|
||||
{
|
||||
min = 0;
|
||||
max = 0;
|
||||
return;
|
||||
}
|
||||
max = numbers[0];
|
||||
|
||||
for (double number : numbers) {
|
||||
if (number < min) {
|
||||
min = number;
|
||||
}
|
||||
if (number > max) {
|
||||
max = number;
|
||||
}
|
||||
min = numbers[0];
|
||||
for (double x : numbers) {
|
||||
if (x < min) min = x;
|
||||
else if (x > max) max = x;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count) {
|
||||
std::vector<size_t> bins(bin_count, 0);
|
||||
|
||||
|
||||
98
laba1.depend
98
laba1.depend
@@ -1,10 +1,11 @@
|
||||
# depslib dependency file v1.0
|
||||
1748812442 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\main.cpp
|
||||
1748850108 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
"histogram.h"
|
||||
"text.h"
|
||||
"svg.h"
|
||||
<curl/curl.h>
|
||||
|
||||
1748386910 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram.h
|
||||
<vector>
|
||||
@@ -78,3 +79,98 @@
|
||||
"histogram_internal.h"
|
||||
<vector>
|
||||
|
||||
1748808114 D
|
||||
|
||||
1748875465 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram.cpp
|
||||
"histogram.h"
|
||||
"histogram_internal.h"
|
||||
<vector>
|
||||
|
||||
1748386910 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram.h
|
||||
<vector>
|
||||
|
||||
1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1749630788 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
<string>
|
||||
"histogram.h"
|
||||
"text.h"
|
||||
"svg.h"
|
||||
"histogram_internal.h"
|
||||
|
||||
1748730472 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\text.h
|
||||
<vector>
|
||||
|
||||
1749627429 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.h
|
||||
<vector>
|
||||
<cstddef>
|
||||
|
||||
1748808306 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\text.cpp
|
||||
"text.h"
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1749628551 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.cpp
|
||||
"svg.h"
|
||||
<iostream>
|
||||
|
||||
1748876656
|
||||
|
||||
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\curl.h
|
||||
"curlver.h"
|
||||
"system.h"
|
||||
<stdio.h>
|
||||
<limits.h>
|
||||
<sys/param.h>
|
||||
<sys/types.h>
|
||||
<time.h>
|
||||
<winsock2.h>
|
||||
<ws2tcpip.h>
|
||||
<sys/select.h>
|
||||
<sys/socket.h>
|
||||
<sys/time.h>
|
||||
"easy.h"
|
||||
"multi.h"
|
||||
"urlapi.h"
|
||||
"options.h"
|
||||
"header.h"
|
||||
"websockets.h"
|
||||
"mprintf.h"
|
||||
"typecheck-gcc.h"
|
||||
|
||||
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\curlver.h
|
||||
|
||||
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\system.h
|
||||
<ConditionalMacros.h>
|
||||
<inttypes.h>
|
||||
<inttypes.h>
|
||||
<sys/types.h>
|
||||
<sys/socket.h>
|
||||
<sys/poll.h>
|
||||
|
||||
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\easy.h
|
||||
|
||||
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\multi.h
|
||||
"curl.h"
|
||||
|
||||
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\urlapi.h
|
||||
"curl.h"
|
||||
|
||||
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\options.h
|
||||
|
||||
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\header.h
|
||||
|
||||
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\websockets.h
|
||||
|
||||
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\mprintf.h
|
||||
<stdarg.h>
|
||||
<stdio.h>
|
||||
"curl.h"
|
||||
|
||||
1748849797 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\curl\include\curl\typecheck-gcc.h
|
||||
|
||||
1748849797 c4f7fe14afe3358e7b9d7bc3578a9c995ebd7
|
||||
|
||||
|
||||
23
main.cpp
23
main.cpp
@@ -1,24 +1,23 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
#include "histogram_internal.h"
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
struct Input {
|
||||
std::vector<double> numbers;
|
||||
vector<double> numbers;
|
||||
size_t bin_count;
|
||||
};
|
||||
|
||||
// Ââîä äàííûõ
|
||||
Input input_data() {
|
||||
Input in;
|
||||
size_t number_count;
|
||||
|
||||
cerr << "Enter number count: ";
|
||||
cin >> number_count;
|
||||
|
||||
in.numbers.resize(number_count);
|
||||
|
||||
cerr << "Enter numbers: ";
|
||||
@@ -27,24 +26,14 @@ Input input_data() {
|
||||
}
|
||||
|
||||
cerr << "Enter bin count: ";
|
||||
cin >> in.bin_count;
|
||||
cin >> in.bin_count; // You were missing this line to read bin_count
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
// Ïîèñê ìèíèìóìà è ìàêñèìóìà
|
||||
|
||||
|
||||
// Ðàñ÷¸ò ãèñòîãðàììû
|
||||
|
||||
|
||||
// Âûâîä ãèñòîãðàììû
|
||||
|
||||
|
||||
// Îñíîâíàÿ ôóíêöèÿ
|
||||
int main() {
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
auto bins = make_histogram(in.numbers, in.bin_count); // Added second argument
|
||||
show_histogram_svg(bins);
|
||||
return 0;
|
||||
}
|
||||
|
||||
78
svg.cpp
78
svg.cpp
@@ -1,66 +1,64 @@
|
||||
#include "svg.h"
|
||||
#include<iostream>
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
using namespace std;
|
||||
void
|
||||
svg_begin(double width, double height) {
|
||||
|
||||
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";
|
||||
cout << "<svg width='" << width << "' height='" << height << "' "
|
||||
<< "viewBox='0 0 " << width << " " << height << "' "
|
||||
<< "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||
|
||||
// Ñòèëè äëÿ SVG
|
||||
cout << "<style>\n"
|
||||
<< " .bar-green { fill: #4CAF50; stroke: #388E3C; stroke-width: 1; }\n"
|
||||
<< " .bar-red { fill: #F44336; stroke: #D32F2F; stroke-width: 1; }\n"
|
||||
<< " .text { font: 12px sans-serif; fill: #333; }\n"
|
||||
<< "</style>\n";
|
||||
}
|
||||
|
||||
void
|
||||
svg_end() {
|
||||
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_text(double left, double baseline, string text) {
|
||||
cout << "<text class='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 svg_rect(double x, double y, double width, double height, bool is_above_average) {
|
||||
string bar_class = is_above_average ? "bar-red" : "bar-green";
|
||||
cout << "<rect class='" << bar_class << "' x='" << x << "' y='" << y
|
||||
<< "' width='" << width << "' height='" << height << "' />";
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
show_histogram_svg(const vector<size_t>& bins)
|
||||
{
|
||||
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 YELLOW = "yellow";
|
||||
const auto PURPLE = "purple";
|
||||
const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
|
||||
const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH;
|
||||
|
||||
|
||||
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
|
||||
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];
|
||||
}
|
||||
size_t max_count = 0;
|
||||
for (size_t count : bins) {
|
||||
if (count > max_count) max_count = count;
|
||||
}
|
||||
|
||||
for (size_t bin : bins)
|
||||
{
|
||||
double bin_width = (MAX_WIDTH)*(bin/max_count);
|
||||
// Âû÷èñëÿåì ñðåäíþþ âûñîòó ñòîëáöà
|
||||
double average_height = 0;
|
||||
if (!bins.empty()) {
|
||||
average_height = accumulate(bins.begin(), bins.end(), 0.0) / bins.size();
|
||||
}
|
||||
|
||||
for (size_t bin : bins) {
|
||||
const double bin_width = MAX_WIDTH * (static_cast<double>(bin) / max_count);
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, YELLOW, PURPLE);
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, bin > average_height);
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,4 +53,10 @@ TEST_CASE("vector with zero") {
|
||||
CHECK(min == -1);
|
||||
CHECK(max == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("empty vector") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({}, min, max);
|
||||
CHECK(min == 0);
|
||||
CHECK(max == 0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# depslib dependency file v1.0
|
||||
1748392121 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram.cpp
|
||||
1748808114 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram.cpp
|
||||
"histogram.h"
|
||||
"histogram_internal.h"
|
||||
<vector>
|
||||
|
||||
1748386910 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram.h
|
||||
@@ -58,11 +59,79 @@
|
||||
1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1748802937 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\svg.cpp
|
||||
1748811805 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\svg.cpp
|
||||
"svg.h"
|
||||
<iostream>
|
||||
|
||||
1748730522 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\svg.h
|
||||
1748810901 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1\svg.h
|
||||
<vector>
|
||||
<cstddef>
|
||||
|
||||
1748875465 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram.cpp
|
||||
"histogram.h"
|
||||
"histogram_internal.h"
|
||||
<vector>
|
||||
|
||||
1748386910 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram.h
|
||||
<vector>
|
||||
|
||||
1748392232 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1749628551 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.cpp
|
||||
"svg.h"
|
||||
<iostream>
|
||||
|
||||
1749627429 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\svg.h
|
||||
<vector>
|
||||
<cstddef>
|
||||
|
||||
1748875527 source:c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\unittest.cpp
|
||||
"doctest.h"
|
||||
"histogram_internal.h"
|
||||
|
||||
1748392747 c:\users\aleks\onedrive\Ðàáî÷èé ñòîë\laba1 — êîïèÿbb\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>
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user