TupikovAA 4 недель назад
Родитель 07d213c312
Сommit 98d28fd42b

2
.gitignore поставляемый

@ -1,3 +1,3 @@
/bin
/obj
/curl

@ -0,0 +1,55 @@
#define CURL_STATICLIB // Äëÿ ñòàòè÷åñêîé ëèíêîâêè
#include <curl/curl.h>
#include <sstream>
#include "histogram.h"
#include <iostream>
static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
size_t real_size = size * nmemb;
std::stringstream* buffer = static_cast<std::stringstream*>(userp);
buffer->write(static_cast<const char*>(contents), real_size);
return real_size;
}
Input download(const std::string& url) {
CURL* curl = curl_easy_init();
std::stringstream buffer;
if(!curl) {
std::cerr << "Îøèáêà: íå óäàëîñü èíèöèàëèçèðîâàòü cURL" << std::endl;
exit(EXIT_FAILURE);
}
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
CURLcode res = curl_easy_perform(curl);
if(res != CURLE_OK) {
std::cerr << "Îøèáêà cURL (" << res << "): "
<< curl_easy_strerror(res) << std::endl;
const char* url_info;
if(curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url_info) == CURLE_OK) {
std::cerr << "URL: " << url_info << std::endl;
}
curl_easy_cleanup(curl);
exit(EXIT_FAILURE);
}
if(buffer.str().empty()) {
std::cerr << "Îøèáêà: ïîëó÷åí ïóñòîé îòâåò îò ñåðâåðà" << std::endl;
curl_easy_cleanup(curl);
exit(EXIT_FAILURE);
}
curl_easy_cleanup(curl);
return input_data(buffer, false);
}

