Сравнить коммиты
9 Коммитов
9279645ea9
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| b9996961be | |||
| ab1e2fb915 | |||
| 6afea87cc2 | |||
| b60bda4025 | |||
| 2bcab524e0 | |||
| ba843ef1c3 | |||
| 9ca4920874 | |||
| c31cf1524f | |||
| d8a59fdb67 |
@@ -14,6 +14,11 @@
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-static-libstdc++" />
|
||||
<Add option="-static-libgcc" />
|
||||
<Add option="-static" />
|
||||
</Linker>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/fin_lab34" prefix_auto="1" extension_auto="1" />
|
||||
@@ -25,13 +30,25 @@
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
<Add option="-static-libstdc++" />
|
||||
<Add option="-static-libgcc" />
|
||||
<Add option="-static" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
<Add directory="D:/PROG/PROGRAMMING/fin_lab34/curl/include" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-static-libstdc++" />
|
||||
<Add option="-static-libgcc" />
|
||||
<Add option="-static" />
|
||||
<Add option="-DCURL_STATICLIB" />
|
||||
<Add library="D:/PROG/PROGRAMMING/fin_lab34/curl/lib/libcurl.dll.a" />
|
||||
<Add directory="D:/PROG/PROGRAMMING/fin_lab34/curl/lib" />
|
||||
</Linker>
|
||||
<Unit filename=".gitignore" />
|
||||
<Unit filename="fin_lab34.cpp" />
|
||||
<Unit filename="histogram.cpp" />
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <curl/curl.h>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
|
||||
const size_t WINDOW_WIDTH = 80;
|
||||
const size_t MAX_VALUE = WINDOW_WIDTH - 3 - 1;
|
||||
using namespace std;
|
||||
@@ -15,24 +19,72 @@ struct Input{
|
||||
};
|
||||
|
||||
Input
|
||||
input_data(){
|
||||
input_data(istream &thread, bool prompt){
|
||||
//ïðîèçîøëà íàêëàäêà ñ èìåíàìè ïåðåìåííûõ: ïðè íàçâàíèè ïîòîêà in ðóãàåòñÿ íà ñ22, â êîòîðîé ÿêîáû îáúÿâëÿåòñÿ àðãóìåíò
|
||||
prompt = false;
|
||||
size_t number_count;
|
||||
if (prompt) {cerr << "Enter the amount of numbers: " << endl;}
|
||||
cin >> number_count;
|
||||
Input in;
|
||||
in.numbers.resize(number_count);
|
||||
if (prompt) {cerr << "Enter the numbers: " << endl;}
|
||||
for (size_t i = 0; i < number_count; i++) {
|
||||
cin >> in.numbers[i];
|
||||
}
|
||||
if (prompt) {cerr << "Enter the amount of bins: " << endl;}
|
||||
cin >> in.bin_count;
|
||||
return in;
|
||||
}
|
||||
|
||||
size_t
|
||||
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
||||
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
||||
size_t data_size = item_size * item_count;
|
||||
(*buffer).write(reinterpret_cast<const char*> (items), data_size);
|
||||
return data_size;
|
||||
}
|
||||
|
||||
Input
|
||||
download(const string& address){
|
||||
stringstream buffer;
|
||||
CURLcode res;
|
||||
CURL *curl = curl_easy_init();
|
||||
if (curl){
|
||||
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||
res = curl_easy_perform(curl);
|
||||
cerr << curl_easy_getinfo(curl, CURLINFO_PRIMARY_IP, write_data); //var 8
|
||||
if (res != CURLE_OK){
|
||||
cerr << curl_easy_strerror(res);
|
||||
exit(1);
|
||||
}
|
||||
return input_data(buffer, false);
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(){
|
||||
double min = 0, max = 0;
|
||||
Input in = input_data();
|
||||
main(int argc, char* argv[]){
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
Input input, in;
|
||||
if (argc > 1) {
|
||||
input = download(argv[1]);
|
||||
} else {
|
||||
input = input_data(cin, true);
|
||||
}
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
//CURLcode curl_global_init(CURL_GLOBAL_ALL);
|
||||
size_t font = 0;
|
||||
//auto in = input_data(cin, prompt);
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
//for (auto now: bins) {cout << now << endl;}
|
||||
show_histogram_svg(bins);
|
||||
cin >> font;
|
||||
if (font < 8) {(cerr << font << "Font value is too small. Please, edit the input file.");}
|
||||
else if (font > 32) {(cerr << "Font value is too large. Please, edit the input file.");}
|
||||
else {show_histogram_svg(bins, font);}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//ñ êëàâèàòóðû â marks.txt, ñ marks.txt â marks.svg
|
||||
|
||||
22
svg.cpp
22
svg.cpp
@@ -18,15 +18,19 @@ svg_end() {
|
||||
cout << "</svg>\n";
|
||||
}
|
||||
void
|
||||
svg_text(double left, double baseline, string text){
|
||||
cout << "<text x='" << left << "' y='" << baseline <<"' >" << text << "</text>" << endl;
|
||||
svg_text(double left, double baseline, size_t font, string text){
|
||||
cout << "<text x='" << left << "' y='" << baseline << "' font-size='" << font << "' >" << text << " </text>" << endl;
|
||||
return;
|
||||
}
|
||||
void
|
||||
svg_rect(double x, double y, double width, double height, string stroke = "#ed53a8", string fill = "#9df3a1"){
|
||||
cout << "<rect x='" << x << "' y='" << y << "' width= '" << width << "' height= '" << height << "' stroke= '" << stroke << "' fill= '" << fill << "'/>" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
show_histogram_svg(const vector <size_t> &bins) {
|
||||
show_histogram_svg(const vector <size_t> &bins, size_t &font) {
|
||||
|
||||
const auto IMAGE_WIDTH = 800;
|
||||
const auto IMAGE_HEIGHT = 600;
|
||||
const auto TEXT_LEFT = 20;
|
||||
@@ -34,13 +38,21 @@ show_histogram_svg(const vector <size_t> &bins) {
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
const auto MAX_VALUE = IMAGE_WIDTH - TEXT_WIDTH;
|
||||
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
double top = 0;
|
||||
size_t max_count = 0;
|
||||
|
||||
for (auto now: bins)
|
||||
{if (now > max_count) {max_count = now;}}
|
||||
for (size_t bin : bins){
|
||||
const double bin_width = BLOCK_WIDTH * bin;
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
double bin_width = BLOCK_WIDTH * bin;
|
||||
if (bin == max_count) {bin_width = MAX_VALUE * 1.0;}
|
||||
else {bin_width = MAX_VALUE * (static_cast <double> (bin) / max_count);}
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, font, to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
svg_end();
|
||||
return;
|
||||
}
|
||||
|
||||
7
svg.h
7
svg.h
@@ -10,11 +10,14 @@ void
|
||||
svg_end();
|
||||
|
||||
void
|
||||
svg_text(double left, double baseline, string text);
|
||||
svg_text(double left, double baseline, size_t font, string text);
|
||||
|
||||
size_t
|
||||
enter_font_size(size_t &font);
|
||||
|
||||
void
|
||||
svg_rect(double x, double y, double width, double height, string stroke, string fill);
|
||||
|
||||
void
|
||||
show_histogram_svg(const vector <size_t> &bins);
|
||||
show_histogram_svg(const vector <size_t> &bins, size_t &font);
|
||||
#endif // SVG_H_INCLUDED
|
||||
|
||||
Ссылка в новой задаче
Block a user