Сравнить коммиты
8 Коммитов
ccff7aed06
...
master
| Автор | SHA1 | Дата | |
|---|---|---|---|
| d9a2b3648a | |||
| 85eb559f72 | |||
| 9f5bbe976c | |||
| b1c26a9503 | |||
| ee9b12fc4f | |||
| 30304c0921 | |||
| bb51ae70ea | |||
| 7892d51950 |
2
.gitignore
поставляемый
2
.gitignore
поставляемый
@@ -1,3 +1,5 @@
|
||||
/bin
|
||||
/obj
|
||||
/lab1.layout
|
||||
/curl
|
||||
/lab1.depend
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "histogram.h"
|
||||
#include <cmath>
|
||||
|
||||
bool find_minmax(vector<double> vec, double& min, double& max) {
|
||||
if (vec.size() == 0) {
|
||||
cerr << "Empty vec";
|
||||
@@ -40,19 +40,3 @@ vector<size_t> make_histogram(size_t number, vector<double> vec) {
|
||||
}
|
||||
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
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
vector<size_t> make_histogram(size_t number, vector<double> vec);
|
||||
vector<int> make_percentages(const vector<size_t>& bins);
|
||||
#endif // HISTOGRAM_H_INCLUDED
|
||||
|
||||
@@ -2,5 +2,4 @@
|
||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
|
||||
bool find_minmax(std::vector<double> vec, double& min, double& max);
|
||||
|
||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
|
||||
5
lab1.cbp
5
lab1.cbp
@@ -31,7 +31,12 @@
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
<Add directory="C:/Users/Professional/Desktop/cs-lab34/lab1/curl/include" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add library="C:/Users/Professional/Desktop/cs-lab34/lab1/curl/lib/libcurl.dll.a" />
|
||||
<Add directory="C:/Users/Professional/Desktop/cs-lab34/lab1/curl/lib" />
|
||||
</Linker>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h">
|
||||
<Option target="<{~None~}>" />
|
||||
|
||||
85
lab1.depend
Обычный файл
85
lab1.depend
Обычный файл
@@ -0,0 +1,85 @@
|
||||
# depslib dependency file v1.0
|
||||
1747403716 source:c:\users\professional\desktop\cs-lab34\lab1\histogram.cpp
|
||||
"histogram.h"
|
||||
|
||||
1747403716 c:\users\professional\desktop\cs-lab34\lab1\histogram.h
|
||||
<vector>
|
||||
<iostream>
|
||||
|
||||
1747403716 source:c:\users\professional\desktop\cs-lab34\lab1\text.cpp
|
||||
"text.h"
|
||||
|
||||
1747403716 c:\users\professional\desktop\cs-lab34\lab1\text.h
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1747651892 source:c:\users\professional\desktop\cs-lab34\lab1\main.cpp
|
||||
<curl/curl.h>
|
||||
"histogram.h"
|
||||
"text.h"
|
||||
"svg.h"
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1747403716 c:\users\professional\desktop\cs-lab34\lab1\svg.h
|
||||
<iostream>
|
||||
<vector>
|
||||
<string>
|
||||
<math.h>
|
||||
|
||||
1747403716 source:c:\users\professional\desktop\cs-lab34\lab1\svg.cpp
|
||||
"svg.h"
|
||||
|
||||
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\curl.h
|
||||
"curlver.h"
|
||||
"system.h"
|
||||
<stdio.h>
|
||||
<limits.h>
|
||||
<sys/param.h>
|
||||
<sys/types.h>
|
||||
<time.h>
|
||||
<winsock2.h>
|
||||
<ws2tcpip.h>
|
||||
<sys/select.h>
|
||||
<sys/socket.h>
|
||||
<sys/time.h>
|
||||
"easy.h"
|
||||
"multi.h"
|
||||
"urlapi.h"
|
||||
"options.h"
|
||||
"header.h"
|
||||
"websockets.h"
|
||||
"mprintf.h"
|
||||
"typecheck-gcc.h"
|
||||
|
||||
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\curlver.h
|
||||
|
||||
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\system.h
|
||||
<ConditionalMacros.h>
|
||||
<inttypes.h>
|
||||
<inttypes.h>
|
||||
<sys/types.h>
|
||||
<sys/socket.h>
|
||||
<sys/poll.h>
|
||||
|
||||
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\easy.h
|
||||
|
||||
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\multi.h
|
||||
"curl.h"
|
||||
|
||||
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\urlapi.h
|
||||
"curl.h"
|
||||
|
||||
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\options.h
|
||||
|
||||
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\header.h
|
||||
|
||||
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\websockets.h
|
||||
|
||||
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\mprintf.h
|
||||
<stdarg.h>
|
||||
<stdio.h>
|
||||
"curl.h"
|
||||
|
||||
1743562062 c:\users\professional\desktop\cs-lab34\lab1\curl\include\curl\typecheck-gcc.h
|
||||
|
||||
66
main.cpp
66
main.cpp
@@ -1,26 +1,68 @@
|
||||
#include <iostream>
|
||||
#include <curl/curl.h>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct Input {
|
||||
vector<double> vec;
|
||||
size_t korz{};
|
||||
};
|
||||
Input input_data() {
|
||||
Input in;
|
||||
|
||||
Input input_data(istream &in, bool prompt) {
|
||||
Input data;
|
||||
size_t n, korz;
|
||||
|
||||
if (prompt) {
|
||||
cerr << "Number of elements: ";
|
||||
cin >> n;
|
||||
in.vec.resize(n);
|
||||
}
|
||||
in >> n;
|
||||
data.vec.resize(n);
|
||||
|
||||
if (prompt) {
|
||||
cerr << "Elements: ";
|
||||
for (size_t i = 0; i < n; i++)
|
||||
cin >> in.vec[i];
|
||||
}
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
in >> data.vec[i];
|
||||
}
|
||||
|
||||
if (prompt) {
|
||||
cerr << "Enter bin count: ";
|
||||
cin >> in.korz;
|
||||
return in;
|
||||
}
|
||||
in >> korz;
|
||||
data.korz = korz;
|
||||
|
||||
return data;
|
||||
}
|
||||
int main() {
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.korz, in.vec);
|
||||
show_histogram_svg(bins);
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
if (argc > 1) {
|
||||
const char *url = argv[1];
|
||||
|
||||
CURL *curl = curl_easy_init();
|
||||
if (curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK) {
|
||||
cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto in_with_prompt = input_data(cin, true);
|
||||
auto bins_with_prompt = make_histogram(in_with_prompt.korz, in_with_prompt.vec);
|
||||
show_histogram_svg(bins_with_prompt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
66
svg.cpp
66
svg.cpp
@@ -1,5 +1,5 @@
|
||||
#include "svg.h"
|
||||
#include <cmath>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void
|
||||
@@ -34,62 +34,38 @@ svg_rect(double x, double y, double width, double height, string stroke = "black
|
||||
|
||||
|
||||
|
||||
|
||||
void show_histogram_svg(const vector<size_t>& bins)
|
||||
{
|
||||
const auto ORIG_WIDTH = 400;
|
||||
const auto PADDING_RIGHT = 50;
|
||||
const auto IMAGE_WIDTH = ORIG_WIDTH + PADDING_RIGHT;
|
||||
void
|
||||
show_histogram_svg(const vector<size_t>& bins)
|
||||
{
|
||||
const auto IMAGE_WIDTH = 400;
|
||||
const auto IMAGE_HEIGHT = 300;
|
||||
const auto TEXT_LEFT = 20;
|
||||
const auto TEXT_BASELINE = 20;
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLACK = "black";
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
const auto GREEN = "green";
|
||||
const auto RED = "red";
|
||||
const auto MAX_WIDTH = ORIG_WIDTH - TEXT_WIDTH;
|
||||
const auto PERCENT_X = TEXT_WIDTH + MAX_WIDTH + 10;
|
||||
const auto MAX_WIDTH = IMAGE_WIDTH - TEXT_WIDTH;
|
||||
|
||||
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;
|
||||
}
|
||||
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
|
||||
|
||||
double top = 0;
|
||||
for (auto b : bins) {
|
||||
|
||||
double bin_width = 0;
|
||||
if (max_count > 0) {
|
||||
bin_width = MAX_WIDTH * (b / max_count);
|
||||
double max_count = bins[0];
|
||||
for (size_t i = 0; i < bins.size(); i++)
|
||||
{
|
||||
if (max_count < bins[i])
|
||||
{
|
||||
max_count = bins[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(b));
|
||||
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, BLACK, 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);
|
||||
|
||||
for (size_t bin : bins)
|
||||
{
|
||||
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, GREEN, RED);
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
|
||||
|
||||
116
text.cpp
116
text.cpp
@@ -1,15 +1,9 @@
|
||||
#include "text.h"
|
||||
#include "histogram.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
void show_histogram(vector<size_t> bins) {
|
||||
void show_histogram(std::vector<size_t> bins) {
|
||||
bool gigant = false;
|
||||
size_t spaces = 0;
|
||||
auto spaces = 0;
|
||||
size_t mx_count = 0;
|
||||
|
||||
|
||||
for (auto x : bins) {
|
||||
if (x > 76) {
|
||||
gigant = true;
|
||||
@@ -17,68 +11,72 @@ void show_histogram(vector<size_t> bins) {
|
||||
if (x > mx_count) {
|
||||
mx_count = x;
|
||||
}
|
||||
size_t len = 0;
|
||||
size_t t = x;
|
||||
do {
|
||||
t /= 10;
|
||||
auto len = 0;
|
||||
while (x > 0) {
|
||||
x /= 10;
|
||||
len++;
|
||||
} while (t > 0);
|
||||
}
|
||||
if (len > spaces) {
|
||||
spaces = len;
|
||||
}
|
||||
}
|
||||
|
||||
size_t bar_max_width;
|
||||
if (gigant) {
|
||||
bar_max_width = 76;
|
||||
} else {
|
||||
bar_max_width = mx_count;
|
||||
}
|
||||
|
||||
auto percentages = make_percentages(bins);
|
||||
|
||||
for (size_t i = 0; i < bins.size(); ++i) {
|
||||
|
||||
size_t len = 0;
|
||||
size_t t = bins[i];
|
||||
do {
|
||||
t /= 10;
|
||||
len++;
|
||||
} while (t > 0);
|
||||
for (size_t s = len; s < spaces + 1; ++s) {
|
||||
cout << " ";
|
||||
}
|
||||
cout << bins[i] << "|";
|
||||
|
||||
|
||||
size_t star_count = 0;
|
||||
if (spaces == 1) {
|
||||
for (size_t i = 0; i < bins.size(); i++) {
|
||||
std::cout << " " << bins[i] << "|";
|
||||
if (gigant) {
|
||||
if (bins[i] == mx_count) {
|
||||
star_count = 76;
|
||||
} else {
|
||||
star_count = static_cast<size_t>(76 * static_cast<double>(bins[i]) / mx_count);
|
||||
for (size_t j = 0; j < 76; j++) {
|
||||
std::cout << "*";
|
||||
}
|
||||
} else {
|
||||
star_count = bins[i];
|
||||
}
|
||||
for (size_t j = 0; j < star_count; ++j) {
|
||||
cout << "*";
|
||||
else
|
||||
{
|
||||
for (size_t j = 0; j < 76 * static_cast<double>(bins[i]) / mx_count; j++) {
|
||||
std::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";
|
||||
else
|
||||
{
|
||||
for (size_t j = 0; j < bins[i]; j++) {
|
||||
std::cout << "*";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < bins.size(); i++) {
|
||||
int len = 1;
|
||||
int k = bins[i];
|
||||
for (; k /= 10; ++len);
|
||||
while (len < spaces) {
|
||||
std::cout << " ";
|
||||
len++;
|
||||
}
|
||||
std::cout << bins[i];
|
||||
std::cout << "|";
|
||||
if (gigant) {
|
||||
if (bins[i] == mx_count) {
|
||||
for (size_t j = 0; j < 76; j++) {
|
||||
std::cout << "*";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t j = 0; j < (76 * static_cast<double>(bins[i]) / mx_count - 1); j++) {
|
||||
std::cout << "*";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t j = 0; j < bins[i]; j++) {
|
||||
std::cout << "*";
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
text.h
1
text.h
@@ -5,5 +5,4 @@
|
||||
#include <vector>
|
||||
|
||||
void show_histogram(std::vector<size_t> bins);
|
||||
|
||||
#endif // TEXT_H_INCLUDED
|
||||
|
||||
@@ -56,3 +56,9 @@ TEST_CASE("vector with zero") {
|
||||
CHECK(min == -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,7 +7,11 @@
|
||||
<vector>
|
||||
<iostream>
|
||||
|
||||
<<<<<<< HEAD
|
||||
1746447653 source:c:\users\professional\desktop\cs-lab34\lab1\unittest.cpp
|
||||
=======
|
||||
1746274690 source:c:\users\professional\desktop\cs-lab34\lab1\unittest.cpp
|
||||
>>>>>>> ccff7aed06ddfe57aff6a2785558e2c335f8cf61
|
||||
"doctest.h"
|
||||
"histogram_internal.h"
|
||||
|
||||
@@ -56,5 +60,9 @@
|
||||
<sys/time.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
|
||||
>>>>>>> ccff7aed06ddfe57aff6a2785558e2c335f8cf61
|
||||
|
||||
|
||||
15
unittest.layout
Обычный файл
15
unittest.layout
Обычный файл
@@ -0,0 +1,15 @@
|
||||
<?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
Обычный файл
Двоичные данные
unittest.o
Обычный файл
Двоичный файл не отображается.
Ссылка в новой задаче
Block a user