@ -47,17 +47,28 @@ std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bi
return bins;
}
Input input_data() {
Input in;
std::cin >> in.number_count;
Input input_data(std::istream& in, bool prompt) { // Áåç = true çäåñü!
Input result;
in.numbers.resize(in.number_count);
for (size_t i = 0; i < in.number_count; i++) {
std::cin >> in.numbers[i];
if (prompt) {
std::cerr << "Ââåäèòå êîëè÷åñòâî ÷èñåë: ";
}
in >> result.number_count;
std::cin >> in.bin_count;
return in;
if (prompt) {
std::cerr << "Ââåäèòå " << result.number_count << " ÷èñåë: ";
}
result.numbers.resize(result.number_count);
for (size_t i = 0; i < result.number_count; i++) {
in >> result.numbers[i];
}
if (prompt) {
std::cerr << "Ââåäèòå êîëè÷åñòâî êîðçèí: ";
}
in >> result.bin_count;
return result;
}
void show_histogram_text(const vector<size_t>& bins, size_t block_width) {

@ -2,6 +2,7 @@
#define HISTOGRAM_H
#include <vector>
#include <iostream>
struct Input {
std::vector<double> numbers;
@ -9,8 +10,11 @@ struct Input {
size_t number_count;
};
Input input_data();
Input input_data(std::istream& in = std::cin, bool prompt = true);
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count);
void show_histogram_text(const std::vector<size_t>& bins, size_t max_width = 80);
Input download(const std::string& url);
#endif

@ -1,13 +1,16 @@
<?xml version='1.0' encoding='UTF-8'?>
<svg width='400' height='300' viewBox='0 0 400 300' xmlns='http://www.w3.org/2000/svg'>
<text x='20' y='35' font-size='14' fill='black'>1</text>
<rect x='50' y='0' width='83.3333' height='30' stroke='#333333' fill='#4CAF50' />
<line x1='50' y1='15' x2='133.333' y2='15' stroke='white' stroke-width='3' stroke-dasharray='20,7' />
<text x='20' y='75' font-size='14' fill='black'>3</text>
<rect x='50' y='40' width='250' height='30' stroke='#333333' fill='#4CAF50' />
<line x1='50' y1='55' x2='300' y2='55' stroke='white' stroke-width='3' stroke-dasharray='20,7' />
<rect x='50' y='0' width='250' height='30' stroke='#333333' fill='#4CAF50' />
<line x1='50' y1='15' x2='300' y2='15' stroke='white' stroke-width='3' stroke-dasharray='6,8' />
<text x='20' y='75' font-size='14' fill='black'>0</text>
<rect x='50' y='40' width='0' height='30' stroke='#333333' fill='#4CAF50' />
<line x1='50' y1='55' x2='50' y2='55' stroke='white' stroke-width='3' stroke-dasharray='6,8' />
<text x='20' y='115' font-size='14' fill='black'>1</text>
<rect x='50' y='80' width='83.3333' height='30' stroke='#333333' fill='#4CAF50' />
<line x1='50' y1='95' x2='133.333' y2='95' stroke='white' stroke-width='3' stroke-dasharray='20,7' />
<rect x='45' y='0' width='260' height='120' fill='none' stroke='black' stroke-width='2'/>
<rect x='50' y='80' width='250' height='30' stroke='#333333' fill='#4CAF50' />
<line x1='50' y1='95' x2='300' y2='95' stroke='white' stroke-width='3' stroke-dasharray='6,8' />
<text x='20' y='155' font-size='14' fill='black'>1</text>
<rect x='50' y='120' width='250' height='30' stroke='#333333' fill='#4CAF50' />
<line x1='50' y1='135' x2='300' y2='135' stroke='white' stroke-width='3' stroke-dasharray='6,8' />
<rect x='45' y='0' width='260' height='160' fill='none' stroke='black' stroke-width='2'/>
</svg>

До

Ширина:  |  Высота:  |  Размер: 942 B

После

Ширина:  |  Высота:  |  Размер: 1.1 KiB

@ -1,14 +1,16 @@
# depslib dependency file v1.0
1750586188 source:c:\users\taa41\desktop\ïðîãà\lab1\main.cpp
1751634290 source:c:\users\taa41\desktop\ďđîăŕ\lab1\main.cpp
<iostream>
<fstream>
"histogram.h"
"svg.h"
<curl/curl.h>
1749173822 c:\users\taa41\desktop\ïðîãà\lab1\histogram.h
1751737430 c:\users\taa41\desktop\ďđîăŕ\lab1\histogram.h
<vector>
<iostream>
1750586035 source:c:\users\taa41\desktop\ïðîãà\lab1\svg.cpp
1750586646 source:c:\users\taa41\desktop\ďđîăŕ\lab1\svg.cpp
"svg.h"
<algorithm>
<string>
@ -19,7 +21,7 @@
<iostream>
<fstream>
1750444430 source:c:\users\taa41\desktop\ïðîãà\lab1\histogram.cpp
1751552407 source:c:\users\taa41\desktop\ďđîăŕ\lab1\histogram.cpp
<iostream>
"histogram.h"
"histogram_internal.h"
@ -30,3 +32,168 @@
1749200462 c:\users\taa41\desktop\ïðîãà\lab1\histogram_internal.h
<vector>
1751736810 source:c:\users\taa41\desktop\ďđîăŕ\lab1\curl_utils.cpp
<curl/curl.h>
<sstream>
"histogram.h"
<iostream>
1751633274 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1\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"
1751633274 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1\include\curl\curlver.h
1751633274 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1\include\curl\system.h
<ConditionalMacros.h>
<inttypes.h>
<inttypes.h>
<sys/types.h>
<sys/socket.h>
<sys/poll.h>
1751633274 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1\include\curl\easy.h
1751633274 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1\include\curl\multi.h
"curl.h"
1751633274 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1\include\curl\urlapi.h
"curl.h"
1751633274 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1\include\curl\options.h
1751633274 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1\include\curl\header.h
1751633274 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1\include\curl\websockets.h
1751633274 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1\include\curl\mprintf.h
<stdarg.h>
<stdio.h>
"curl.h"
1751633274 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1\include\curl\typecheck-gcc.h
1751634753 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1_2-win64a-mingw\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"
1751634753 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1_2-win64a-mingw\include\curl\curlver.h
1751634753 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1_2-win64a-mingw\include\curl\system.h
<ConditionalMacros.h>
<inttypes.h>
<inttypes.h>
<sys/types.h>
<sys/socket.h>
<sys/poll.h>
1751634753 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1_2-win64a-mingw\include\curl\easy.h
1751634753 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1_2-win64a-mingw\include\curl\multi.h
"curl.h"
1751634753 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1_2-win64a-mingw\include\curl\urlapi.h
"curl.h"
1751634753 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1_2-win64a-mingw\include\curl\options.h
1751634753 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1_2-win64a-mingw\include\curl\header.h
1751634753 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1_2-win64a-mingw\include\curl\websockets.h
1751634753 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1_2-win64a-mingw\include\curl\mprintf.h
<stdarg.h>
<stdio.h>
"curl.h"
1751634753 c:\users\taa41\desktop\ďđîăŕ\curl\curl-8.14.1_2-win64a-mingw\include\curl\typecheck-gcc.h
1751635109 c:\curl\curl-8.14.1_2-win64-mingw\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"
1751635109 c:\curl\curl-8.14.1_2-win64-mingw\include\curl\curlver.h
1751635110 c:\curl\curl-8.14.1_2-win64-mingw\include\curl\system.h
<ConditionalMacros.h>
<inttypes.h>
<inttypes.h>
<sys/types.h>
<sys/socket.h>
<sys/poll.h>
1751635109 c:\curl\curl-8.14.1_2-win64-mingw\include\curl\easy.h
1751635110 c:\curl\curl-8.14.1_2-win64-mingw\include\curl\multi.h
"curl.h"
1751635110 c:\curl\curl-8.14.1_2-win64-mingw\include\curl\urlapi.h
"curl.h"
1751635110 c:\curl\curl-8.14.1_2-win64-mingw\include\curl\options.h
1751635110 c:\curl\curl-8.14.1_2-win64-mingw\include\curl\header.h
1751635110 c:\curl\curl-8.14.1_2-win64-mingw\include\curl\websockets.h
1751635110 c:\curl\curl-8.14.1_2-win64-mingw\include\curl\mprintf.h
<stdarg.h>
<stdio.h>
"curl.h"
1751635110 c:\curl\curl-8.14.1_2-win64-mingw\include\curl\typecheck-gcc.h

@ -2,29 +2,29 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="svg.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<File name="svg.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2445" topLine="53" />
<Cursor1 position="966" topLine="0" />
</Cursor>
</File>
<File name="histogram.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram.cpp" open="1" top="1" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="168" topLine="0" />
<Cursor1 position="1932" topLine="0" />
</Cursor>
</File>
<File name="svg.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="862" topLine="0" />
<Cursor1 position="218" topLine="0" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<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="81" topLine="0" />
<Cursor1 position="168" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="1" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="1932" topLine="56" />
<Cursor1 position="1826" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -1,25 +1,61 @@
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "histogram.h"
#include "svg.h"
#include <curl/curl.h>
using namespace std;
int main() {
Input data = input_data();
auto bins = make_histogram(data.numbers, data.bin_count);
static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp) {
size_t real_size = size * nmemb;
stringstream* buffer = static_cast<stringstream*>(userp);
buffer->write(static_cast<const char*>(contents), real_size);
return real_size;
}
int main(int argc, char* argv[]) {
Input download(const std::string& url);
curl_global_init(CURL_GLOBAL_ALL);
Input input;
if(argc > 1) {
try {
input = download(argv[1]);
} catch(const exception& e) {
cerr << "Îøèáêà çàãðóçêè: " << e.what() << endl;
curl_global_cleanup();
return EXIT_FAILURE;
}
} else {
input = input_data(cin, true);
}
auto bins = make_histogram(input.numbers, input.bin_count);
show_histogram_text(bins);
int dash_len, gap_len;
cout << "Enter dash length (e.g., 20): ";
cout << "Ââåäèòå äëèíó øòðèõà (íàïðèìåð, 20): ";
cin >> dash_len;
cout << "Enter gap length (e.g., 10): ";
cout << "Ââåäèòå äëèíó ïðîìåæóòêà (íàïðèìåð, 10): ";
cin >> gap_len;
show_histogram_text(bins);
ofstream svg_file("histogram.svg");
svg::show_histogram_svg(svg_file, bins, dash_len, gap_len);
svg_file.close();
if(svg_file) {
svg::show_histogram_svg(svg_file, bins, dash_len, gap_len);
cout << "Ãèñòîãðàììà ñîõðàíåíà â histogram.svg" << endl;
} else {
cerr << "Îøèáêà: íå óäàëîñü ñîçäàòü ôàéë SVG" << endl;
}
curl_global_cleanup();
return 0;
return EXIT_SUCCESS;
}

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