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

..

4 Коммитов

Автор SHA1 Сообщение Дата
Dmitri (Krivov)
adbbe8862d full lab03 2025-05-04 22:38:06 +03:00
Dmitri (Krivov)
0f65ce7b08 finish version 2025-05-04 22:35:26 +03:00
Dmitri (Krivov)
4574a4c976 doctest library 2025-05-04 21:25:18 +03:00
Dmitri (Krivov)
c176293107 changed code 2025-05-04 21:00:42 +03:00
37 изменённых файлов: 7610 добавлений и 79 удалений

3
bin/Debug/01-example.actual.txt Обычный файл
Просмотреть файл

@@ -0,0 +1,3 @@
2|**
5|*****
3|***

3
bin/Debug/01-example.expected.txt Обычный файл
Просмотреть файл

@@ -0,0 +1,3 @@
2|**
5|*****
3|***

3
bin/Debug/01-example.input.txt Обычный файл
Просмотреть файл

@@ -0,0 +1,3 @@
10
4 4 3 5 3 4 5 5 4 4
3

3
bin/Debug/02-alignment.expected.txt Обычный файл
Просмотреть файл

@@ -0,0 +1,3 @@
9|*********
33|*********************************
100|****************************************************************************************************

5
bin/Debug/02-alignment.input.txt Обычный файл
Просмотреть файл

@@ -0,0 +1,5 @@
142
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3

Двоичные данные
bin/Debug/lab01.exe Обычный файл

Двоичный файл не отображается.

3
bin/Debug/marks.svg Обычный файл
Просмотреть файл

@@ -0,0 +1,3 @@
<?xml version='1.0' encoding='UTF-8'?>
<svg width='400' height='300' viewBox='0 0 400 300' xmlns='http://www.w3.org/2000/svg'>
<text x='20' y='20'>2</text><rect x='50' y='0' width='20' height='30' stroke='blue' fill='green '/><text x='20' y='50'>5</text><rect x='50' y='30' width='50' height='30' stroke='blue' fill='green '/><text x='20' y='80'>3</text><rect x='50' y='60' width='30' height='30' stroke='blue' fill='green '/></svg>

После

Ширина:  |  Высота:  |  Размер: 433 B

3
bin/Debug/marks.txt Обычный файл
Просмотреть файл

@@ -0,0 +1,3 @@
10
3 3 4 4 4 4 4 5 5 5
3

2
bin/Debug/test1.bat Обычный файл
Просмотреть файл

@@ -0,0 +1,2 @@
lab01.exe < 01-example.input.txt > 01-example.actual.txt 2>NUL
fc /N 01-example.actual.txt 01-example.expected.txt || pause

2
bin/Debug/test2.bat Обычный файл
Просмотреть файл

@@ -0,0 +1,2 @@
lab01.exe < 02-alignment.input.txt > 01-example.actual.txt 2>NUL
fc /N 01-example.actual.txt 02-alignment.expected.txt || pause

Двоичные данные
bin/Debug/unittest.exe Обычный файл

Двоичный файл не отображается.

7134
doctest.h Обычный файл

Разница между файлами не показана из-за своего большого размера Загрузить разницу

58
histogram.cpp Обычный файл
Просмотреть файл

@@ -0,0 +1,58 @@
#include "histogram.h"
#include "histogram_internal.h"
using namespace std;
void
find_minmax(const vector<double>& numbers, double& min, double& max)
{
min = numbers[0];
max = numbers[0];
for (double x : numbers)
{
if (x<min)
{
min=x;
}
else if (x>max)
{
max=x;
}
}
}
vector<size_t>
make_histogram(const vector<double>& numbers, size_t bin_count)
{
vector<size_t> bins(bin_count);
double min, max;
find_minmax(numbers, min, max);
double bin_size = (max - min) / 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 = min + j * bin_size;
auto hi = min + (j + 1) * bin_size;
if ((lo <= numbers[i]) && (numbers[i] < hi))
{
bins[j]++;
if (bins[j] > max_count)
{
max_count = bins[j];
}
found = true;
}
}
if (!found)
{
bins[bin_count - 1]++;
}
}
return bins;
}

9
histogram.h Обычный файл
Просмотреть файл

@@ -0,0 +1,9 @@
#ifndef HISTOGRAM_H_INCLUDED
#define HISTOGRAM_H_INCLUDED
#include <vector>
std::vector<size_t>
make_histogram(const std::vector<double>& numbers, size_t bin_count);
#endif // HISTOGRAM_H_INCLUDED

