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

..

9 Коммитов
main ... double

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

@ -1,3 +1,4 @@
/curl
/bin /bin
/obj /obj
*.layout *.layout

@ -32,20 +32,7 @@
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
</Compiler> </Compiler>
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="histogram_internal.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Unit filename="text.cpp" />
<Unit filename="text.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Extensions /> <Extensions />
</Project> </Project>
</CodeBlocks_project_file> </CodeBlocks_project_file>

@ -1,36 +0,0 @@
# depslib dependency file v1.0
1746405872 source:c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\histogram.cpp
"histogram.h"
<vector>
1746351454 c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\histogram.h
<vector>
1747656559 source:c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\main.cpp
<cstdio>
<cstdlib>
<iostream>
<vector>
<cmath>
"histogram.h"
"text.h"
"svg.h"
1746352309 c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\text.h
<vector>
1747656828 c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\svg.h
<vector>
<string>
1747656828 source:c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\svg.cpp
<iostream>
"svg.h"
<vector>
<string>
1746352405 source:c:\kog cpp\jia6bl no npore\2 cemectp\jia6a_3\jia6a_3_project\text.cpp
"text.h"
<vector>
<iostream>

@ -6,58 +6,96 @@
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h" #include "svg.h"
#include <curl/curl.h>
#include <sstream>
#include <string>
using namespace std; using namespace std;
//Ñîçäàíèå ñòðóêòóðû Input äëÿ âõîäíûõ äàííûõ //Ñîçäàíèå ñòðóêòóðû Input äëÿ âõîäíûõ äàííûõ
struct Input { struct Input
{
vector<double> Numbers; vector<double> Numbers;
size_t bin_count{}; size_t bin_count{};
}; };
//Ôóíêöèÿ ââîäà //Ôóíêöèÿ ââîäà
Input input_data(){ Input input_data(istream& in, bool prompt)
{
size_t number_count; size_t number_count;
Input stct; Input stct;
//Ââîä êîëè÷åñòâà ýëåìåíòîâ ìàññèâà //Ââîä êîëè÷åñòâà ýëåìåíòîâ ìàññèâà
if (prompt)
{
cerr << "Enter number count "; cerr << "Enter number count ";
cin >> number_count; }
in >> number_count;
//Ââîä ìàññèâà //Ââîä ìàññèâà
vector<double> Numbers(number_count); vector<double> Numbers(number_count);
stct.Numbers.resize(number_count); stct.Numbers.resize(number_count);
if (prompt)
{
cerr << "Enter array:\n"; cerr << "Enter array:\n";
cin >> stct.Numbers[0]; }
for (int i = 1; i < number_count; i++) { in >> stct.Numbers[0];
cin >> stct.Numbers[i]; for (int i = 1; i < number_count; i++)
{
in >> stct.Numbers[i];
} }
//Ââîä êîëè÷åñòâà êîðçèí //Ââîä êîëè÷åñòâà êîðçèí
if (prompt)
{
cerr << "Enter bin count\n"; cerr << "Enter bin count\n";
cin >> stct.bin_count; }
in >> stct.bin_count;
//Âîçâðàùàåì ñòðóêòóðó //Âîçâðàùàåì ñòðóêòóðó
return stct; return stct;
} }
//Ââîä ïàðàìåòðîâ ÷åðòî÷êè size_t
void dash_param(size_t& length_dsh, size_t& length_invl){ write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
cerr << "Enter length dash "; stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
cin >> length_dsh; size_t data_size = item_size * item_count;
cerr << "Enter length interval "; //buffer.write(items, data_size);
cin >> length_invl; (*buffer).write(reinterpret_cast<const char*>(items), data_size);
return data_size;
} }
int main() { Input
//Ââîä ìàññèâà è êîëè÷åñòâà êîðçèí download(const string& address)
Input in = input_data(); {
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);
//Ââîä äëèíû ÷åðòû è èíòåðâàëà ìåæäó ÷åðòàìè
size_t length_dash, length_interval;
dash_param(length_dash, length_interval);
//Ñîçäàíèå âåêòîðà bins äëÿ ãèñòîãðàììû res = curl_easy_perform(curl);
vector<size_t> bins = make_histogram(in.Numbers, in.bin_count); if (res != CURLE_OK)
{
cerr << curl_easy_strerror(res);
exit(1);
}
curl_easy_cleanup(curl);
}
return input_data(buffer, false);
}
//Âûâîä ãèñòîãðàììû
show_histogram_svg(bins, length_dash, length_interval);
//show_histogram_text(bins);
return 0; 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_histogram(input.Numbers, input.bin_count);
show_histogram_svg(bins);
} }

