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

..

13 Коммитов
main ... lab4

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

@ -0,0 +1,7 @@
ProjectLab34_1.vcxproj
ProjectLab34_1.vcxproj.filters
ProjectLab34_1.vcxproj.user
/.vs
/x64
/ProjectLab34_1
/curl

@ -4,27 +4,34 @@
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h" #include "svg.h"
#include <curl/curl.h>
#include <sstream>
using namespace std; using namespace std;
struct Input { struct Input {
vector<double> Numbers; vector<double> Numbers;
size_t BinCount{}; size_t BinCount{};
}; };
Input Input
InputData() { InputData(istream& in, bool prompt) {
Input in; Input inp;
size_t NumberCount; size_t NumberCount;
cerr << "Enter number count: "; if (prompt) {
cin >> NumberCount; cerr << "Enter number count: ";
cerr << "Enter bin count: "; }
cin >> in.BinCount; in >> NumberCount;
in.Numbers.resize(NumberCount); inp.Numbers.resize(NumberCount);
for (int i = 0; i < NumberCount; i++) { for (int i = 0; i < NumberCount; i++) {
cin >> in.Numbers[i]; in >> inp.Numbers[i];
} }
return in; if (prompt) {
cerr << "Enter bin count: ";
}
in >> inp.BinCount;
return inp;
} }
void FindMinMax(const vector<double>& Numbers, double& minn, double& maxx); void FindMinMax(const vector<double>& Numbers, double& minn, double& maxx);
@ -33,11 +40,64 @@ vector<size_t> MakeHistogram(vector<double> Numbers, size_t BinCount, double& Ma
void ShowHistogrammText(vector<size_t> Bins); void ShowHistogrammText(vector<size_t> Bins);
int main() { size_t
WriteData(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, const string& option) {
stringstream buffer;
if ((option != "") && (address != "-verbose") && (option != "-verbose")) {
cout << "Invalid argument, please use -verbose" << endl;
exit(2);
}
CURL* curl = curl_easy_init();
if (curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, (option == "" || option == "-verbose") ? address.c_str() : option.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteData);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
if (address == "-verbose" || option == "-verbose") {
curl_easy_setopt(curl, CURLOPT_VERBOSE, option == "-verbose" ? option.c_str() : address.c_str());
}
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
cout << curl_easy_strerror(res);
exit(1);
}
curl_easy_cleanup(curl);
}
return InputData(buffer, false);
}
int main(int argc, char* argv[]) {
setlocale(LC_ALL, "Russian");
double MaxCount = 0; double MaxCount = 0;
Input in = InputData(); Input in;
if (argc > 1) {
if (argc == 2) {
in = Download(argv[1], "");
}
else {
in = Download(argv[1], argv[2]);
}
}
else {
in = InputData(cin, true);
}
vector <size_t> Bins(in.BinCount); vector <size_t> Bins(in.BinCount);
Bins = MakeHistogram(in.Numbers, in.BinCount, MaxCount); Bins = MakeHistogram(in.Numbers, in.BinCount, MaxCount);
ShowHistogramSvg(Bins); ShowHistogramSvg(Bins);
return 0; return 0;
} }

@ -38,25 +38,25 @@ void SvgRect(double x, double y, double width, double height, string stroke = "b
void void
ShowHistogramSvg(const vector<size_t>& bins) { ShowHistogramSvg(const vector<size_t>& bins) {
double move = 0; double top = 0;
SvgBegin(IMAGE_WIDTH, IMAGE_HEIGHT); SvgBegin(400, 300);
double k = 1;
size_t max_bin = bins[0]; size_t MaxCount = 0;
for (size_t bin : bins) { for (auto bin : bins) {
if (bin > max_bin) { if (MaxCount < bin) {
max_bin = bin; MaxCount = bin;
} }
} }
if (max_bin * 10 > IMAGE_HEIGHT) { int k = (IMAGE_WIDTH - TEXT_WIDTH) / MaxCount * BLOCK_WIDTH;
k = double(IMAGE_HEIGHT - TEXT_WIDTH) / (max_bin * 10);
}
if (k > 1) k = 1; if (k > 1) k = 1;
for (size_t bin : bins) { for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin * k; bin = bin * k;
SvgText(TEXT_LEFT + move, TEXT_BASELINE, to_string(bin)); const double bin_width = BLOCK_WIDTH * bin;
SvgRect(move+13, 3*BLOCK_WIDTH, BIN_HEIGHT, bin_width,"red","#FFD700"); SvgText(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
move += BIN_HEIGHT; SvgRect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "red", "#FF69B4");
top += BIN_HEIGHT;
} }
SvgEnd(); SvgEnd();
} }

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