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

..

Ничего общего в коммитах. 'bb51ae70ea3bfd8f4a672cf94c8b697595ede843' и 'ccff7aed06ddfe57aff6a2785558e2c335f8cf61' имеют совершенно разные истории.

@ -1,5 +1,5 @@
#include "histogram.h" #include "histogram.h"
#include <cmath>
bool find_minmax(vector<double> vec, double& min, double& max) { bool find_minmax(vector<double> vec, double& min, double& max) {
if (vec.size() == 0) { if (vec.size() == 0) {
cerr << "Empty vec"; cerr << "Empty vec";
@ -16,7 +16,7 @@ bool find_minmax(vector<double> vec, double& min, double& max) {
max = x; max = x;
} }
} }
return true; return true;
} }
vector<size_t> make_histogram(size_t number, vector<double> vec) { vector<size_t> make_histogram(size_t number, vector<double> vec) {
vector<size_t> bins(number); vector<size_t> bins(number);
@ -40,3 +40,19 @@ vector<size_t> make_histogram(size_t number, vector<double> vec) {
} }
return bins; return bins;
} }
vector<int> make_percentages(const vector<size_t>& bins) {
size_t total = 0;
for (auto x : bins) {
total += x;
}
vector<int> pct(bins.size());
for (size_t i = 0; i < bins.size(); i++) {
if (total > 0) {
pct[i] = static_cast<int>(round(100.0 * bins[i] / total));
}
else {
pct[i] = 0;
}
}
return pct;
}

@ -2,7 +2,7 @@
#define HISTOGRAM_H_INCLUDED #define HISTOGRAM_H_INCLUDED
#include <vector> #include <vector>
#include <iostream> #include <iostream>
using namespace std; using namespace std;
vector<size_t> make_histogram(size_t number, vector<double> vec); vector<size_t> make_histogram(size_t number, vector<double> vec);
vector<int> make_percentages(const vector<size_t>& bins);
#endif // HISTOGRAM_H_INCLUDED #endif // HISTOGRAM_H_INCLUDED

@ -2,4 +2,5 @@
#define HISTOGRAM_INTERNAL_H_INCLUDED #define HISTOGRAM_INTERNAL_H_INCLUDED
bool find_minmax(std::vector<double> vec, double& min, double& max); bool find_minmax(std::vector<double> vec, double& min, double& max);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED #endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -1,33 +0,0 @@
# depslib dependency file v1.0
1747403061 source:c:\users\professional\desktop\cs-lab34\lab1\histogram.cpp
"histogram.h"
1747403061 c:\users\professional\desktop\cs-lab34\lab1\histogram.h
<vector>
<iostream>
1746444035 source:c:\users\professional\desktop\cs-lab34\lab1\text.cpp
"text.h"
"histogram.h"
<iostream>
<vector>
<string>
1747403061 c:\users\professional\desktop\cs-lab34\lab1\text.h
<iostream>
<vector>
1747403061 source:c:\users\professional\desktop\cs-lab34\lab1\main.cpp
"histogram.h"
"text.h"
"svg.h"
1747403061 c:\users\professional\desktop\cs-lab34\lab1\svg.h
<iostream>
<vector>
<string>
<math.h>
1747403061 source:c:\users\professional\desktop\cs-lab34\lab1\svg.cpp
"svg.h"

