Сравнить коммиты
7 Коммитов
be6059fb6c
...
master
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 06dd40b9dd | |||
| 5240446cfa | |||
| bca4632c89 | |||
| 2825a9dc08 | |||
| 19fbaf3a4d | |||
| 744f381e19 | |||
| 3339fa726a |
2
LR3/.gitignore
поставляемый
2
LR3/.gitignore
поставляемый
@@ -2,3 +2,5 @@
|
||||
/obj
|
||||
/LR3.depend
|
||||
/LR3.layout
|
||||
/curl/
|
||||
/unittest.layout
|
||||
|
||||
@@ -13,7 +13,12 @@
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
<Add directory="C:/Users/daemo/OneDrive/Рабочий стол/lab03/LR3/curl/include" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add library="libcurl.dll.a" />
|
||||
<Add directory="C:/Users/daemo/OneDrive/Рабочий стол/lab03/LR3/curl/lib" />
|
||||
</Linker>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/LR3" prefix_auto="1" extension_auto="1" />
|
||||
|
||||
@@ -5,8 +5,13 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
bool
|
||||
find_minmax(vector<double> numbers, double& min, double& max) {
|
||||
if (numbers.empty()) {
|
||||
min = max = 0;
|
||||
return false;
|
||||
}
|
||||
else{
|
||||
min = numbers[0];
|
||||
max = numbers[0];
|
||||
for (double x : numbers) {
|
||||
@@ -17,6 +22,8 @@ find_minmax(vector<double> numbers, double& min, double& max) {
|
||||
max = x;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
vector<size_t>
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
bool
|
||||
find_minmax(vector<double> numbers, double& min, double& max);
|
||||
|
||||
95
LR3/main.cpp
95
LR3/main.cpp
@@ -3,33 +3,94 @@
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
#include <curl/curl.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
|
||||
struct Input{
|
||||
vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
};
|
||||
|
||||
Input
|
||||
input_data(){
|
||||
Input in;
|
||||
size_t number_count;
|
||||
cin >> number_count;
|
||||
in.numbers.resize(number_count);
|
||||
for (size_t i = 0; i < number_count; i++) {
|
||||
cin >> in.numbers[i];
|
||||
}
|
||||
cin >> in.bin_count;
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
input_data(istream& in, bool prompt)
|
||||
{
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
Input cin;
|
||||
string numbCntPrmt, numbsPrmt, binCntPrmt;
|
||||
if (prompt == true) {
|
||||
numbCntPrmt = "Enter number count: ";
|
||||
numbsPrmt = "Enter numbers: ";
|
||||
binCntPrmt = "Enter bin count: ";
|
||||
}
|
||||
size_t number_count;
|
||||
cerr << numbCntPrmt;
|
||||
in >> number_count;
|
||||
cin.numbers.resize(number_count);
|
||||
|
||||
vector<double> numbers(number_count);
|
||||
|
||||
cerr << numbsPrmt;
|
||||
for (size_t i = 0; i < number_count; i++)
|
||||
{
|
||||
in >> cin.numbers[i];
|
||||
}
|
||||
|
||||
cerr << binCntPrmt;
|
||||
in >> cin.bin_count;
|
||||
return cin;
|
||||
}
|
||||
|
||||
size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
||||
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) {
|
||||
curl_off_t ul;
|
||||
res = curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD_T, &ul);
|
||||
}
|
||||
|
||||
if (res != 0){
|
||||
cerr << 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);
|
||||
}
|
||||
auto bins = make_histogram(input.numbers, input.bin_count);
|
||||
show_histogram_svg(bins);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
|
||||
svg_begin(double width, double height) {
|
||||
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||
cout << "<svg ";
|
||||
@@ -11,6 +12,7 @@ svg_begin(double width, double height) {
|
||||
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||
}
|
||||
|
||||
|
||||
void svg_end() {
|
||||
cout << "</svg>\n";
|
||||
}
|
||||
@@ -19,6 +21,7 @@ void svg_text(double left, double baseline, string text) {
|
||||
cout << "<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
|
||||
|
||||
@@ -27,3 +27,18 @@ TEST_CASE("
|
||||
CHECK(min == -2);
|
||||
CHECK(max == -1);
|
||||
}
|
||||
|
||||
TEST_CASE("îäèíàêîâûå ÷èñëà")
|
||||
{
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1, 1}, min, max);
|
||||
CHECK(min == max);
|
||||
}
|
||||
|
||||
TEST_CASE("distinct equals numbers")
|
||||
{
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
CHECK(!find_minmax({}, min, max));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# depslib dependency file v1.0
|
||||
1748202161 source:c:\users\daemo\onedrive\Ðàáî÷èé ñòîë\lab03\lr3\histogram.cpp
|
||||
1748284319 source:c:\users\daemo\onedrive\Ðàáî÷èé ñòîë\lab03\lr3\histogram.cpp
|
||||
"histogram.h"
|
||||
"histogram_internal.h"
|
||||
<vector>
|
||||
@@ -7,6 +7,6 @@
|
||||
1748199863 c:\users\daemo\onedrive\Ðàáî÷èé ñòîë\lab03\lr3\histogram.h
|
||||
<vector>
|
||||
|
||||
1748202619 c:\users\daemo\onedrive\Ðàáî÷èé ñòîë\lab03\lr3\histogram_internal.h
|
||||
1748284462 c:\users\daemo\onedrive\Ðàáî÷èé ñòîë\lab03\lr3\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user