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

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

@ -6,21 +6,28 @@
#include <conio.h>
using namespace std;
/*void find_minmax(vector<double> numbers, double& min, double& max) {
min = numbers[0];
for (auto i = 0; i < numbers.size(); i++) {
if (numbers[i] < min) {
min = numbers[i];
}
/*bool find_minmax(vector<double> numbers, double& min, double& max) {
if (numbers.empty())
{
return true;
}
else
{
min = numbers[0];
for (auto i = 0; i < numbers.size(); i++) {
if (numbers[i] < min) {
min = numbers[i];
}
}
max = numbers[0];
for (auto i = 0; i < numbers.size(); i++) {
if (numbers[i] > max) {
max = numbers[i];
max = numbers[0];
for (auto i = 0; i < numbers.size(); i++) {
if (numbers[i] > max) {
max = numbers[i];
}
}
}
return false;
}
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;
}

@ -2,8 +2,9 @@
#define HISTOGAM_INTERNAL_H_INCLUDED
#include <vector>
/*
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

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

@ -4,12 +4,12 @@
#include <string>
#include "histogam.h"
#include "text.h"
#include "svg.h"
#include <conio.h>
#include "histogam_internal.h"
#include <curl/curl.h>
#include <sstream>
#include <string>
#include "svg.h"
using namespace std;
@ -45,7 +45,8 @@ int main()
return 0;
}
*/
struct Input {
struct Input
{
vector<double> numbers;
size_t bin_count{};
};
@ -54,7 +55,7 @@ Input
input_data(istream& in, bool promt)
{
size_t number_count;
if (promt)
if (promt)
{
cerr << "Enter number count: ";
}
@ -65,7 +66,10 @@ input_data(istream& in, bool promt)
{
in >> ik.numbers[i];
}
cerr << "Enter bin count: ";
if (promt)
{
cerr << "Enter bin count: ";
}
in>> ik.bin_count;
return ik;
}
@ -74,31 +78,38 @@ 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(static_cast<const char*>(items), data_size);
return 0;
buffer->write(reinterpret_cast<const char*>(items), data_size);
return data_size;
}
Input
download(const string& address)
{
stringstream buffer;
stringstream buffer;
CURL *curl = curl_easy_init();
if(curl)
{
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);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res != CURLE_OK)
{
cout << curl_easy_strerror;
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
exit(1);
}
}
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
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_cleanup(curl);
}
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);
show_histogram_svg(bins);
}

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

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

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

@ -8,10 +8,42 @@ TEST_CASE("distinct positive numbers") {
double min = 0;
double max = 0;
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);
find_minmax(f, min, max);
CHECK(min == 1);
CHECK(max == 2);
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
1682280773 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.cpp
1685962483 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.cpp
<iostream>
<vector>
<cmath>
@ -7,10 +7,10 @@
"histogam_internal.h"
<conio.h>
1682273839 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.h
1685896776 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam.h
<vector>
1682273796 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam_internal.h
1685896777 c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\histogam_internal.h
<vector>
1682276830 source:c:\users\admin\onedrive\Ðàáî÷èé ñòîë\lab1\unittest.cpp

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