закинул всё что мог)
Этот коммит содержится в:
3
.gitignore
поставляемый
Обычный файл
3
.gitignore
поставляемый
Обычный файл
@@ -0,0 +1,3 @@
|
|||||||
|
/bin
|
||||||
|
/obj
|
||||||
|
*.layout
|
||||||
7106
doctest.h
Обычный файл
7106
doctest.h
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
42
histogram.cpp
Обычный файл
42
histogram.cpp
Обычный файл
@@ -0,0 +1,42 @@
|
|||||||
|
#include "histogram.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){
|
||||||
|
|
||||||
|
double min, max;
|
||||||
|
find_minmax(numbers, min, max);
|
||||||
|
double bin_size = (max - min) / bin_count;
|
||||||
|
vector<size_t> bins(bin_count);
|
||||||
|
|
||||||
|
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]++;
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
bins[bin_count - 1]++;
|
||||||
|
}}
|
||||||
|
|
||||||
|
return bins;
|
||||||
|
}
|
||||||
11
histogram.h
Обычный файл
11
histogram.h
Обычный файл
@@ -0,0 +1,11 @@
|
|||||||
|
#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
Обычный файл
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
|
||||||
|
|
||||||
4
lab3.cbp
4
lab3.cbp
@@ -32,7 +32,11 @@
|
|||||||
<Add option="-Wall" />
|
<Add option="-Wall" />
|
||||||
<Add option="-fexceptions" />
|
<Add option="-fexceptions" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
|
<Unit filename="histogram.cpp" />
|
||||||
|
<Unit filename="histogram.h" />
|
||||||
<Unit filename="main.cpp" />
|
<Unit filename="main.cpp" />
|
||||||
|
<Unit filename="text.cpp" />
|
||||||
|
<Unit filename="text.h" />
|
||||||
<Extensions>
|
<Extensions>
|
||||||
<lib_finder disable_auto="1" />
|
<lib_finder disable_auto="1" />
|
||||||
</Extensions>
|
</Extensions>
|
||||||
|
|||||||
19
lab3.depend
Обычный файл
19
lab3.depend
Обычный файл
@@ -0,0 +1,19 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1686343289 source:c:\users\kostello\desktop\lubs\lab03.2\main.cpp
|
||||||
|
<string>
|
||||||
|
"histogram.h"
|
||||||
|
"text.h"
|
||||||
|
|
||||||
|
1686342281 source:c:\users\kostello\desktop\lubs\lab03.2\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
|
||||||
|
1686342254 c:\users\kostello\desktop\lubs\lab03.2\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1686342636 source:c:\users\kostello\desktop\lubs\lab03.2\text.cpp
|
||||||
|
"text.h"
|
||||||
|
|
||||||
|
1686343275 c:\users\kostello\desktop\lubs\lab03.2\text.h
|
||||||
|
<vector>
|
||||||
|
<iostream>
|
||||||
|
|
||||||
66
main.cpp
66
main.cpp
@@ -1,6 +1,8 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "histogram.h"
|
||||||
|
#include "text.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -34,66 +36,6 @@ for (size_t i = 0; i < in.bin_count; i++) {
|
|||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
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){
|
|
||||||
|
|
||||||
double min, max;
|
|
||||||
find_minmax(numbers, min, max);
|
|
||||||
double bin_size = (max - min) / bin_count;
|
|
||||||
vector<size_t> bins(bin_count);
|
|
||||||
|
|
||||||
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]++;
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
bins[bin_count - 1]++;
|
|
||||||
}}
|
|
||||||
|
|
||||||
return bins;
|
|
||||||
}
|
|
||||||
|
|
||||||
void show_histogram_text(vector <size_t> bins, const double& bin_count)
|
|
||||||
{
|
|
||||||
|
|
||||||
for (size_t i = 0; i < bin_count; i++)
|
|
||||||
{
|
|
||||||
if (bins[i] < 100)
|
|
||||||
{
|
|
||||||
cout<< " ";
|
|
||||||
}
|
|
||||||
if (bins[i] < 10)
|
|
||||||
{
|
|
||||||
cout<< " ";
|
|
||||||
}
|
|
||||||
cout<< bins[i]<<"|";
|
|
||||||
for (size_t j = 0; j < bins[i]; j++)
|
|
||||||
{
|
|
||||||
cout<< "*";
|
|
||||||
}
|
|
||||||
cout<< "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
|||||||
29
text.cpp
Обычный файл
29
text.cpp
Обычный файл
@@ -0,0 +1,29 @@
|
|||||||
|
#include "text.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <math.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void show_histogram_text(vector <size_t> bins, size_t bin_count)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (size_t i = 0; i < bin_count; i++)
|
||||||
|
{
|
||||||
|
if (bins[i] < 100)
|
||||||
|
{
|
||||||
|
cout<< " ";
|
||||||
|
}
|
||||||
|
if (bins[i] < 10)
|
||||||
|
{
|
||||||
|
cout<< " ";
|
||||||
|
}
|
||||||
|
cout<< bins[i]<<"|";
|
||||||
|
for (size_t j = 0; j < bins[i]; j++)
|
||||||
|
{
|
||||||
|
cout<< "*";
|
||||||
|
}
|
||||||
|
cout<< "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
10
text.h
Обычный файл
10
text.h
Обычный файл
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef TEXT_H_INCLUDED
|
||||||
|
#define TEXT_H_INCLUDED
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void show_histogram_text(std::vector <size_t> bins, size_t bin_count);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // TEXT_H_INCLUDED
|
||||||
38
unittest.cbp
Обычный файл
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>
|
||||||
45
unittest.cpp
Обычный файл
45
unittest.cpp
Обычный файл
@@ -0,0 +1,45 @@
|
|||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("distinct positive numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({}, min, max);
|
||||||
|
CHECK(min == 0);
|
||||||
|
CHECK(max == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("distinct positive numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({1}, min, max);
|
||||||
|
CHECK(min == 1);
|
||||||
|
CHECK(max == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("distinct positive numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({-1, 2}, min, max);
|
||||||
|
CHECK(min == -1);
|
||||||
|
CHECK(max == 2);
|
||||||
|
}
|
||||||
|
TEST_CASE("distinct positive numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({2, 2, 2, 2}, min, max);
|
||||||
|
CHECK(min == 2);
|
||||||
|
CHECK(max == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
7
unittest.depend
Обычный файл
7
unittest.depend
Обычный файл
@@ -0,0 +1,7 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1686342281 source:c:\users\kostello\desktop\lubs\lab03.2\histogram.cpp
|
||||||
|
"histogram.h"
|
||||||
|
|
||||||
|
1686342254 c:\users\kostello\desktop\lubs\lab03.2\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
Ссылка в новой задаче
Block a user