@ -1,7 +1,6 @@
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h" #include "svg.h"
struct Input { struct Input {
vector<double> vec; vector<double> vec;
size_t korz{}; size_t korz{};
@ -20,7 +19,6 @@ Input input_data() {
cin >> in.korz; cin >> in.korz;
return in; return in;
} }
int main() { int main() {
auto in = input_data(); auto in = input_data();
auto bins = make_histogram(in.korz, in.vec); auto bins = make_histogram(in.korz, in.vec);

@ -1,5 +1,5 @@
#include "svg.h" #include "svg.h"
#include <cmath>
using namespace std; using namespace std;
void void
@ -34,38 +34,62 @@ svg_rect(double x, double y, double width, double height, string stroke = "black
void
show_histogram_svg(const vector<size_t>& bins) void show_histogram_svg(const vector<size_t>& bins)
{ {
const auto IMAGE_WIDTH = 400; const auto ORIG_WIDTH = 400;
const auto IMAGE_HEIGHT = 300; const auto PADDING_RIGHT = 50;
const auto TEXT_LEFT = 20; const auto IMAGE_WIDTH = ORIG_WIDTH + PADDING_RIGHT;
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
const auto TEXT_BASELINE = 20; const auto TEXT_BASELINE = 20;
const auto TEXT_WIDTH = 50; const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30; const auto BIN_HEIGHT = 30;
const auto BLOCK_WIDTH = 10; const auto BLACK = "black";
const auto GREEN = "green"; const auto RED = "red";
const auto RED = "red"; const auto MAX_WIDTH = ORIG_WIDTH - TEXT_WIDTH;
const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH; const auto PERCENT_X = TEXT_WIDTH + MAX_WIDTH + 10;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT); double max_count = 0;
for (auto b : bins) {
if (b > max_count) {
max_count = b;
}
}
size_t total_count = 0;
for (auto b : bins) {
total_count += b;
}
double top = 0; double top = 0;
double max_count = bins[0]; for (auto b : bins) {
for (size_t i = 0; i < bins.size(); i++)
{ double bin_width = 0;
if (max_count < bins[i]) if (max_count > 0) {
{ bin_width = MAX_WIDTH * (b / max_count);
max_count = bins[i];
} }
}
for (size_t bin : bins)
{ svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(b));
double bin_width = (MAX_WIDTH) * (bin/max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin)); svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, BLACK, RED);
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, GREEN, RED);
int pct = 0;
if (total_count > 0) {
pct = static_cast<int>(round(100.0 * b / total_count));
}
string pct_str = to_string(pct);
if (pct < 10) {
pct_str = "0" + pct_str;
}
pct_str += "%";
svg_text(PERCENT_X, top + TEXT_BASELINE, pct_str);
top += BIN_HEIGHT; top += BIN_HEIGHT;
} }

@ -1,9 +1,15 @@
#include "text.h" #include "text.h"
#include "histogram.h"
#include <iostream>
#include <vector>
#include <string>
void show_histogram(std::vector<size_t> bins) { void show_histogram(vector<size_t> bins) {
bool gigant = false; bool gigant = false;
auto spaces = 0; size_t spaces = 0;
size_t mx_count = 0; size_t mx_count = 0;
for (auto x : bins) { for (auto x : bins) {
if (x > 76) { if (x > 76) {
gigant = true; gigant = true;
@ -11,72 +17,68 @@ void show_histogram(std::vector<size_t> bins) {
if (x > mx_count) { if (x > mx_count) {
mx_count = x; mx_count = x;
} }
auto len = 0; size_t len = 0;
while (x > 0) { size_t t = x;
x /= 10; do {
t /= 10;
len++; len++;
} } while (t > 0);
if (len > spaces) { if (len > spaces) {
spaces = len; spaces = len;
} }
} }
if (spaces == 1) {
for (size_t i = 0; i < bins.size(); i++) { size_t bar_max_width;
std::cout << " " << bins[i] << "|"; if (gigant) {
if (gigant) { bar_max_width = 76;
if (bins[i] == mx_count) { } else {
for (size_t j = 0; j < 76; j++) { bar_max_width = mx_count;
std::cout << "*";
}
}
else
{
for (size_t j = 0; j < 76 * static_cast<double>(bins[i]) / mx_count; j++) {
std::cout << "*";
}
}
}
else
{
for (size_t j = 0; j < bins[i]; j++) {
std::cout << "*";
}
std::cout << std::endl;
}
}
} }
else
{ auto percentages = make_percentages(bins);
for (size_t i = 0; i < bins.size(); i++) {
int len = 1; for (size_t i = 0; i < bins.size(); ++i) {
int k = bins[i];
for (; k /= 10; ++len); size_t len = 0;
while (len < spaces) { size_t t = bins[i];
std::cout << " "; do {
len++; t /= 10;
} len++;
std::cout << bins[i]; } while (t > 0);
std::cout << "|"; for (size_t s = len; s < spaces + 1; ++s) {
if (gigant) { cout << " ";
if (bins[i] == mx_count) { }
for (size_t j = 0; j < 76; j++) { cout << bins[i] << "|";
std::cout << "*";
}
} size_t star_count = 0;
else if (gigant) {
{ if (bins[i] == mx_count) {
for (size_t j = 0; j < (76 * static_cast<double>(bins[i]) / mx_count - 1); j++) { star_count = 76;
std::cout << "*"; } else {
} star_count = static_cast<size_t>(76 * static_cast<double>(bins[i]) / mx_count);
}
}
else
{
for (size_t j = 0; j < bins[i]; j++) {
std::cout << "*";
}
} }
std::cout << std::endl; } else {
star_count = bins[i];
}
for (size_t j = 0; j < star_count; ++j) {
cout << "*";
} }
size_t pad = bar_max_width - star_count;
for (size_t p = 0; p < pad + 2; ++p) {
cout << " ";
}
int pct = percentages[i];
string pct_str;
if (pct < 10) {
pct_str = "0" + to_string(pct);
} else {
pct_str = to_string(pct);
}
pct_str += "%";
cout << pct_str << "\n";
} }
} }

@ -5,4 +5,5 @@
#include <vector> #include <vector>
void show_histogram(std::vector<size_t> bins); void show_histogram(std::vector<size_t> bins);
#endif // TEXT_H_INCLUDED #endif // TEXT_H_INCLUDED

@ -56,9 +56,3 @@ TEST_CASE("vector with zero") {
CHECK(min == -1); CHECK(min == -1);
CHECK(max == 1); CHECK(max == 1);
} }
TEST_CASE("vector with procent"){
std::vector<size_t> vec {1,2,1};
auto res = make_percentages (vec);
CHECK(res[0] == 25);
}

@ -7,11 +7,7 @@
<vector> <vector>
<iostream> <iostream>
<<<<<<< HEAD
1746447653 source:c:\users\professional\desktop\cs-lab34\lab1\unittest.cpp
=======
1746274690 source:c:\users\professional\desktop\cs-lab34\lab1\unittest.cpp 1746274690 source:c:\users\professional\desktop\cs-lab34\lab1\unittest.cpp
>>>>>>> ccff7aed06ddfe57aff6a2785558e2c335f8cf61
"doctest.h" "doctest.h"
"histogram_internal.h" "histogram_internal.h"
@ -60,9 +56,5 @@
<sys/time.h> <sys/time.h>
<unistd.h> <unistd.h>
<<<<<<< HEAD
1746447694 c:\users\professional\desktop\cs-lab34\lab1\histogram_internal.h
=======
1746444163 c:\users\professional\desktop\cs-lab34\lab1\histogram_internal.h 1746444163 c:\users\professional\desktop\cs-lab34\lab1\histogram_internal.h
>>>>>>> ccff7aed06ddfe57aff6a2785558e2c335f8cf61

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="unittest.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1494" topLine="36" />
</Cursor>
</File>
<File name="histogram_internal.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="193" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

Двоичные данные
unittest.o

Двоичный файл не отображается.
Загрузка…
Отмена
Сохранить