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

...

6 Коммитов

Автор SHA1 Сообщение Дата
AnisenkovPD c0aba9ac09 code: обработка ошибок
11 месяцев назад
AnisenkovPD ba8761de75 code: загрузка файла по сети
11 месяцев назад
AnisenkovPD 6c28d443fa code: получены аргументы программы
11 месяцев назад
AnisenkovPD 6ad5b7518a code: динамические библиотеки
11 месяцев назад
AnisenkovPD 8e462a9fa6 добавлен новый параметр функции
11 месяцев назад
AnisenkovPD 7d41e081ce переписана функция ввода
11 месяцев назад

@ -1,8 +1,11 @@
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include <vector> #include <vector>
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h"
#include <curl/curl.h>
using namespace std; using namespace std;
const size_t SCREEN_WIDTH = 80; const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
@ -13,31 +16,54 @@ struct Input {
}; };
Input Input
input_data() { input_data(istream& in, bool prompt) {
size_t number_count; size_t number_count;
cin >> number_count; if (prompt == true){
Input in; cerr << "input number count";
in.numbers.resize(number_count); in >> number_count;
for (size_t i = 0; i < number_count; i++) { Input inn;
cin >> in.numbers[i]; inn.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++) {
in >> inn.numbers[i];
}
size_t bin_count;
in >> inn.bin_count;
return inn;
}
else{
cout << "input number count";
in >> number_count;
Input inn;
inn.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++) {
in >> inn.numbers[i];
}
size_t bin_count;
in >> inn.bin_count;
return inn;
} }
size_t bin_count;
cin >> in.bin_count;
return in;
} }
int main(int argc, char* argv[]) {
if (argc>1){
CURL *curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
res = curl_easy_perform(curl);
if (res!=CURLE_OK){
cerr << curl_easy_strerror(res);
exit(1);
}
curl_easy_cleanup(curl);
return 0;
}
}
auto in = input_data(cin, true);
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
return 0;
int main()
{
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins);
return 0;
} }

@ -31,8 +31,25 @@
<Compiler> <Compiler>
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
<Add directory="curl/include" />
</Compiler> </Compiler>
<Linker>
<Add library="libcurl.dll.a" />
<Add directory="curl/lib" />
</Linker>
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="main.cpp" /> <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;" />
</Unit>
<Extensions> <Extensions>
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />
</Extensions> </Extensions>

@ -22,14 +22,14 @@ svg_end() {
} }
void void
svg_text(double TEXT_LEFT, double BASELINE, string text) { svg_text(double TEXT_LEFT, double BASELINE, string text, size_t bukva_scale) {
cout << "<text x='" << TEXT_LEFT << "' y='"<< BASELINE <<"'> " << text << "</text>"; cout << "<text x='" << TEXT_LEFT << "' font-size = '" << bukva_scale << "' y='"<< BASELINE <<"'> " << text << "</text>";
} }
void svg_rect(double TEXT_WIDTH, double top, double bin_width, double BIN_HEIGHT){ void svg_rect(double TEXT_WIDTH, double top, double bin_width, double BIN_HEIGHT, string grad){
cout << "<rect x='"<<TEXT_WIDTH<<"' y='"<<top<<"' width='"<<bin_width<<"' height='"<<BIN_HEIGHT<<"' stroke ='cyan' fill='#fce166' />\n"; cout << "<rect x='"<<TEXT_WIDTH<<"' y='"<<top<<"' width='"<<bin_width<<"' height='"<<BIN_HEIGHT<<"' stroke ='cyan' fill='#"<<grad<<grad<<grad<<"' />\n";
} }
void void
@ -43,8 +43,11 @@ show_histogram_svg(const vector<size_t>& bins) {
const auto BLOCK_WIDTH = 10; const auto BLOCK_WIDTH = 10;
const double SCALE = IMAGE_WIDTH - TEXT_WIDTH; const double SCALE = IMAGE_WIDTH - TEXT_WIDTH;
size_t grad = 0;
double max_count = 0; double max_count = 0;
size_t bukva_scale = 12;
cin >> bukva_scale;
for (double x: bins) { for (double x: bins) {
if (x > max_count) { if (x > max_count) {
max_count = x; max_count = x;
@ -56,8 +59,9 @@ show_histogram_svg(const vector<size_t>& bins) {
double top = 0; double top = 0;
for (size_t i = 0; i < bins.size(); i++) { for (size_t i = 0; i < bins.size(); i++) {
const double bin_width = SCALE * ( bins[i] / max_count); const double bin_width = SCALE * ( bins[i] / max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i])); grad = (11 - (bins[i] * 9) / max_count);
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT); svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bins[i]), bukva_scale);
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, to_string(grad));
top += BIN_HEIGHT; top += BIN_HEIGHT;
cout << endl; cout << endl;
cout << bin_width; cout << bin_width;

@ -31,6 +31,12 @@
<Compiler> <Compiler>
<Add option="-Wall" /> <Add option="-Wall" />
</Compiler> </Compiler>
<Unit filename="doctest.h" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram_internal.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="unittest.cpp" />
<Extensions> <Extensions>
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />
</Extensions> </Extensions>

@ -6,17 +6,19 @@
TEST_CASE("distinct positive numbers") { TEST_CASE("distinct positive numbers") {
double min = 0; double min = 0;
double max = 0; double max = 0;
std::vector<double>test = {0};
bool flag;
find_minmax({1, 2}, min, max); find_minmax({1, 2}, min, max);
CHECK(min == 1); CHECK(min == 1);
CHECK(max == 2); CHECK(max == 2);
}
TEST_CASE("distinct negative numbers") {
double min = 0;
double max = 0;
find_minmax({-1, -2, -3, -4, -5}, min, max); find_minmax({-1, -2, -3, -4, -5}, min, max);
CHECK(min == -5); CHECK(min == -5);
CHECK(max == -1); CHECK(max == -1);
}
TEST_CASE("distinct null vector") {
double min = 0;
double max = 0;
CHECK(!find_minmax({}, min, max)); CHECK(!find_minmax({}, min, max));
CHECK(true); }
}

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