Сравнить коммиты
Ничего общего в коммитах. '298322cd64f635e19165ad4d4993db3f01fb743c' и '041102a83e262c4cbf9285fca0062a157ff3a74b' имеют совершенно разные истории.
298322cd64
...
041102a83e
@ -1,2 +0,0 @@
|
||||
/bin
|
||||
/obj
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -1,65 +0,0 @@
|
||||
#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;
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
#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
|
@ -1,6 +0,0 @@
|
||||
#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,44 +1,92 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
#include <string>
|
||||
#include <conio.h>
|
||||
|
||||
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;
|
||||
|
||||
struct Input {
|
||||
vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
};
|
||||
vector<size_t> bins(bin_count);
|
||||
vector<size_t> binss(bin_count);
|
||||
|
||||
Input
|
||||
input_data() {
|
||||
size_t number_count;
|
||||
cin >> number_count;
|
||||
Input in;
|
||||
in.numbers.resize(number_count);
|
||||
float t = numbers[0];
|
||||
for (size_t i = 0; i < number_count; i++) {
|
||||
if (numbers[i] < t) {
|
||||
t = numbers[i];
|
||||
}
|
||||
}
|
||||
|
||||
float min = t;
|
||||
t = numbers[0];
|
||||
for (size_t i = 0; i < number_count; i++) {
|
||||
cin >> in.numbers[i];
|
||||
if (numbers[i] > t) {
|
||||
t = numbers[i];
|
||||
}
|
||||
}
|
||||
|
||||
float max = t;
|
||||
|
||||
cout << "Enter number of bins";
|
||||
cin >> in.bin_count;
|
||||
return in;
|
||||
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++) {
|
||||
binss[i] = bins[i];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
# 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>
|
||||
|
@ -1,25 +0,0 @@
|
||||
<?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>
|
@ -1,35 +0,0 @@
|
||||
#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();
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
#ifndef SVG_H_INCLUDED
|
||||
#define SVG_H_INCLUDED
|
||||
#include <vector>
|
||||
void
|
||||
show_histogram_svg(const std::vector<size_t>& bins);
|
||||
|
||||
#endif // SVG_H_INCLUDED
|
@ -1,23 +0,0 @@
|
||||
#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";
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
#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
|
@ -1,36 +0,0 @@
|
||||
<?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>
|
@ -1,16 +0,0 @@
|
||||
#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);
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
# 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>
|
||||
|
Загрузка…
Ссылка в новой задаче