code: добавил логическую переменную promt для вывода приглашений
Этот коммит содержится в:
@@ -48,12 +48,4 @@ vector <size_t> make_histogramm(vector<double>numbers, size_t bin_count){
|
||||
}
|
||||
else
|
||||
cerr << "Empty massive of numbers";
|
||||
}
|
||||
bool check_interval(size_t interval){
|
||||
bool need;
|
||||
if (interval > 9 || interval < 2)
|
||||
need = false;
|
||||
else
|
||||
need = true;
|
||||
return need;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,4 @@
|
||||
#include <vector>
|
||||
|
||||
bool find_minmax(std::vector<double> numbers, double &min, double &max);
|
||||
bool check_interval(size_t interval);
|
||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# depslib dependency file v1.0
|
||||
1682340368 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.cpp
|
||||
1684755837 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.cpp
|
||||
<math.h>
|
||||
<iostream>
|
||||
<conio.h>
|
||||
@@ -10,7 +10,7 @@
|
||||
1682341619 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.h
|
||||
<vector>
|
||||
|
||||
1682338657 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\main.cpp
|
||||
1684755828 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\main.cpp
|
||||
<math.h>
|
||||
<iostream>
|
||||
<conio.h>
|
||||
@@ -30,12 +30,12 @@
|
||||
<vector>
|
||||
"text.h"
|
||||
|
||||
1682339360 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram_internal.h
|
||||
1684755787 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram_internal.h
|
||||
<vector>
|
||||
|
||||
1682183926 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\svg.h
|
||||
1684755829 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\svg.h
|
||||
|
||||
1682337971 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\svg.cpp
|
||||
1684755829 source:c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\svg.cpp
|
||||
<math.h>
|
||||
<iostream>
|
||||
<conio.h>
|
||||
|
||||
17
main.cpp
17
main.cpp
@@ -15,16 +15,19 @@ struct Input {
|
||||
};
|
||||
|
||||
Input
|
||||
input_data(istream &tin){
|
||||
input_data(istream &tin, bool prompt){
|
||||
if (prompt)
|
||||
cerr << "Input numbers count: ";
|
||||
size_t number_count;
|
||||
tin >> number_count;
|
||||
Input in;
|
||||
in.numbers.resize(number_count);
|
||||
if (prompt)
|
||||
cerr << "Input numbers: ";
|
||||
for (size_t i = 0; i < number_count; i++) {
|
||||
tin >> in.numbers[i];
|
||||
}
|
||||
if (prompt)
|
||||
cerr << "Input bin count: ";
|
||||
tin >> in.bin_count;
|
||||
return in;
|
||||
@@ -32,16 +35,8 @@ input_data(istream &tin){
|
||||
|
||||
|
||||
int main() {
|
||||
Input in = input_data(cin);
|
||||
Input in = input_data(cin, false);
|
||||
auto bins = make_histogramm(in.numbers, in.bin_count);
|
||||
size_t interval;
|
||||
cerr << "Input interval: "; cin >> interval;
|
||||
bool inRange;
|
||||
inRange = check_interval(interval);
|
||||
if (!inRange){
|
||||
cerr << "ERROR";
|
||||
return 0;
|
||||
}
|
||||
show_histogram_svg(bins, interval);
|
||||
show_histogram_svg(bins);
|
||||
return 0;
|
||||
}
|
||||
|
||||
13
svg.cpp
13
svg.cpp
@@ -31,7 +31,7 @@ void svg_rect(double x, double y, double width, double height, string colour = "
|
||||
}
|
||||
|
||||
void
|
||||
show_histogram_svg(const vector<size_t>& bins, size_t interval) {
|
||||
show_histogram_svg(const vector<size_t>& bins) {
|
||||
const auto IMAGE_WIDTH = 400;
|
||||
const auto IMAGE_HEIGHT = 300;
|
||||
const auto TEXT_LEFT = 20;
|
||||
@@ -52,16 +52,5 @@ show_histogram_svg(const vector<size_t>& bins, size_t interval) {
|
||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "green", "#FF00FF");
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
top+=BIN_HEIGHT;
|
||||
const size_t SPACE = 2;
|
||||
double max_width = (IMAGE_WIDTH - TEXT_WIDTH);
|
||||
const double block = max_width/max_count;
|
||||
for (size_t i = 0; i<max_count; i++){
|
||||
if (i%interval == 0){
|
||||
svg_text(TEXT_WIDTH - SPACE + block*i, top, "|");
|
||||
svg_text(TEXT_WIDTH - SPACE + block*i, top + BIN_HEIGHT, to_string(i));
|
||||
}
|
||||
}
|
||||
svg_rect(TEXT_WIDTH, top, TEXT_WIDTH - SPACE + block*max_count, BIN_HEIGHT/5);
|
||||
svg_end();
|
||||
}
|
||||
|
||||
2
svg.h
2
svg.h
@@ -2,6 +2,6 @@
|
||||
#define SVG_H_INCLUDED
|
||||
|
||||
void
|
||||
show_histogram_svg(const std::vector<size_t>& bins, size_t interval);
|
||||
show_histogram_svg(const std::vector<size_t>& bins);
|
||||
|
||||
#endif // SVG_H_INCLUDED
|
||||
|
||||
Ссылка в новой задаче
Block a user