Сравнить коммиты
5 Коммитов
041102a83e
...
298322cd64
Автор | SHA1 | Дата |
---|---|---|
|
298322cd64 | 2 лет назад |
|
9a4b65ee9a | 2 лет назад |
|
d5c6b1a53b | 2 лет назад |
|
20bb417d84 | 2 лет назад |
|
acb9bcd7f4 | 2 лет назад |
@ -0,0 +1,2 @@
|
|||||||
|
/bin
|
||||||
|
/obj
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -0,0 +1,65 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
#include "histogram.h"
|
||||||
|
#include "histogram_internal.h"
|
||||||
|
#include <conio.h>
|
||||||
|
using namespace std;
|
||||||
|
void find_minmax(const vector<double> numbers, double& min, double& max) {
|
||||||
|
min = numbers[0];
|
||||||
|
for (auto i = 0; i < numbers.size(); i++) {
|
||||||
|
if (numbers[i] < min) {
|
||||||
|
min = numbers[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
max = numbers[0];
|
||||||
|
for (auto i = 0; i < numbers.size(); i++) {
|
||||||
|
if (numbers[i] > max) {
|
||||||
|
max = numbers[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
||||||
|
|
||||||
|
vector<size_t> bins(bin_count);
|
||||||
|
vector<size_t> binss(bin_count);
|
||||||
|
|
||||||
|
double max, min;
|
||||||
|
find_minmax(numbers, min, max);
|
||||||
|
double bin_size = (max / min) / 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]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int max_count = bins[0];
|
||||||
|
for (size_t i = 0; i < bin_count; i++) {
|
||||||
|
if (bins[i] > max_count) {
|
||||||
|
max_count = bins[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max_count > 76) {
|
||||||
|
|
||||||
|
for (size_t i = 0; i < bin_count; i++) {
|
||||||
|
int count = bins[i];
|
||||||
|
size_t height = 76 * (static_cast<double>(count) / max_count);
|
||||||
|
bins[i] = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bins;
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
#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
|
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
#include <vector>
|
||||||
|
void find_minmax(std::vector<double> numbers, double& min, double& max);
|
||||||
|
|
||||||
|
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
@ -1,92 +1,44 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include "histogram.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "svg.h"
|
||||||
|
#include <string>
|
||||||
|
#include <conio.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
int main()
|
|
||||||
{
|
|
||||||
size_t number_count;
|
|
||||||
size_t bin_count;
|
|
||||||
cerr << "Enter number count:";
|
|
||||||
cin >> number_count;
|
|
||||||
|
|
||||||
vector<double> numbers(number_count);
|
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
|
||||||
cin >> numbers[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
cerr << "Enter number of bins:";
|
|
||||||
cin >> bin_count;
|
|
||||||
|
|
||||||
vector<size_t> bins(bin_count);
|
struct Input {
|
||||||
vector<size_t> binss(bin_count);
|
vector<double> numbers;
|
||||||
|
size_t bin_count{};
|
||||||
|
};
|
||||||
|
|
||||||
float t = numbers[0];
|
Input
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
input_data() {
|
||||||
if (numbers[i] < t) {
|
size_t number_count;
|
||||||
t = numbers[i];
|
cin >> number_count;
|
||||||
}
|
Input in;
|
||||||
}
|
in.numbers.resize(number_count);
|
||||||
|
|
||||||
float min = t;
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
t = numbers[0];
|
cin >> in.numbers[i];
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
}
|
||||||
if (numbers[i] > t) {
|
|
||||||
t = numbers[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float max = t;
|
|
||||||
|
|
||||||
double bin_size = (max / min) / bin_count;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < number_count; 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]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < bin_count; i++) {
|
cout << "Enter number of bins";
|
||||||
binss[i] = bins[i];
|
cin >> in.bin_count;
|
||||||
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
int max_count = bins[0];
|
|
||||||
for (size_t i = 0; i < bin_count; i++) {
|
|
||||||
if (bins[i] > max_count) {
|
|
||||||
max_count = bins[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (max_count > 76) {
|
|
||||||
|
|
||||||
for (size_t i = 0; i < bin_count; i++) {
|
|
||||||
int count = bins[i];
|
|
||||||
size_t height = 76 * (static_cast<double>(count) / max_count);
|
|
||||||
bins[i] = height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < bin_count; i++) {
|
|
||||||
if (binss[i] < 100) {
|
|
||||||
cout << " ";
|
|
||||||
}
|
|
||||||
if (binss[i] < 10) {
|
|
||||||
cout << " ";
|
|
||||||
}
|
|
||||||
cout << bins[i] << "|";
|
|
||||||
for (size_t j = 0; j < binss[i]; j++) {
|
|
||||||
cout << "*";
|
|
||||||
}
|
|
||||||
cout << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
int main()
|
||||||
|
{
|
||||||
|
Input in = input_data();
|
||||||
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
|
show_histogram_svg(bins);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1682281180 source:c:\users\hp\desktop\lab-03\project3\main.cpp
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
<cmath>
|
||||||
|
"histogram.h"
|
||||||
|
"text.h"
|
||||||
|
"svg.h"
|
||||||
|
<string>
|
||||||
|
<conio.h>
|
||||||
|
|
||||||
|
1682271918 c:\users\hp\desktop\lab-03\project3\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1682280773 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
<cmath>
|
||||||
|
"histogram.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
<conio.h>
|
||||||
|
|
||||||
|
1682280773 source:c:\users\hp\desktop\lab-03\project3\text.cpp
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
<cmath>
|
||||||
|
"text.h"
|
||||||
|
<conio.h>
|
||||||
|
|
||||||
|
1682273446 c:\users\hp\desktop\lab-03\project3\text.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1682275464 c:\users\hp\desktop\lab-03\project3\histogram_internal.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1682280773 source:c:\users\hp\desktop\lab-03\project3\svg.cpp
|
||||||
|
<math.h>
|
||||||
|
<iostream>
|
||||||
|
<conio.h>
|
||||||
|
<vector>
|
||||||
|
<string>
|
||||||
|
"svg.h"
|
||||||
|
<conio.h>
|
||||||
|
|
||||||
|
1682278136 c:\users\hp\desktop\lab-03\project3\svg.h
|
||||||
|
<vector>
|
||||||
|
|
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_layout_file>
|
||||||
|
<FileVersion major="1" minor="0" />
|
||||||
|
<ActiveTarget name="Debug" />
|
||||||
|
<File name="histogram.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="175" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="99" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="text.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="77" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="histogram.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="160" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
</CodeBlocks_layout_file>
|
@ -0,0 +1,35 @@
|
|||||||
|
#include <math.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <conio.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include "svg.h"
|
||||||
|
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
|
||||||
|
show_histogram_svg(const vector<size_t>& bins) {
|
||||||
|
svg_begin(400, 300);
|
||||||
|
svg_text(20, 20, to_string(bins[0]));
|
||||||
|
svg_end();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef SVG_H_INCLUDED
|
||||||
|
#define SVG_H_INCLUDED
|
||||||
|
#include <vector>
|
||||||
|
void
|
||||||
|
show_histogram_svg(const std::vector<size_t>& bins);
|
||||||
|
|
||||||
|
#endif // SVG_H_INCLUDED
|
@ -0,0 +1,23 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
#include "text.h"
|
||||||
|
#include <conio.h>
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef TEXT_H_INCLUDED
|
||||||
|
#define TEXT_H_INCLUDED
|
||||||
|
#include <vector>
|
||||||
|
void show_histogram_text(std::vector <size_t> bins, size_t bin_count );
|
||||||
|
|
||||||
|
#endif // TEXT_H_INCLUDED
|
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="unitest" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/unitest" 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/unitest" 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 />
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
@ -0,0 +1,16 @@
|
|||||||
|
#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;
|
||||||
|
std::vector<double>mas{1,2};
|
||||||
|
CHECK(mas.size() != 0);
|
||||||
|
CHECK(mas.size() != 1);
|
||||||
|
find_minmax(mas, min, max);
|
||||||
|
CHECK(min == 1);
|
||||||
|
CHECK(max == 2);
|
||||||
|
CHECK(min != max);
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
# depslib dependency file v1.0
|
||||||
|
1682275493 source:c:\users\hp\desktop\lab-03\project3\histogram.cpp
|
||||||
|
<iostream>
|
||||||
|
<vector>
|
||||||
|
<cmath>
|
||||||
|
"histogram.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
|
||||||
|
1682271918 c:\users\hp\desktop\lab-03\project3\histogram.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1682275464 c:\users\hp\desktop\lab-03\project3\histogram_internal.h
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1682275379 source:c:\users\hp\desktop\lab-03\project3\unitest.cpp
|
||||||
|
"doctest.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
<vector>
|
||||||
|
|
||||||
|
1682274805 c:\users\hp\desktop\lab-03\project3\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>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче