индивидуальное задание

master
LedovskojMM 2 лет назад
Родитель 5328947674
Сommit 5bfd1b3ef9

@ -6,7 +6,13 @@
#include <conio.h> #include <conio.h>
using namespace std; using namespace std;
/*void find_minmax(vector<double> numbers, double& min, double& max) { /*bool find_minmax(vector<double> numbers, double& min, double& max) {
if (numbers.empty())
{
return true;
}
else
{
min = numbers[0]; min = numbers[0];
for (auto i = 0; i < numbers.size(); i++) { for (auto i = 0; i < numbers.size(); i++) {
if (numbers[i] < min) { if (numbers[i] < min) {
@ -20,7 +26,8 @@ using namespace std;
max = numbers[i]; max = numbers[i];
} }
} }
}
return false;
} }
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) { vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
@ -113,3 +120,4 @@ vector<size_t> make_histogram (vector<double> numbers, size_t bin_count)
return bins; return bins;
} }

@ -2,8 +2,9 @@
#define HISTOGAM_INTERNAL_H_INCLUDED #define HISTOGAM_INTERNAL_H_INCLUDED
#include <vector> #include <vector>
/*
void find_minmax(std::vector<double> numbers, double& min, double& max); void find_minmax(std::vector<double> numbers, double& min, double& max);
/*bool find_minmax(std::vector<double> numbers, double& min, double& max);
*/ */
void find_minmax(std::vector<double> numbers, double& min, double& max);
#endif // HISTOGAM_INTERNAL_H_INCLUDED #endif // HISTOGAM_INTERNAL_H_INCLUDED

@ -3,22 +3,24 @@
<iostream> <iostream>
<vector> <vector>
1685897816 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\main.cpp 1685968543 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\main.cpp
<iostream> <iostream>
<vector> <vector>
<cmath> <cmath>
<string> <string>
"histogam.h" "histogam.h"
"text.h" "text.h"
"svg.h"
<conio.h> <conio.h>
"histogam_internal.h" "histogam_internal.h"
<curl/curl.h> <curl/curl.h>
<sstream>
<string>
"svg.h"
1685896776 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.h 1685967301 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.h
<vector> <vector>
1685896777 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.cpp 1685967301 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.cpp
<iostream> <iostream>
<vector> <vector>
<cmath> <cmath>
@ -26,7 +28,7 @@
"histogam_internal.h" "histogam_internal.h"
<conio.h> <conio.h>
1685896776 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\text.cpp 1685967301 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\text.cpp
<iostream> <iostream>
<vector> <vector>
<cmath> <cmath>
@ -36,10 +38,10 @@
1685896777 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\text.h 1685896777 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\text.h
<vector> <vector>
1685896777 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam_internal.h 1685967301 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam_internal.h
<vector> <vector>
1685896777 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\svg.cpp 1685967301 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\svg.cpp
<math.h> <math.h>
<iostream> <iostream>
<conio.h> <conio.h>
@ -47,7 +49,7 @@
<string> <string>
"svg.h" "svg.h"
1685896776 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\svg.h 1685967301 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\svg.h
1685361112 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\curl\include\curl\curl.h 1685361112 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\curl\include\curl\curl.h
"curlver.h" "curlver.h"