9
histogram_internal.h Обычный файл
Просмотреть файл

@@ -0,0 +1,9 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
#include <vector>
void
find_minmax(const std::vector<double>& numbers, double& min, double& max);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED

0
lab01 Обычный файл
Просмотреть файл

Просмотреть файл

@@ -32,7 +32,22 @@
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
</Compiler> </Compiler>
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="histogram_internal.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 />
</Project> </Project>
</CodeBlocks_project_file> </CodeBlocks_project_file>

29
lab01.depend Обычный файл
Просмотреть файл

@@ -0,0 +1,29 @@
# depslib dependency file v1.0
1746385589 source:c:\users\krivo\desktop\lab03\main.cpp
<iostream>
<vector>
"histogram.h"
"text.h"
"svg.h"
1746381170 c:\users\krivo\desktop\lab03\histogram.h
<vector>
1746383913 source:c:\users\krivo\desktop\lab03\histogram.cpp
"histogram.h"
"histogram_internal.h"
1746381509 c:\users\krivo\desktop\lab03\text.h
<vector>
1746382043 source:c:\users\krivo\desktop\lab03\text.cpp
"text.h"
<iostream>
1746383746 c:\users\krivo\desktop\lab03\histogram_internal.h
<vector>
1746386429 c:\users\krivo\desktop\lab03\svg.h
<vector>
<string>

40
lab01.layout Обычный файл
Просмотреть файл

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="623" topLine="10" />
</Cursor>
</File>
<File name="histogram.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="124" topLine="0" />
</Cursor>
</File>
<File name="text.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="52" topLine="0" />
</Cursor>
</File>
<File name="text.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="histogram_internal.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="205" topLine="0" />
</Cursor>
</File>
<File name="svg.cpp" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="40" topLine="0" />
</Cursor>
</File>
<File name="histogram.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

Просмотреть файл

@@ -1,98 +1,43 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "histogram.h"
#include "text.h"
#include "svg.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;
void printspace (int number) struct
{ Input {
if (number < 10) cout << " "; vector<double> numbers;
else if (number < 100) cout << " "; size_t bin_count{};
} };
int main() Input
input_data ()
{ {
Input in;
size_t number_count; size_t number_count;
cerr << "enter number count: "; cerr << "enter number count: ";
cin >> number_count; cin >> number_count;
vector<double> numbers(number_count); in.numbers.resize(number_count);
for (size_t i=0; i<number_count; i++) for (size_t i=0; i<number_count; i++)
{ {
cerr << "enter number" << (i+1) << ": "; cerr << "enter number" << (i+1) << ": ";
cin >> numbers[i]; cin >> in.numbers[i];
}
size_t bin_count;
cerr << "enter bin count: ";
cin >> bin_count;
vector<size_t> bins(bin_count);
double min = numbers[0];
double max = numbers[0];
for (double x : numbers)
{
if (x<min)
{
min=x;
}
else if (x>max)
{
max=x;
} }
cin >> in.bin_count;
return in;
} }
double bin_size = (max - min) / bin_count; int
main()
size_t max_count = 0;
for (size_t i = 0; i < number_count; i++)
{ {
bool found = false; auto in = input_data();
for (size_t j = 0; (j < bin_count - 1) && !found; j++) auto bins = make_histogram(in.numbers, in.bin_count);
{ show_histogram_svg(bins);
auto lo = min + j * bin_size;
auto hi = min + (j + 1) * bin_size;
if ((lo <= numbers[i]) && (numbers[i] < hi))
{
bins[j]++;
if (bins[j] > max_count)
{
max_count = bins[j];
}
found = true;
}
}
if (!found)
{
bins[bin_count - 1]++;
}
}
if (max_count <= 76)
{
for (size_t i = 0; i < bin_count; i++)
{
printspace(bins[i]);
cout << bins[i] << "|";
for (size_t j = 0; j < bins[i]; j++)
{
cout << "*";
}
cout << endl;
}
}
else
{
for (size_t i = 0; i < bin_count; i++){
size_t height = 76 * (static_cast<double>(bins[i]) / max_count);
printSpace(bins[i]);
cout << bins[i] << "|";
for (size_t j = 0; j < height; j++)
{
cout << "*";
}
cout << endl;
} }

Двоичные данные
main.exe Обычный файл

Двоичный файл не отображается.

Двоичные данные
main.o Обычный файл

Двоичный файл не отображается.

3
marks.txt Обычный файл
Просмотреть файл

@@ -0,0 +1,3 @@
10
3 3 4 4 4 4 4 5 5 5
3

Двоичные данные
obj/Debug/histogram.o Обычный файл

Двоичный файл не отображается.

Двоичные данные
obj/Debug/main.o Обычный файл

Двоичный файл не отображается.

Двоичные данные
obj/Debug/svg.o Обычный файл

Двоичный файл не отображается.

Двоичные данные
obj/Debug/text.o Обычный файл

Двоичный файл не отображается.

Двоичные данные
obj/Debug/unittest.o Обычный файл

Двоичный файл не отображается.

67
svg.cpp Обычный файл
Просмотреть файл

@@ -0,0 +1,67 @@
#include "svg.h"
#include <string>
#include <iostream>
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, string fill)
{
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;
svg_begin(400, 300);
double top = 0;
for (size_t bin : bins)
{
const double bin_width = BLOCK_WIDTH * bin;
if(bin_width> IMAGE_WIDTH)
{
const double bin_width= IMAGE_WIDTH - TEXT_WIDTH;
}
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "light blue");
top += BIN_HEIGHT;
}
//svg_text(20, 20, to_string(bins[0]));
//svg_rect(50, 0, bins[0] * 10, 30);
svg_end();
}

