Сравнить коммиты
5 Коммитов
716c6bec27
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
d398de7076 | ||
|
|
dc84cefcc9 | ||
|
|
28bd0866d8 | ||
|
|
c364184a0c | ||
|
|
5cb547497e |
2
.gitignore
поставляемый
2
.gitignore
поставляемый
@@ -1,3 +1,3 @@
|
||||
/bin
|
||||
/obj
|
||||
/lab01.layout
|
||||
/curl
|
||||
|
||||
7106
doctest.h
Обычный файл
7106
doctest.h
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -1,54 +1,65 @@
|
||||
#include "text.h"
|
||||
#include "histogram.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
|
||||
using namespace std;
|
||||
//ihhkhh
|
||||
void show_histogram_text(const vector <size_t>& bins,size_t bin_count, size_t max_count)
|
||||
|
||||
bool find_minmax(const vector<double>& numbers, double& minN, double& maxN)
|
||||
{
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
bool scaling = false;
|
||||
|
||||
if (max_count > MAX_ASTERISK)
|
||||
{
|
||||
scaling = true;
|
||||
if (numbers.empty()) {
|
||||
minN = maxN = 0;
|
||||
return false;
|
||||
}
|
||||
minN = numbers[0];
|
||||
maxN = numbers[0];
|
||||
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
for (double x: numbers)
|
||||
{
|
||||
if (bins[i] < 10)
|
||||
if (minN > x)
|
||||
{
|
||||
cout << " ";
|
||||
minN = x;
|
||||
}
|
||||
else if (bins[i] < 100)
|
||||
if (maxN < x)
|
||||
{
|
||||
cout << " ";
|
||||
maxN = x;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "";
|
||||
}
|
||||
cout << bins[i] << '|';
|
||||
|
||||
size_t number_of_stars = bins[i];
|
||||
|
||||
if (scaling)
|
||||
{
|
||||
if (bins[i] == max_count)
|
||||
{
|
||||
number_of_stars = MAX_ASTERISK * 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
number_of_stars = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < number_of_stars; j++)
|
||||
{
|
||||
cout << '*';
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count)
|
||||
{
|
||||
double minN, maxN;
|
||||
find_minmax( numbers, minN, maxN);
|
||||
|
||||
vector <size_t> bins(bin_count);
|
||||
double diff = (maxN - minN) / bin_count;
|
||||
size_t max_count = 0;
|
||||
for (size_t i = 0; i <numbers.size() ; i++)
|
||||
{
|
||||
bool found = false;
|
||||
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
||||
{
|
||||
auto lo = minN + j * diff;
|
||||
auto hi = minN + (j + 1) * diff;
|
||||
if ((lo <= numbers[i]) && (hi > numbers[i]))
|
||||
{
|
||||
bins[j]++;
|
||||
if (bins[j] > max_count)
|
||||
{
|
||||
max_count = bins[j];
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
{
|
||||
bins[bin_count - 1]++;
|
||||
if (bins[bin_count - 1] > max_count)
|
||||
{
|
||||
max_count = bins[bin_count - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return bins;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define HISTOGRAM_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <cstddef>
|
||||
std::vector<size_t>
|
||||
make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
||||
|
||||
|
||||
9
histogram_internal.h
Обычный файл
9
histogram_internal.h
Обычный файл
@@ -0,0 +1,9 @@
|
||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
//std::vector<size_t>
|
||||
bool find_minmax(const std::vector<double>& numbers, double& minN, double& maxN);
|
||||
|
||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
27
lab01.cbp
27
lab01.cbp
@@ -14,6 +14,10 @@
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-static-libstdc++" />
|
||||
<Add option="-static" />
|
||||
</Linker>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/lab01" prefix_auto="1" extension_auto="1" />
|
||||
@@ -31,15 +35,30 @@
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
<Add directory="curl/include" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-static-libstdc++" />
|
||||
<Add option="-static-libgcc" />
|
||||
<Add option="-static" />
|
||||
<Add library="curl/lib/libcurl.dll.a" />
|
||||
<Add directory="curl/lib" />
|
||||
</Linker>
|
||||
<Unit filename=".gitignore" />
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h">
|
||||
<Unit filename="histogram.h" />
|
||||
<Unit filename="histogram_internal.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="main.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h">
|
||||
<Option target="<{~None~}>" />
|
||||
</Unit>
|
||||
<Extensions />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
|
||||
121
lab01.depend
121
lab01.depend
@@ -1,5 +1,124 @@
|
||||
# depslib dependency file v1.0
|
||||
1746105820 source:c:\users\liza\desktop\lab01\lab01\main.cpp
|
||||
1745706239 source:c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
"histogram.h"
|
||||
"text.h"
|
||||
"svg.h"
|
||||
|
||||
1745844301 source:c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\histogram.cpp
|
||||
"histogram.h"
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1745703309 c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\histogram.h
|
||||
<vector>
|
||||
|
||||
1745703516 source:c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\text.cpp
|
||||
"text.h"
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1745703516 c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\text.h
|
||||
<vector>
|
||||
|
||||
1745706239 c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\svg.h
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1745708042 source:c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\svg.cpp
|
||||
"svg.h"
|
||||
<string>
|
||||
|
||||
1749210284 source:c:\users\liza\desktop\lab01\lab01\main.cpp
|
||||
<iostream>
|
||||
<vector>
|
||||
<sstream>
|
||||
<string>
|
||||
"histogram.h"
|
||||
"svg.h"
|
||||
"text.h"
|
||||
<curl/curl.h>
|
||||
|
||||
1746171356 c:\users\liza\desktop\lab01\lab01\histogram.h
|
||||
<vector>
|
||||
<cstddef>
|
||||
|
||||
1746171356 c:\users\liza\desktop\lab01\lab01\text.h
|
||||
<vector>
|
||||
<cstddef>
|
||||
|
||||
1746171356 c:\users\liza\desktop\lab01\lab01\svg.h
|
||||
<iostream>
|
||||
<vector>
|
||||
<cstddef>
|
||||
|
||||
1746171356 source:c:\users\liza\desktop\lab01\lab01\histogram.cpp
|
||||
"histogram.h"
|
||||
<iostream>
|
||||
<cstddef>
|
||||
|
||||
1748597934 source:c:\users\liza\desktop\lab01\lab01\svg.cpp
|
||||
"svg.h"
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1746177922 source:c:\users\liza\desktop\lab01\lab01\text.cpp
|
||||
"text.h"
|
||||
<iostream>
|
||||
<vector>
|
||||
<cstddef>
|
||||
|
||||
1748873299 c:\users\liza\desktop\lab01\lab01\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"
|
||||
|
||||
1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\curlver.h
|
||||
|
||||
1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\system.h
|
||||
<ConditionalMacros.h>
|
||||
<inttypes.h>
|
||||
<inttypes.h>
|
||||
<sys/types.h>
|
||||
<sys/socket.h>
|
||||
<sys/poll.h>
|
||||
|
||||
1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\easy.h
|
||||
|
||||
1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\multi.h
|
||||
"curl.h"
|
||||
|
||||
1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\urlapi.h
|
||||
"curl.h"
|
||||
|
||||
1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\options.h
|
||||
|
||||
1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\header.h
|
||||
|
||||
1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\websockets.h
|
||||
|
||||
1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\mprintf.h
|
||||
<stdarg.h>
|
||||
<stdio.h>
|
||||
"curl.h"
|
||||
|
||||
1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\typecheck-gcc.h
|
||||
|
||||
|
||||
50
lab01.layout
Обычный файл
50
lab01.layout
Обычный файл
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<File name="svg.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="195" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram_internal.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="37" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="svg.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="356" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="201" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name=".gitignore" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="0" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="text.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="214" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="text.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="79" topLine="6" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="main.cpp" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="1822" topLine="60" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
128
main.cpp
128
main.cpp
@@ -1,52 +1,96 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "histogram.h"
|
||||
#include "svg.h"
|
||||
#include "text.h"
|
||||
#include <curl/curl.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
size_t number;
|
||||
cout<<"Enter number count: ";
|
||||
cin>> number;
|
||||
struct Input
|
||||
{
|
||||
vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
};
|
||||
|
||||
vector <double> count(number);
|
||||
cout<< "enter chicla";
|
||||
for (int i=0;i<number;i++){
|
||||
cin>>count[i];
|
||||
Input input_data(istream& in, bool prompt = true) {
|
||||
Input data;
|
||||
size_t number_count;
|
||||
|
||||
if (prompt) {
|
||||
cerr << "Enter number count: ";
|
||||
}
|
||||
in >> number_count;
|
||||
|
||||
data.numbers.resize(number_count);
|
||||
if (prompt) {
|
||||
cerr << "Enter numbers: ";
|
||||
}
|
||||
for (size_t i = 0; i < number_count; i++) {
|
||||
in >> data.numbers[i];
|
||||
}
|
||||
|
||||
size_t bin_count;
|
||||
cout<<"Enter number bin_count: ";
|
||||
cin>> bin_count;
|
||||
|
||||
vector <size_t> bins(bin_count);
|
||||
|
||||
double max=count[0];
|
||||
for (size_t i=0;i<number; i++){
|
||||
if(count[i]> max){
|
||||
max=count[i];
|
||||
}
|
||||
if (prompt) {
|
||||
cerr << "Enter number of bins: ";
|
||||
}
|
||||
in >> data.bin_count;
|
||||
|
||||
double min=count[0];
|
||||
for (size_t i=0;i<number; i++){
|
||||
if(count[i]<min){
|
||||
min=count[i];
|
||||
}
|
||||
}
|
||||
|
||||
double bin_size = (max-min)/bin_count;
|
||||
|
||||
for(size_t i = 0; i<number; i++){
|
||||
bool found=false;
|
||||
for(size_t j=0; (j<bin_count-1) && !found; j++){
|
||||
auto lo = min+j*bin_size;
|
||||
auto hi = min+(j+1)*bin_size;
|
||||
if ((lo<=count[i])&&(count[i]<hi)){
|
||||
bins[j]++;
|
||||
found=true;
|
||||
}
|
||||
}
|
||||
if (!found){
|
||||
bins[bin_count-1]++;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
static size_t Write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
||||
size_t data_size = item_size * item_count;
|
||||
auto* buffer = reinterpret_cast<stringstream*>(ctx);
|
||||
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
||||
return data_size;
|
||||
}
|
||||
|
||||
|
||||
Input download(const string& address) {
|
||||
stringstream buffer;
|
||||
CURL* curl = curl_easy_init();
|
||||
|
||||
if (!curl) {
|
||||
cerr << "Error: Failed to invent cURL" << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Write_data);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
if (res != CURLE_OK) {
|
||||
cerr << "Loading error: " << curl_easy_strerror(res) << endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Ïîëó÷åíèå âðåìåíè name lookup
|
||||
double name_lookup_time;
|
||||
curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &name_lookup_time);
|
||||
cerr << "Name lookup time: " << name_lookup_time << " seconds" << endl;
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
return input_data(buffer, false);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
Input input;
|
||||
if (argc > 1) {
|
||||
input = download(argv[1]);
|
||||
}
|
||||
else {
|
||||
input = input_data(cin, true);
|
||||
}
|
||||
size_t max_count;
|
||||
auto bins = make_histogram(input.numbers, input.bin_count);
|
||||
show_histogram_svg(bins);
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
}
|
||||
|
||||
60
svg.cpp
Обычный файл
60
svg.cpp
Обычный файл
@@ -0,0 +1,60 @@
|
||||
#include "svg.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void svg_begin(double width, double height) {
|
||||
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||
cout << "<svg ";
|
||||
cout << "width='" << width << "' ";
|
||||
cout << "height='" << height << "' ";
|
||||
cout << "viewBox='0 0 " << width << " " << height << "' ";
|
||||
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||
}
|
||||
|
||||
void svg_end() {
|
||||
cout << "</svg>\n";
|
||||
}
|
||||
|
||||
void svg_text(double left, double baseline, string text) {
|
||||
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
|
||||
}
|
||||
|
||||
void svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black") {
|
||||
cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "'/>";
|
||||
}
|
||||
|
||||
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 BLOCK_WIDTH = 10;
|
||||
const auto MAX_BIN_WIDTH = IMAGE_WIDTH - 2.3 * TEXT_WIDTH;
|
||||
auto max_bins = bins[0];
|
||||
size_t sum_bins = 0;
|
||||
|
||||
for (size_t bin : bins) sum_bins += bin;
|
||||
|
||||
for (size_t bin : bins) {
|
||||
if (bin > max_bins) max_bins = bin;
|
||||
}
|
||||
|
||||
auto koef = MAX_BIN_WIDTH / BLOCK_WIDTH / max_bins;
|
||||
|
||||
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||
double top = 0;
|
||||
for (size_t bin : bins) {
|
||||
const double bin_width = BLOCK_WIDTH * bin * koef;
|
||||
|
||||
size_t percent = bin * 100 / sum_bins;
|
||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
||||
svg_text((IMAGE_WIDTH - TEXT_WIDTH), top + TEXT_BASELINE, to_string(percent));
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
svg_end();
|
||||
}
|
||||
8
svg.h
Обычный файл
8
svg.h
Обычный файл
@@ -0,0 +1,8 @@
|
||||
#ifndef SVG_H_INCLUDED
|
||||
#define SVG_H_INCLUDED
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
void show_histogram_svg(const std::vector<size_t> &bins);
|
||||
|
||||
#endif // SVG_H_INCLUDED
|
||||
56
text.cpp
Обычный файл
56
text.cpp
Обычный файл
@@ -0,0 +1,56 @@
|
||||
#include "text.h"
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void show_histogram_text(const vector <size_t>& bins,size_t bin_count, size_t max_count)
|
||||
{
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
bool scaling = false;
|
||||
|
||||
if (max_count > MAX_ASTERISK)
|
||||
{
|
||||
scaling = true;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < bin_count; i++)
|
||||
{
|
||||
if (bins[i] < 10)
|
||||
{
|
||||
cout << " ";
|
||||
}
|
||||
else if (bins[i] < 100)
|
||||
{
|
||||
cout << " ";
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "";
|
||||
}
|
||||
cout << bins[i] << '|';
|
||||
|
||||
size_t number_of_stars = bins[i];
|
||||
|
||||
if (scaling)
|
||||
{
|
||||
if (bins[i] == max_count)
|
||||
{
|
||||
number_of_stars = MAX_ASTERISK * 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
number_of_stars = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t j = 0; j < number_of_stars; j++)
|
||||
{
|
||||
cout << '*';
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
7
text.h
Обычный файл
7
text.h
Обычный файл
@@ -0,0 +1,7 @@
|
||||
#ifndef TEXT_H_INCLUDED
|
||||
#define TEXT_H_INCLUDED
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
void show_histogram_text(const std::vector <size_t>& bins,size_t bin_count, size_t max_count);
|
||||
|
||||
#endif // TEXT_H_INCLUDED
|
||||
41
unittest.cbp
Обычный файл
41
unittest.cbp
Обычный файл
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="unittest" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/unittest" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Debug/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-g" />
|
||||
</Compiler>
|
||||
</Target>
|
||||
<Target title="Release">
|
||||
<Option output="bin/Release/unittest" prefix_auto="1" extension_auto="1" />
|
||||
<Option object_output="obj/Release/" />
|
||||
<Option type="1" />
|
||||
<Option compiler="gcc" />
|
||||
<Compiler>
|
||||
<Add option="-O2" />
|
||||
</Compiler>
|
||||
<Linker>
|
||||
<Add option="-s" />
|
||||
</Linker>
|
||||
</Target>
|
||||
</Build>
|
||||
<Compiler>
|
||||
<Add option="-Wall" />
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram_internal.h" />
|
||||
<Unit filename="unittest.cpp" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
48
unittest.cpp
Обычный файл
48
unittest.cpp
Обычный файл
@@ -0,0 +1,48 @@
|
||||
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
#include <vector>
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1, 2}, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
CHECK(find_minmax({1, 2}, min, max));
|
||||
}
|
||||
|
||||
TEST_CASE("distinct negative numbers")
|
||||
{
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({-1, -2}, min, max);
|
||||
CHECK(min == -2);
|
||||
CHECK(max == -1);
|
||||
CHECK(find_minmax({-1, -2}, min, max));
|
||||
}
|
||||
TEST_CASE("vector 1 element")
|
||||
{
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1}, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 1);
|
||||
CHECK(find_minmax({1}, min, max));
|
||||
}
|
||||
TEST_CASE("distinct equals numbers")
|
||||
{
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1, 1}, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 1);
|
||||
CHECK(find_minmax({1, 1}, min, max));
|
||||
}
|
||||
TEST_CASE("distinct empty vector")
|
||||
{
|
||||
double min = -1;
|
||||
double max = -1;
|
||||
CHECK(!find_minmax({}, min, max));
|
||||
}
|
||||
62
unittest.depend
Обычный файл
62
unittest.depend
Обычный файл
@@ -0,0 +1,62 @@
|
||||
# depslib dependency file v1.0
|
||||
1745848382 source:c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\histogram.cpp
|
||||
"histogram.h"
|
||||
<iostream>
|
||||
<vector>
|
||||
|
||||
1745845585 c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\histogram.h
|
||||
<vector>
|
||||
|
||||
1745848628 source:c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\unittest.cpp
|
||||
"doctest.h"
|
||||
"histogram_internal.h"
|
||||
<vector>
|
||||
|
||||
1745704427 c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\doctest.h
|
||||
<signal.h>
|
||||
<ciso646>
|
||||
<cstddef>
|
||||
<ostream>
|
||||
<istream>
|
||||
<type_traits>
|
||||
"doctest_fwd.h"
|
||||
<ctime>
|
||||
<cmath>
|
||||
<climits>
|
||||
<math.h>
|
||||
<new>
|
||||
<cstdio>
|
||||
<cstdlib>
|
||||
<cstring>
|
||||
<limits>
|
||||
<utility>
|
||||
<fstream>
|
||||
<sstream>
|
||||
<iostream>
|
||||
<algorithm>
|
||||
<iomanip>
|
||||
<vector>
|
||||
<atomic>
|
||||
<mutex>
|
||||
<set>
|
||||
<map>
|
||||
<unordered_set>
|
||||
<exception>
|
||||
<stdexcept>
|
||||
<csignal>
|
||||
<cfloat>
|
||||
<cctype>
|
||||
<cstdint>
|
||||
<string>
|
||||
<sys/types.h>
|
||||
<unistd.h>
|
||||
<sys/sysctl.h>
|
||||
<AfxWin.h>
|
||||
<windows.h>
|
||||
<io.h>
|
||||
<sys/time.h>
|
||||
<unistd.h>
|
||||
|
||||
1745848412 c:\users\lenovo\documents\labsproga2sem\firstlaba\lab01\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
20
unittest.layout
Обычный файл
20
unittest.layout
Обычный файл
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_layout_file>
|
||||
<FileVersion major="1" minor="0" />
|
||||
<ActiveTarget name="Debug" />
|
||||
<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="250" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="histogram.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="223" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
<File name="unittest.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||
<Cursor>
|
||||
<Cursor1 position="372" topLine="0" />
|
||||
</Cursor>
|
||||
</File>
|
||||
</CodeBlocks_layout_file>
|
||||
Ссылка в новой задаче
Block a user