code: добавлен ввод из произвольного потока
Этот коммит содержится в:
14
main.cpp
14
main.cpp
@@ -14,31 +14,31 @@ struct Input {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Input
|
Input
|
||||||
input_data() {
|
input_data(istream& in_stream) {
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
Input in;
|
Input in;
|
||||||
|
|
||||||
cerr << "Enter number count: ";
|
cerr << "Enter number count: ";
|
||||||
cin >> number_count;
|
in_stream >> number_count;
|
||||||
vector<double> numbers(number_count);
|
vector<double> numbers(number_count);
|
||||||
|
|
||||||
in.numbers.resize(number_count);
|
in.numbers.resize(number_count);
|
||||||
|
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
cin >> in.numbers[i];
|
in_stream >> in.numbers[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
cerr << "Enter bins count and colors: ";
|
cerr << "Enter bins count and colors: ";
|
||||||
cin >> in.bin_count;
|
in_stream >> in.bin_count;
|
||||||
vector<string> colors(in.bin_count);
|
vector<string> colors(in.bin_count);
|
||||||
in.colors.resize(in.bin_count);
|
in.colors.resize(in.bin_count);
|
||||||
|
|
||||||
for (size_t i = 0; i < in.bin_count; i++) {
|
for (size_t i = 0; i < in.bin_count; i++) {
|
||||||
cin >> in.colors[i];
|
in_stream >> in.colors[i];
|
||||||
bool check = check_color(in.colors[i]);
|
bool check = check_color(in.colors[i]);
|
||||||
while (!check) {
|
while (!check) {
|
||||||
cerr << "Incorrect input. Color doesn't contain # or has spaces." << endl;
|
cerr << "Incorrect input. Color doesn't contain # or has spaces." << endl;
|
||||||
cin >> in.colors[i];
|
in_stream >> in.colors[i];
|
||||||
check = check_color(in.colors[i]);
|
check = check_color(in.colors[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ input_data() {
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Input in = input_data();
|
auto in = input_data(cin);
|
||||||
vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
||||||
//show_histogram_text(bins, in.bin_count);
|
//show_histogram_text(bins, in.bin_count);
|
||||||
show_histogram_svg(bins, in.colors);
|
show_histogram_svg(bins, in.colors);
|
||||||
|
|||||||
1
svg.cpp
1
svg.cpp
@@ -7,6 +7,7 @@ using namespace std;
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
check_color(string color) {
|
check_color(string color) {
|
||||||
|
|
||||||
if (color[0]=='#'||color.find(' ')==(-1))
|
if (color[0]=='#'||color.find(' ')==(-1))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
|
|||||||
3
svg.h
3
svg.h
@@ -7,4 +7,7 @@
|
|||||||
void
|
void
|
||||||
show_histogram_svg(const std::vector<size_t>& bins, const std::vector<std::string>& colors);
|
show_histogram_svg(const std::vector<size_t>& bins, const std::vector<std::string>& colors);
|
||||||
|
|
||||||
|
bool
|
||||||
|
check_color(std::string color);
|
||||||
|
|
||||||
#endif // SVG_H_INCLUDED
|
#endif // SVG_H_INCLUDED
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user