code: заменил поток cin на выборочный поток
Этот коммит содержится в:
@@ -6,8 +6,13 @@
|
|||||||
#include "histogram_internal.h"
|
#include "histogram_internal.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void
|
bool
|
||||||
find_minmax(vector<double> numbers, double &min, double &max) {
|
find_minmax(vector<double> numbers, double &min, double &max) {
|
||||||
|
|
||||||
|
bool notEmpty = true;
|
||||||
|
if (numbers.size() == 0 || numbers.size() == 1)
|
||||||
|
notEmpty = false;
|
||||||
|
else{
|
||||||
min = numbers[0];
|
min = numbers[0];
|
||||||
max = numbers[0];
|
max = numbers[0];
|
||||||
for (size_t i = 1; i < numbers.size(); i++) {
|
for (size_t i = 1; i < numbers.size(); i++) {
|
||||||
@@ -16,11 +21,14 @@ find_minmax(vector<double> numbers, double &min, double &max) {
|
|||||||
if (max < numbers[i])
|
if (max < numbers[i])
|
||||||
max = numbers[i];
|
max = numbers[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return notEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count){
|
vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count){
|
||||||
double min, max;
|
double min, max;
|
||||||
find_minmax(numbers, min, max);
|
bool haveElements = find_minmax(numbers, min, max);
|
||||||
|
if (haveElements){
|
||||||
double binSize = (max - min) / bin_count;
|
double binSize = (max - min) / bin_count;
|
||||||
vector<size_t> bins(bin_count);
|
vector<size_t> bins(bin_count);
|
||||||
for (size_t i = 0; i < numbers.size(); i++) {
|
for (size_t i = 0; i < numbers.size(); i++) {
|
||||||
@@ -36,23 +44,16 @@ vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count){
|
|||||||
if (!found)
|
if (!found)
|
||||||
bins[bin_count - 1]++;
|
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;
|
return bins;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cerr << "Empty massive of numbers";
|
||||||
}
|
}
|
||||||
|
bool check_interval(size_t interval){
|
||||||
void check_interval(size_t &interval){
|
bool need;
|
||||||
if (interval > 9 || interval < 2)
|
if (interval > 9 || interval < 2)
|
||||||
interval = 0;
|
need = false;
|
||||||
return;
|
else
|
||||||
|
need = true;
|
||||||
|
return need;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,5 @@
|
|||||||
|
|
||||||
std::vector<size_t>
|
std::vector<size_t>
|
||||||
make_histogramm(std::vector<double> numbers, size_t bin_count);
|
make_histogramm(std::vector<double> numbers, size_t bin_count);
|
||||||
void check_interval(size_t &interval);
|
|
||||||
|
|
||||||
#endif // HISTOGRAM_H_INCLUDED
|
#endif // HISTOGRAM_H_INCLUDED
|
||||||
|
|||||||
@@ -2,6 +2,6 @@
|
|||||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void find_minmax(std::vector<double> numbers, double &min, double &max);
|
bool find_minmax(std::vector<double> numbers, double &min, double &max);
|
||||||
void check_interval(size_t &interval);
|
bool check_interval(size_t interval);
|
||||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1682183565 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.cpp
|
1682340368 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.cpp
|
||||||
<math.h>
|
<math.h>
|
||||||
<iostream>
|
<iostream>
|
||||||
<conio.h>
|
<conio.h>
|
||||||
@@ -7,10 +7,10 @@
|
|||||||
"histogram.h"
|
"histogram.h"
|
||||||
"histogram_internal.h"
|
"histogram_internal.h"
|
||||||
|
|
||||||
1682184342 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.h
|
1682341619 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.h
|
||||||
<vector>
|
<vector>
|
||||||
|
|
||||||
1682184846 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\main.cpp
|
1682338657 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\main.cpp
|
||||||
<math.h>
|
<math.h>
|
||||||
<iostream>
|
<iostream>
|
||||||
<conio.h>
|
<conio.h>
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
"histogram.h"
|
"histogram.h"
|
||||||
"text.h"
|
"text.h"
|
||||||
"svg.h"
|
"svg.h"
|
||||||
|
"histogram_internal.h"
|
||||||
|
|
||||||
1681931523 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\text.h
|
1681931523 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\text.h
|
||||||
<vector>
|
<vector>
|
||||||
@@ -29,12 +30,12 @@
|
|||||||
<vector>
|
<vector>
|
||||||
"text.h"
|
"text.h"
|
||||||
|
|
||||||
1682183685 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram_internal.h
|
1682339360 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram_internal.h
|
||||||
<vector>
|
<vector>
|
||||||
|
|
||||||
1682183926 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\svg.h
|
1682183926 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\svg.h
|
||||||
|
|
||||||
1682189679 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\svg.cpp
|
1682337971 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\svg.cpp
|
||||||
<math.h>
|
<math.h>
|
||||||
<iostream>
|
<iostream>
|
||||||
<conio.h>
|
<conio.h>
|
||||||
|
|||||||
@@ -2,7 +2,22 @@
|
|||||||
<CodeBlocks_layout_file>
|
<CodeBlocks_layout_file>
|
||||||
<FileVersion major="1" minor="0" />
|
<FileVersion major="1" minor="0" />
|
||||||
<ActiveTarget name="Debug" />
|
<ActiveTarget name="Debug" />
|
||||||
<File name="text.cpp" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="main.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="824" topLine="19" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="histogram.h" open="0" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="207" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="svg.h" open="0" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="123" 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>
|
<Cursor>
|
||||||
<Cursor1 position="211" topLine="0" />
|
<Cursor1 position="211" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
@@ -12,19 +27,14 @@
|
|||||||
<Cursor1 position="73" topLine="0" />
|
<Cursor1 position="73" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<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="123" topLine="0" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="svg.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="svg.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="2180" topLine="43" />
|
<Cursor1 position="1618" topLine="44" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<File name="histogram.cpp" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="histogram.cpp" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="0" topLine="0" />
|
<Cursor1 position="0" topLine="32" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<File name="histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
@@ -32,14 +42,4 @@
|
|||||||
<Cursor1 position="173" topLine="0" />
|
<Cursor1 position="173" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<File name="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="885" topLine="22" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="histogram.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="207" topLine="0" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
</CodeBlocks_layout_file>
|
</CodeBlocks_layout_file>
|
||||||
|
|||||||
16
main.cpp
16
main.cpp
@@ -5,6 +5,7 @@
|
|||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
|
#include "histogram_internal.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
struct Input {
|
struct Input {
|
||||||
@@ -14,29 +15,30 @@ struct Input {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Input
|
Input
|
||||||
input_data(){
|
input_data(istream &tin){
|
||||||
cerr << "Input numbers count: ";
|
cerr << "Input numbers count: ";
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
cin >> number_count;
|
tin >> number_count;
|
||||||
Input in;
|
Input in;
|
||||||
in.numbers.resize(number_count);
|
in.numbers.resize(number_count);
|
||||||
cerr << "Input numbers: ";
|
cerr << "Input numbers: ";
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
cin >> in.numbers[i];
|
tin >> in.numbers[i];
|
||||||
}
|
}
|
||||||
cerr << "Input bin count: ";
|
cerr << "Input bin count: ";
|
||||||
cin >> in.bin_count;
|
tin >> in.bin_count;
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
Input in = input_data();
|
Input in = input_data(cin);
|
||||||
auto bins = make_histogramm(in.numbers, in.bin_count);
|
auto bins = make_histogramm(in.numbers, in.bin_count);
|
||||||
size_t interval;
|
size_t interval;
|
||||||
cerr << "Input interval: "; cin >> interval;
|
cerr << "Input interval: "; cin >> interval;
|
||||||
check_interval(interval);
|
bool inRange;
|
||||||
if (interval == 0){
|
inRange = check_interval(interval);
|
||||||
|
if (!inRange){
|
||||||
cerr << "ERROR";
|
cerr << "ERROR";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
2
svg.cpp
2
svg.cpp
@@ -49,7 +49,7 @@ show_histogram_svg(const vector<size_t>& bins, size_t interval) {
|
|||||||
for (size_t bin : bins) {
|
for (size_t bin : bins) {
|
||||||
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH)*(bin/max_count);
|
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH)*(bin/max_count);
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
||||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#FF00FF");
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "green", "#FF00FF");
|
||||||
top += BIN_HEIGHT;
|
top += BIN_HEIGHT;
|
||||||
}
|
}
|
||||||
top+=BIN_HEIGHT;
|
top+=BIN_HEIGHT;
|
||||||
|
|||||||
47
unittest.cpp
47
unittest.cpp
@@ -4,36 +4,37 @@
|
|||||||
#include "histogram_internal.h"
|
#include "histogram_internal.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
/*TEST_CASE("distinct positive numbers") {
|
TEST_CASE("distinct positive numbers") {
|
||||||
double min = 0;
|
double min = 0;
|
||||||
double max = 0;
|
double max = 0;
|
||||||
std::vector<double>v{1};
|
std::vector<double>v{1, 2};
|
||||||
CHECK(v.size() != 0);
|
bool haveElements = find_minmax(v, min, max);
|
||||||
CHECK(v.size() != 1);
|
CHECK(haveElements);
|
||||||
find_minmax(v, min, max);
|
|
||||||
CHECK(min == 1);
|
CHECK(min == 1);
|
||||||
CHECK(max == 2);
|
CHECK(max == 2);
|
||||||
CHECK(min != max);
|
CHECK(min != max);
|
||||||
}*/
|
}
|
||||||
|
TEST_CASE("EMPTY MASSIVE OR 1 ELEMENT IN MASSIVE"){
|
||||||
TEST_CASE("interval check"){
|
double min = 0;
|
||||||
size_t interval = 3;
|
double max = 0;
|
||||||
check_interval(interval);
|
std::vector<double>v{};
|
||||||
CHECK(interval != 0);
|
bool haveElements = find_minmax(v, min, max);
|
||||||
interval = 10;
|
CHECK(!haveElements);
|
||||||
check_interval(interval);
|
|
||||||
CHECK(interval == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*#define DOCTEST_CONFIG_NO_MULTITHREADING
|
/*TEST_CASE("interval check"){
|
||||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
|
||||||
#include "doctest.h"
|
|
||||||
#include "histogram_internal.h"
|
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
|
||||||
TEST_CASE("interval check"){
|
|
||||||
size_t interval = 3;
|
size_t interval = 3;
|
||||||
bool flag = check_interval(interval);
|
bool inRange;
|
||||||
CHECK(flag == true);
|
inRange = check_interval(interval);
|
||||||
|
CHECK(inRange);
|
||||||
|
inerval = 1
|
||||||
|
inRange = check_interval(interval);
|
||||||
|
CHECK(!inRange);
|
||||||
|
interval = 2
|
||||||
|
inRange = check_interval(interval);
|
||||||
|
CHECK(inRange);
|
||||||
|
interval = 9
|
||||||
|
inRange = check_interval(interval);
|
||||||
|
CHECK(inRange);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# depslib dependency file v1.0
|
# depslib dependency file v1.0
|
||||||
1682183565 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.cpp
|
1682340368 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.cpp
|
||||||
<math.h>
|
<math.h>
|
||||||
<iostream>
|
<iostream>
|
||||||
<conio.h>
|
<conio.h>
|
||||||
@@ -7,10 +7,10 @@
|
|||||||
"histogram.h"
|
"histogram.h"
|
||||||
"histogram_internal.h"
|
"histogram_internal.h"
|
||||||
|
|
||||||
1681931103 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.h
|
1682341619 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram.h
|
||||||
<vector>
|
<vector>
|
||||||
|
|
||||||
1682183685 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram_internal.h
|
1682339360 c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\histogram_internal.h
|
||||||
<vector>
|
<vector>
|
||||||
|
|
||||||
1682182932 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\unittest_15.cpp
|
1682182932 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\unittest_15.cpp
|
||||||
@@ -19,11 +19,7 @@
|
|||||||
<vector>
|
<vector>
|
||||||
<iostream>
|
<iostream>
|
||||||
|
|
||||||
1682183802 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\unittest.cpp
|
1682341526 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\unittest.cpp
|
||||||
"doctest.h"
|
|
||||||
"histogram_internal.h"
|
|
||||||
<vector>
|
|
||||||
<iostream>
|
|
||||||
"doctest.h"
|
"doctest.h"
|
||||||
"histogram_internal.h"
|
"histogram_internal.h"
|
||||||
<vector>
|
<vector>
|
||||||
|
|||||||
@@ -7,19 +7,19 @@
|
|||||||
<Cursor1 position="97" topLine="0" />
|
<Cursor1 position="97" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<File name="doctest.h" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="histogram.cpp" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="168296" topLine="3336" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="unittest.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="485" topLine="6" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="histogram.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="1542" topLine="0" />
|
<Cursor1 position="1542" topLine="0" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
|
<File name="doctest.h" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="168296" topLine="3336" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="unittest.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="650" topLine="3" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
</CodeBlocks_layout_file>
|
</CodeBlocks_layout_file>
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user