Сравнить коммиты

...

10 Коммитов

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

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

@ -6,47 +6,46 @@
#include "histogram_internal.h"
using namespace std;
void
bool
find_minmax(vector<double> numbers, double &min, double &max) {
min = numbers[0];
max = numbers[0];
for (size_t i = 1; i < numbers.size(); i++) {
if (min > numbers[i])
min = numbers[i];
if (max < numbers[i])
max = numbers[i];
bool notEmpty = true;
if (numbers.size() == 0 || numbers.size() == 1)
notEmpty = false;
else{
min = numbers[0];
max = numbers[0];
for (size_t i = 1; i < numbers.size(); i++) {
if (min > numbers[i])
min = numbers[i];
if (max < numbers[i])
max = numbers[i];
}
}
return notEmpty;
}
vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count){
double min, max;
find_minmax(numbers, min, max);
double binSize = (max - min) / bin_count;
vector<size_t> bins(bin_count);
for (size_t i = 0; i < numbers.size(); i++) {
bool found = false;
for (size_t j = 0; (j <= bin_count - 1) && !found; j++) {
auto lo = min + j * binSize;
auto hi = min + (j + 1) * binSize;
if ((numbers[i] >= lo) && (numbers[i] < hi)) {
bins[j]++;
found = true;
bool haveElements = find_minmax(numbers, min, max);
if (haveElements){
double binSize = (max - min) / bin_count;
vector<size_t> bins(bin_count);
for (size_t i = 0; i < numbers.size(); i++) {
bool found = false;
for (size_t j = 0; (j <= bin_count - 1) && !found; j++) {
auto lo = min + j * binSize;
auto hi = min + (j + 1) * binSize;
if ((numbers[i] >= lo) && (numbers[i] < hi)) {
bins[j]++;
found = true;
}
}
if (!found)
bins[bin_count - 1]++;
}
if (!found)
bins[bin_count - 1]++;
return bins;
}
int max_count = bins[0];
for (size_t i = 0; i < bin_count; i++) {
if (bins[i] > max_count)
max_count = bins[i];
else
cerr << "Empty massive of numbers";
}
if (max_count > 76) {
for (size_t i = 0; i < bin_count; i++) {
int count = bins[i];
size_t height = 76 * (static_cast<double>(count) / max_count);
bins[i] = height;
}
}
return bins;
}

@ -6,5 +6,4 @@
std::vector<size_t>
make_histogramm(std::vector<double> numbers, size_t bin_count);
#endif // HISTOGRAM_H_INCLUDED

@ -2,6 +2,5 @@
#define HISTOGRAM_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);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -13,7 +13,12 @@
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="curl/include" />
</Compiler>
<Linker>
<Add library="libcurl.dll.a" />
<Add directory="curl/lib" />
</Linker>
</Target>
<Target title="Release">
<Option output="bin/Release/lab_01" prefix_auto="1" extension_auto="1" />
@ -40,6 +45,10 @@
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="text.cpp" />
<Unit filename="text.h">
<Option target="&lt;{~None~}&gt;" />

@ -1,21 +1,25 @@
# depslib dependency file v1.0
1682090855 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.cpp
1684755837 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.cpp
<math.h>
<iostream>
<conio.h>
<vector>
"histogram.h"
"histogram_internal.h"
1681931103 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.h
1682341619 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.h
<vector>
1681931332 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\main.cpp
1684761978 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\main.cpp
<math.h>
<iostream>
<conio.h>
<vector>
"histogram.h"
"text.h"
"svg.h"
"histogram_internal.h"
<curl/curl.h>
1681931523 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\text.h
<vector>
@ -27,3 +31,64 @@
<vector>
"text.h"
1684755787 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram_internal.h
<vector>
1684755829 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\svg.h
1684755829 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\svg.cpp
<math.h>
<iostream>
<conio.h>
<vector>
<string>
"svg.h"
1684137360 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\curl\include\curl\curl.h
"curlver.h"
"system.h"
<stdio.h>
<limits.h>
<osreldate.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"
"typecheck-gcc.h"
1684292872 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\curl\include\curl\curlver.h
1684137360 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\curl\include\curl\system.h
<ConditionalMacros.h>
<winsock2.h>
<windows.h>
<ws2tcpip.h>
<sys/types.h>
<sys/socket.h>
<sys/poll.h>
1684137360 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\curl\include\curl\easy.h
1684137360 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\curl\include\curl\multi.h
"curl.h"
1684137360 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\curl\include\curl\urlapi.h
"curl.h"
1684137360 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\curl\include\curl\options.h
1684137360 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\curl\include\curl\header.h
1684137360 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\curl\include\curl\websockets.h
1684137360 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\curl\include\curl\typecheck-gcc.h

@ -2,34 +2,44 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="text.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="564" topLine="0" />
<Cursor1 position="73" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="text.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="211" topLine="0" />
</Cursor>
</File>
<File name="text.cpp" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="362" topLine="0" />
<Cursor1 position="106" topLine="0" />
</Cursor>
</File>
<File name="histogram_internal.h" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="svg.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="980" 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="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="1502" topLine="23" />
</Cursor>
</File>
<File name="text.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="73" topLine="0" />
<Cursor1 position="173" topLine="0" />
</Cursor>
</File>
<File name="histogram.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="167" topLine="0" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="811" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -4,33 +4,85 @@
#include <vector>
#include "histogram.h"
#include "text.h"
#include "svg.h"
#include "histogram_internal.h"
#include <curl/curl.h>
#include <sstream>
#include <string>
using namespace std;
struct Input {
vector<double> numbers;
size_t bin_count{};
size_t interval;
};
Input
input_data(){
cerr << "Input numbers count: ";
input_data(istream &tin, bool prompt){
if (prompt)
cerr << "Input numbers count: ";
size_t number_count;
cin >> number_count;
tin >> number_count;
Input in;
in.numbers.resize(number_count);
cerr << "Input numbers: ";
if (prompt)
cerr << "Input numbers: ";
for (size_t i = 0; i < number_count; i++) {
cin >> in.numbers[i];
tin >> in.numbers[i];
}
cerr << "Input bin count: ";
cin >> in.bin_count;
if (prompt)
cerr << "Input bin count: ";
tin >> in.bin_count;
return in;
}
int main() {
Input in = input_data();
auto bins = make_histogramm(in.numbers, in.bin_count);
show_histogramm(bins);
size_t
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
CURL* curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
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);
}
size_t data_size = item_size * item_count;
return 0;
}
Input
download(const string& address) {
stringstream buffer;
CURL* curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
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_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
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);
}
const auto bins = make_histogramm(input.numbers, input.bin_count);
show_histogram_svg(bins);
}