@ -4,12 +4,12 @@
#include <string> #include <string>
#include "histogam.h" #include "histogam.h"
#include "text.h" #include "text.h"
#include "svg.h"
#include <conio.h> #include <conio.h>
#include "histogam_internal.h" #include "histogam_internal.h"
#include <curl/curl.h> #include <curl/curl.h>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include "svg.h"
using namespace std; using namespace std;
@ -45,7 +45,8 @@ int main()
return 0; return 0;
} }
*/ */
struct Input { struct Input
{
vector<double> numbers; vector<double> numbers;
size_t bin_count{}; size_t bin_count{};
}; };
@ -65,7 +66,10 @@ input_data(istream& in, bool promt)
{ {
in >> ik.numbers[i]; in >> ik.numbers[i];
} }
if (promt)
{
cerr << "Enter bin count: "; cerr << "Enter bin count: ";
}
in>> ik.bin_count; in>> ik.bin_count;
return ik; return ik;
} }
@ -74,8 +78,8 @@ size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx)
{ {
size_t data_size = item_size * item_count; size_t data_size = item_size * item_count;
stringstream* buffer = reinterpret_cast<stringstream*>(ctx); stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
buffer->write(static_cast<const char*>(items), data_size); buffer->write(reinterpret_cast<const char*>(items), data_size);
return 0; return data_size;
} }
@ -87,18 +91,25 @@ stringstream buffer;
if(curl) if(curl)
{ {
CURLcode res; CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, address); curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res != CURLE_OK) if (res != CURLE_OK)
{ {
cout << curl_easy_strerror; fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
exit(1); exit(1);
} }
if(res == CURLE_OK)
{
long req;
res = curl_easy_getinfo(curl, CURLINFO_REQUEST_SIZE, &req);
if(!res)
cerr<<"Request size: %ld bytes: "<< req;
} }
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_cleanup(curl);
}
return input_data(buffer, false); return input_data(buffer, false);
} }
@ -118,3 +129,4 @@ int main(int argc, char* argv[])
const auto bins = make_histogram(input.numbers, input.bin_count); const auto bins = make_histogram(input.numbers, input.bin_count);
show_histogram_svg(bins); show_histogram_svg(bins);
} }

@ -139,3 +139,4 @@ show_histogram_svg(const vector<size_t>& bins)
svg_end(); svg_end();
} }

@ -6,4 +6,5 @@ show_histogram_svg(const std::vector<size_t>& bins,double min, double max);
*/ */
void void
show_histogram_svg(const std::vector<size_t>& bins); show_histogram_svg(const std::vector<size_t>& bins);
#endif // SVG_H_INCLUDED #endif // SVG_H_INCLUDED

@ -69,3 +69,4 @@ void show_histogram_text(vector<size_t> bins, size_t bin_count)
cout << endl; cout << endl;
} }
} }

@ -8,10 +8,42 @@ TEST_CASE("distinct positive numbers") {
double min = 0; double min = 0;
double max = 0; double max = 0;
std::vector<double>f{1,2}; std::vector<double>f{1,2};
CHECK(f.size() != 0);
find_minmax(f, min, max);
CHECK(min == 1);
CHECK(max == 2);
CHECK(min != max);
}
TEST_CASE("distinct positive numbers") {
double min = 0;
double max = 0;
std::vector<double>f{};
CHECK(find_minmax(f, min, max) != 0);
CHECK(f.size() != 1); CHECK(f.size() != 1);
find_minmax(f, min, max); find_minmax(f, min, max);
CHECK(min == 1); CHECK(min == 1);
CHECK(max == 2); CHECK(max == 2);
CHECK(min != max); CHECK(min != max);
} }
TEST_CASE("void vector") {
double min = 3;
double max = 2;
std::vector<double> numbers {};
bool check = find_minmax(numbers, min, max);
CHECK(check == true);
}
TEST_CASE("vector with same elements") {
double min = 0;
double max = 0;
find_minmax({2,2,2}, min, max);
CHECK(min == 2);
CHECK(max == 2);
}
TEST_CASE("vector with one element") {
double min = 0;
double max = 0;
find_minmax({1}, min, max);
CHECK(min == 1);
CHECK(max == 1);
}

@ -1,5 +1,5 @@
# depslib dependency file v1.0 # depslib dependency file v1.0
1682280773 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.cpp 1685962483 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.cpp
<iostream> <iostream>
<vector> <vector>
<cmath> <cmath>
@ -7,10 +7,10 @@
"histogam_internal.h" "histogam_internal.h"
<conio.h> <conio.h>
1682273839 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.h 1685896776 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.h
<vector> <vector>
1682273796 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam_internal.h 1685896777 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam_internal.h
<vector> <vector>
1682276830 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\unittest.cpp 1682276830 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\unittest.cpp

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