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

..

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 "text.h"
#include "svg.h"
#include <curl/curl.h>
#include <sstream>
using namespace std;
struct Input {
vector<double> Numbers;
size_t BinCount{};
};
Input
InputData() {
Input in;
InputData(istream& in, bool prompt) {
Input inp;
size_t NumberCount;
cerr << "Enter number count: ";
cin >> NumberCount;
cerr << "Enter bin count: ";
cin >> in.BinCount;
in.Numbers.resize(NumberCount);
if (prompt) {
cerr << "Enter number count: ";
}
in >> NumberCount;
inp.Numbers.resize(NumberCount);
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);
@ -33,11 +40,64 @@ vector<size_t> MakeHistogram(vector<double> Numbers, size_t BinCount, double& Ma
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;
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);
Bins = MakeHistogram(in.Numbers, in.BinCount, MaxCount);
ShowHistogramSvg(Bins);
return 0;
}

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

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