@ -23,7 +23,7 @@ void svg_text(double left, double baseline, std::string text)
std::cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>"; std::cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
} }
void show_histogram_svg(const std::vector<size_t>& bins, const size_t length_dsh, const size_t length_invl) void show_histogram_svg(const std::vector<size_t>& bins)
{ {
const auto IMAGE_WIDTH = 400; const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300; const auto IMAGE_HEIGHT = 300;
@ -43,8 +43,6 @@ void show_histogram_svg(const std::vector<size_t>& bins, const size_t length_dsh
if (bin > max_bin) max_bin = bin; if (bin > max_bin) max_bin = bin;
} }
std::string dash_pattern = std::to_string(length_dsh) + " " + std::to_string(length_invl);
if (max_bin * BLOCK_WIDTH > MAX_AVAIL_WIDTH) if (max_bin * BLOCK_WIDTH > MAX_AVAIL_WIDTH)
{ {
// ìàñøòàáíûé êîýôôèöèåíò // ìàñøòàáíûé êîýôôèöèåíò
@ -57,7 +55,6 @@ void show_histogram_svg(const std::vector<size_t>& bins, const size_t length_dsh
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
svg_line(0, top + BIN_HEIGHT, IMAGE_WIDTH, top + BIN_HEIGHT, dash_pattern);
top += BIN_HEIGHT; top += BIN_HEIGHT;
} }
} }
@ -69,7 +66,6 @@ void show_histogram_svg(const std::vector<size_t>& bins, const size_t length_dsh
const double bin_width = BLOCK_WIDTH * bin; const double bin_width = BLOCK_WIDTH * bin;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
svg_line(0, top + BIN_HEIGHT, IMAGE_WIDTH, top + BIN_HEIGHT, dash_pattern);
top += BIN_HEIGHT; top += BIN_HEIGHT;
} }
} }
@ -81,11 +77,3 @@ void svg_rect(double x, double y, double width, double height, std::string strok
{ {
std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "' />"; std::cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "' />";
} }
//çàùèòà
void svg_line(double x1, double y1, double x2, double y2, const std::string stroke_dasharray){
std::cout << "<line x1='" << x1 << "' y1='" << y1 << "' x2='" << x2 << "' y2='" << y2
<< "' stroke='black' stroke-dasharray='" << stroke_dasharray << "' />\n";
}

@ -5,11 +5,8 @@
void svg_begin(double width, double height); void svg_begin(double width, double height);
void svg_end(); void svg_end();
void show_histogram_svg(const std::vector<size_t>& bins, const size_t length_dsh, const size_t length_invl); void show_histogram_svg(const std::vector<size_t>& bins);
void svg_text(double left, double baseline, std::string text); void svg_text(double left, double baseline, std::string text);
void svg_rect(double x, double y, double width, double height, std::string stroke = "black", std::string fill = "black"); void svg_rect(double x, double y, double width, double height, std::string stroke = "black", std::string fill = "black");
//çàùèòà
void svg_line(double x1, double y1, double x2, double y2, const std::string stroke_dasharray);
#endif // SVG_H_INCLUDED #endif // SVG_H_INCLUDED

@ -31,10 +31,6 @@
<Compiler> <Compiler>
<Add option="-Wall" /> <Add option="-Wall" />
</Compiler> </Compiler>
<Unit filename="doctest.h" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram_internal.h" />
<Unit filename="unittest.cpp" />
<Extensions /> <Extensions />
</Project> </Project>
</CodeBlocks_project_file> </CodeBlocks_project_file>

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