GaidaiAS 5 дней назад
Родитель 30b4711b88
Сommit 99972b93c5

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

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

@ -18,9 +18,6 @@ Input input_data(std::istream& in, bool prompt) {
if (prompt) std::cerr << "Enter bin count: "; if (prompt) std::cerr << "Enter bin count: ";
in >> data.bin_count; in >> data.bin_count;
if (prompt) std::cerr << "Enter text width : ";
in >> data.width;
return data; return data;
} }

@ -5,7 +5,6 @@
struct Input { struct Input {
std::vector<double> numbers; std::vector<double> numbers;
size_t bin_count{}; size_t bin_count{};
int width;
}; };
Input input_data(std::istream& in, bool prompt); Input input_data(std::istream& in, bool prompt);

@ -34,13 +34,14 @@
1746175715 source:c:\users\gajda\onedrive\Đŕáî÷čé ńňîë\lab03\alex\project\text.cpp 1746175715 source:c:\users\gajda\onedrive\Đŕáî÷čé ńňîë\lab03\alex\project\text.cpp
"text.h" "text.h"
1749605127 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\main.cpp 1749674358 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\main.cpp
"histogram.h" "histogram.h"
"svg.h" "svg.h"
<sstream> <sstream>
<curl/curl.h> <curl/curl.h>
<string>
1749593919 c:\mpei\programming\c++ 2sem\lab03\alex\project\histogram.h 1749672481 c:\mpei\programming\c++ 2sem\lab03\alex\project\histogram.h
<iostream> <iostream>
<vector> <vector>
@ -48,16 +49,16 @@
<iostream> <iostream>
<vector> <vector>
1749584700 c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.h 1749672481 c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.h
<vector> <vector>
<iostream> <iostream>
1749596419 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\histogram.cpp 1749673891 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\histogram.cpp
"histogram.h" "histogram.h"
<iostream> <iostream>
<limits> <limits>
1749584700 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.cpp 1749672481 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.cpp
"svg.h" "svg.h"
"text.h" "text.h"

@ -2,20 +2,47 @@
#include "svg.h" #include "svg.h"
#include <sstream> #include <sstream>
#include <curl/curl.h> #include <curl/curl.h>
#include <string>
int main(int argc, char* argv[]) { size_t write_data(void* ptr, size_t size, size_t nmemb, std::stringstream* stream) {
if(argc > 1) { size_t data_size = size * nmemb;
std::cout << "Number of arguments (argc): " << argc << std::endl; stream->write(static_cast<const char*>(ptr), data_size);
for (int i = 0; i < argc; ++i) { return data_size;
std::cout << "argv[" << i << "] = " << argv[i] << std::endl;
} }
return 0;
Input download(const std::string& url) {
std::stringstream buffer;
CURL* curl = curl_easy_init();
if (!curl) {
std::cerr << "Failed to initialize cURL\n";
exit(1);
} }
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
CURLcode res = curl_easy_perform(curl);
if (res != CURLE_OK) {
std::cerr << "cURL error: " << curl_easy_strerror(res) << "\n";
exit(1);
}
curl_easy_cleanup(curl);
return input_data(buffer, false);
}
int main(int argc, char* argv[]) {
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
auto in = input_data(std::cin, true);
auto bins = make_histogram(in.numbers, in.bin_count); Input input;
show_histogram_svg(bins, in.width); if (argc > 1) {
input = download(argv[1]);
} else {
input = input_data(std::cin, true);
}
auto bins = make_histogram(input.numbers, input.bin_count);
show_histogram_svg(bins);
curl_global_cleanup(); curl_global_cleanup();
return 0; return 0;
} }

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

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

@ -13,21 +13,25 @@ void svg_end() {
std::cout << "</svg>\n"; std::cout << "</svg>\n";
} }
void svg_text(double left, double baseline, std::string text) { void svg_text(double left, double baseline, std::string text) {
std::cout << "<text x='" << left << "' y='"<< baseline <<"'>" << text<<"</text>"; std::cout << "<text x='" << left << "' y='" << baseline
<< "' font-family='Arial' font-size='12' fill='black'>"
<< text << "</text>";
} }
void show_histogram_svg(const std::vector<size_t>& bins, int TEXT_WIDTH) { void show_histogram_svg(const std::vector<size_t>& bins) {
const auto IMAGE_WIDTH = 400; const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300; const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20; const auto TEXT_LEFT = 20;
const auto TEXT_BASELINE = 20; const auto TEXT_BASELINE = 20;
const auto BIN_HEIGHT = 30; const auto BIN_HEIGHT = 30;
const auto TEXT_GAP = 10; const auto TEXT_GAP = 10;
const auto TEXT_WIDTH = 50;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
size_t maxCount = maxBin(bins); size_t maxCount = maxBin(bins);
double top = 0; double top = 0;
double current_y = TEXT_GAP;
for (size_t bin : bins) { for (size_t bin : bins) {
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH - TEXT_GAP) * (bin / double(maxCount)); const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH - TEXT_GAP) * (bin / double(maxCount));
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));

@ -5,7 +5,7 @@
#include <iostream> #include <iostream>
void svg_begin(double width, double height); void svg_begin(double width, double height);
void svg_end(); void svg_end();
void show_histogram_svg(const std::vector<size_t>& bins, int width); void show_histogram_svg(const std::vector<size_t>& bins);
void svg_text(double left, double baseline, std::string text); void svg_text(double left, double baseline, std::string text);
void svg_rect(double x, double y, double width, double height,std::string stroke, std::string fills); void svg_rect(double x, double y, double width, double height,std::string stroke, std::string fills);

Загрузка…
Отмена
Сохранить