Сравнить коммиты
8 Коммитов
0b29726755
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
90eca7b315 | ||
|
|
d799078416 | ||
|
|
58059fb68e | ||
|
|
87b36b3fff | ||
|
|
6a5f77f201 | ||
|
|
b817e966c5 | ||
|
|
ce0a6677e3 | ||
|
|
5209da476a |
1
.gitignore
поставляемый
1
.gitignore
поставляемый
@@ -1,5 +1,6 @@
|
||||
/bin
|
||||
/obj
|
||||
/curl
|
||||
/lab01.depend
|
||||
/lab01.layout
|
||||
/unittest.depend
|
||||
|
||||
@@ -31,7 +31,12 @@
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
<Add directory="curl/include" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add library="C:/Users/ASUS X507UF/Desktop/РПОСУ/lab01/curl/lib/libcurl.dll.a" />
|
||||
<Add directory="curl/lib" />
|
||||
</Linker>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h">
|
||||
<Option target="<{~None~}>" />
|
||||
|
||||
62
main.cpp
62
main.cpp
@@ -1,5 +1,8 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <curl/curl.h>
|
||||
#include "histogram.h"
|
||||
#include "svg.h"
|
||||
|
||||
@@ -12,25 +15,66 @@ struct Input
|
||||
};
|
||||
|
||||
Input
|
||||
input_data()
|
||||
input_data(istream& stream, bool prompt)
|
||||
{
|
||||
size_t number_count;
|
||||
cerr << "Enter number count: ";
|
||||
cin >> number_count;
|
||||
if (prompt) {
|
||||
cerr << "Enter number count: ";
|
||||
}
|
||||
stream >> number_count;
|
||||
Input in;
|
||||
in.numbers.resize(number_count);
|
||||
for (size_t i = 0; i < number_count; i++)
|
||||
{
|
||||
cin >> in.numbers[i];
|
||||
stream >> in.numbers[i];
|
||||
}
|
||||
cerr << "Enter bin count: ";
|
||||
cin >> in.bin_count;
|
||||
if (prompt) {
|
||||
cerr << "Enter bin count: ";
|
||||
}
|
||||
stream >> in.bin_count;
|
||||
return in;
|
||||
}
|
||||
|
||||
int main()
|
||||
size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx)
|
||||
{
|
||||
Input in = input_data();
|
||||
vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
||||
size_t data_size = item_size * item_count;
|
||||
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
||||
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
||||
return data_size;
|
||||
}
|
||||
|
||||
Input download(const string& address) {
|
||||
stringstream buffer;
|
||||
CURL* curl = curl_easy_init();
|
||||
if (curl) {
|
||||
CURLcode res;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||
res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK) {
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||
exit(1);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
return input_data(buffer, false);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
Input input;
|
||||
if (argc > 1) {
|
||||
input = download(argv[1]);
|
||||
}
|
||||
else {
|
||||
input = input_data(cin, true);
|
||||
}
|
||||
if (curl_version_info(CURLVERSION_NOW) != nullptr) {
|
||||
auto curl_ver = curl_version_info(CURLVERSION_NOW)->version;
|
||||
cerr << "cURL version " << curl_ver << "\n";
|
||||
auto ssl_ver = curl_version_info(CURLVERSION_NOW)->ssl_version;
|
||||
cerr << "SSL version " << ssl_ver << "\n";
|
||||
} else{ cerr<<"curl_version_info() failed \n"; }
|
||||
vector<size_t> bins = make_histogram(input.numbers, input.bin_count);
|
||||
show_histogram_svg(bins);
|
||||
}
|
||||
|
||||
18
svg.cpp
18
svg.cpp
@@ -5,14 +5,6 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool
|
||||
check_width(double width) {
|
||||
if (width >= 3 && width <= 30)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
svg_text(double left, double baseline, string text) {
|
||||
cout << "<text x='" << left
|
||||
@@ -55,16 +47,8 @@ show_histogram_svg(const vector<size_t>& bins) {
|
||||
const auto TEXT_BASELINE = 20;
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
double BLOCK_WIDTH = 0;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH;
|
||||
cerr << "Enter block width: ";
|
||||
cin >> BLOCK_WIDTH;
|
||||
bool check = check_width(BLOCK_WIDTH);
|
||||
while (!check) {
|
||||
cerr << "Incorrectly enter. The block width must be >= 3px and <= 30 px. Please try again." << endl;
|
||||
cin >> BLOCK_WIDTH;
|
||||
check = check_width(BLOCK_WIDTH);
|
||||
}
|
||||
size_t max_count = 0;
|
||||
for (size_t x : bins) {
|
||||
if (x > max_count) {
|
||||
|
||||
11
unittest.cpp
11
unittest.cpp
@@ -2,7 +2,6 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
#include "svg_internal.h"
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double min = 0;
|
||||
@@ -53,13 +52,3 @@ TEST_CASE("empty vector") {
|
||||
CHECK(min == 0);
|
||||
CHECK(max == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("correct block width") {
|
||||
bool check = check_width(23.5);
|
||||
CHECK(check == true);
|
||||
}
|
||||
|
||||
TEST_CASE("incorrect block width") {
|
||||
bool check = check_width(59);
|
||||
CHECK(check == false);
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user