23
svg.h Обычный файл
Просмотреть файл

@@ -0,0 +1,23 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
#include <vector>
#include<string>
using namespace std;
void
svg_begin(double width, double height);
void
svg_end();
void
svg_text(double left, double baseline, string text);
void
svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black");
void
show_histogram_svg(const vector<size_t>& bins);
#endif // SVG_H_INCLUDED

48
text.cpp Обычный файл
Просмотреть файл

@@ -0,0 +1,48 @@
#include "text.h"
#include <iostream>
using namespace std;
void
static printspace (int number)
{
if (number < 10) cout << " ";
else if (number < 100) cout << " ";
}
void
show_histogram_text(const vector<size_t>& bins, size_t bin_count)
{
size_t max_count = 0;
for (int i = 0; i < bins.size(); i++)
{
if (bins[i] > max_count) max_count = bins[i];
}
if (max_count <= 76)
{
for (size_t i = 0; i < bin_count; i++)
{
printspace(bins[i]);
cout << bins[i] << "|";
for (size_t j = 0; j < bins[i]; j++)
{
cout << "*";
}
cout << endl;
}
}
else
{
for (size_t i = 0; i < bin_count; i++)
{
size_t height = 76 * (static_cast<double>(bins[i]) / max_count);
printspace(bins[i]);
cout << bins[i] << "|";
for (size_t j = 0; j < height; j++)
{
cout << "*";
}
cout << endl;
}
}
}

9
text.h Обычный файл
Просмотреть файл

@@ -0,0 +1,9 @@
#ifndef TEXT_H_INCLUDED
#define TEXT_H_INCLUDED
#include <vector>
void
show_histogram_text(const std::vector<size_t>& bins, size_t bin_count);
#endif // TEXT_H_INCLUDED

38
unittest.cbp Обычный файл
Просмотреть файл

@@ -0,0 +1,38 @@
<?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>
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

12
unittest.cpp Обычный файл
Просмотреть файл

@@ -0,0 +1,12 @@
#define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "histogram_internal.h"
TEST_CASE("distinct positive numbers") {
double min = 0;
double max = 0;
find_minmax({1, 2}, min, max);
CHECK(min == 1);
CHECK(max == 2);
}

60
unittest.depend Обычный файл
Просмотреть файл

@@ -0,0 +1,60 @@
# depslib dependency file v1.0
1746383500 source:c:\users\krivo\desktop\lab03\unittest.cpp
"doctest.h"
"histogram_internal.h"
1746383051 c:\users\krivo\desktop\lab03\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>
1746383746 c:\users\krivo\desktop\lab03\histogram_internal.h
<vector>
1746383913 source:c:\users\krivo\desktop\lab03\histogram.cpp
"histogram.h"
"histogram_internal.h"
1746381170 c:\users\krivo\desktop\lab03\histogram.h
<vector>

5
unittest.layout Обычный файл
Просмотреть файл

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
</CodeBlocks_layout_file>

Двоичные данные
Архив WinRAR (2).rar Обычный файл

Двоичный файл не отображается.