code: Добавлен работа с любым потоком и в функцию input_data добавлен параметр bool prompt
Этот коммит содержится в:
@@ -32,7 +32,13 @@
|
|||||||
<Add option="-Wall" />
|
<Add option="-Wall" />
|
||||||
<Add option="-fexceptions" />
|
<Add option="-fexceptions" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
|
<Unit filename="histogram.cpp" />
|
||||||
|
<Unit filename="histogram.h" />
|
||||||
<Unit filename="main.cpp" />
|
<Unit filename="main.cpp" />
|
||||||
|
<Unit filename="svg.cpp" />
|
||||||
|
<Unit filename="svg.h" />
|
||||||
|
<Unit filename="text.cpp" />
|
||||||
|
<Unit filename="text.h" />
|
||||||
<Extensions>
|
<Extensions>
|
||||||
<lib_finder disable_auto="1" />
|
<lib_finder disable_auto="1" />
|
||||||
</Extensions>
|
</Extensions>
|
||||||
|
|||||||
23
main.cpp
23
main.cpp
@@ -10,25 +10,28 @@ struct Input {
|
|||||||
size_t bin_count{};
|
size_t bin_count{};
|
||||||
};
|
};
|
||||||
|
|
||||||
Input input_data()
|
Input input_data(istream& in, bool prompt)
|
||||||
{
|
{
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
cerr << "Enter number count = ";
|
if (prompt)
|
||||||
cin >> number_count;
|
cerr << "Enter number count = ";
|
||||||
Input in;
|
|
||||||
in.numbers.resize(number_count);
|
in >> number_count;
|
||||||
|
Input inn;
|
||||||
|
inn.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 >> inn.numbers[i];
|
||||||
}
|
}
|
||||||
cerr << "Enter bin_count = ";
|
if (prompt)
|
||||||
cin >> in.bin_count;
|
cerr << "Enter bin_count = ";
|
||||||
return in;
|
in >> inn.bin_count;
|
||||||
|
return inn;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
auto in = input_data();
|
auto in = input_data(cin, true);
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
show_histogram_svg(bins);
|
show_histogram_svg(bins);
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user