@ -0,0 +1,56 @@
#include <math.h>
#include <iostream>
#include <conio.h>
#include <vector>
#include <string>
#include "svg.h"
using namespace std;
void
svg_begin(double width, double height) {
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
cout << "<svg ";
cout << "width='" << width << "' ";
cout << "height='" << height << "' ";
cout << "viewBox='0 0 " << width << " " << height << "' ";
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
}
void
svg_end() {
cout << "</svg>\n";
}
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 colour = "black", string fill = "black"){
cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke = '"<<colour <<"' fill = '"<<fill<<"' />";
}
void
show_histogram_svg(const vector<size_t>& bins) {
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
const auto TEXT_BASELINE = 20;
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10;
double top = 0;
double max_count = bins[0];
for (size_t i = 0; i < bins.size(); i++) {
if (bins[i] > max_count)
max_count = bins[i];
}
svg_begin(400, 300);
for (size_t bin : bins) {
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH)*(bin/max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "green", "#FF00FF");
top += BIN_HEIGHT;
}
svg_end();
}

@ -0,0 +1,7 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
void
show_histogram_svg(const std::vector<size_t>& bins);
#endif // SVG_H_INCLUDED

@ -7,11 +7,34 @@
TEST_CASE("distinct positive numbers") {
double min = 0;
double max = 0;
std::vector<double>v{1};
CHECK(v.size() != 0);
CHECK(v.size() != 1);
find_minmax(v, min, max);
std::vector<double>v{1, 2};
bool haveElements = find_minmax(v, min, max);
CHECK(haveElements);
CHECK(min == 1);
CHECK(max == 2);
CHECK(min != max);
}
TEST_CASE("EMPTY MASSIVE OR 1 ELEMENT IN MASSIVE"){
double min = 0;
double max = 0;
std::vector<double>v{};
bool haveElements = find_minmax(v, min, max);
CHECK(!haveElements);
}
/*TEST_CASE("interval check"){
size_t interval = 3;
bool inRange;
inRange = check_interval(interval);
CHECK(inRange);
inerval = 1
inRange = check_interval(interval);
CHECK(!inRange);
interval = 2
inRange = check_interval(interval);
CHECK(inRange);
interval = 9
inRange = check_interval(interval);
CHECK(inRange);
}
*/

@ -1,5 +1,5 @@
# depslib dependency file v1.0
1682090965 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.cpp
1682340368 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.cpp
<math.h>
<iostream>
<conio.h>
@ -7,9 +7,66 @@
"histogram.h"
"histogram_internal.h"
1681931103 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.h
1682341619 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.h
<vector>
1682091658 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram_internal.h
1682339360 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram_internal.h
<vector>
1682182932 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\unittest_15.cpp
"doctest.h"
"histogram_internal.h"
<vector>
<iostream>
1682341526 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\unittest.cpp
"doctest.h"
"histogram_internal.h"
<vector>
<iostream>
1682092158 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\doctest.h
<signal.h>
<ciso646>
<cstddef>
<ostream>
<istream>
<type_traits>
"doctest_fwd.h"
<ctime>
<cmath>
<climits>
<math.h>
<new>
<cstdio>
<cstdlib>
<cstring>
<limits>
<utility>
<fstream>
<sstream>
<iostream>
<algorithm>
<iomanip>
<vector>
<atomic>
<mutex>
<set>
<map>
<unordered_set>
<exception>
<stdexcept>
<csignal>
<cfloat>
<cctype>
<cstdint>
<string>
<sys/types.h>
<unistd.h>
<sys/sysctl.h>
<AfxWin.h>
<windows.h>
<io.h>
<sys/time.h>
<unistd.h>

@ -2,24 +2,24 @@
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="doctest.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="unittest.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
<Cursor1 position="395" topLine="0" />
</Cursor>
</File>
<File name="histogram_internal.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="97" topLine="0" />
<Cursor1 position="171" topLine="0" />
</Cursor>
</File>
<File name="histogram.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="histogram.cpp" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="23" />
<Cursor1 position="1542" topLine="0" />
</Cursor>
</File>
<File name="unittest.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="doctest.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="414" topLine="0" />
<Cursor1 position="168296" topLine="3336" />
</Cursor>
</File>
</CodeBlocks_layout_file>

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