diff --git a/histogram.cpp b/histogram.cpp index 659cddb..9354d92 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -2,26 +2,26 @@ #include <iostream> #include <limits> -Input input_data() { - Input in; +Input input_data(std::istream& in, bool prompt) { + Input data; size_t number_count; - std::cerr << "Enter number count: "; - std::cin >> number_count; + if (prompt) std::cerr << "Enter number count: "; + in >> number_count; - in.numbers.resize(number_count); - std::cerr << "Enter " << number_count << " numbers: "; + data.numbers.resize(number_count); + if (prompt) std::cerr << "Enter " << number_count << " numbers: "; for (size_t i = 0; i < number_count; i++) { - std::cin >> in.numbers[i]; + in >> data.numbers[i]; } - std::cerr << "Enter bin count: "; - std::cin >> in.bin_count; + if (prompt) std::cerr << "Enter bin count: "; + in >> data.bin_count; - std::cerr << "Enter text width : "; - std::cin >> in.width; + if (prompt) std::cerr << "Enter text width : "; + in >> data.width; - return in; + return data; } void find_minmax(const std::vector<double>& numbers, double& min, double& max) { diff --git a/histogram.h b/histogram.h index 89afcdc..f781d35 100644 --- a/histogram.h +++ b/histogram.h @@ -1,5 +1,5 @@ #pragma once - +#include <iostream> #include <vector> struct Input { @@ -8,6 +8,6 @@ struct Input { int width; }; -Input input_data(); +Input input_data(std::istream& in, bool prompt); std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count); void show_histogram_text(const std::vector<size_t>& bins); diff --git a/lab01.depend b/lab01.depend index 4c05552..3bf3eba 100644 --- a/lab01.depend +++ b/lab01.depend @@ -38,14 +38,15 @@ "histogram.h" "svg.h" -1749169080 c:\mpei\programming\c++ 2sem\lab03\alex\project\histogram.h +1749593919 c:\mpei\programming\c++ 2sem\lab03\alex\project\histogram.h + <iostream> <vector> 1749162416 c:\mpei\programming\c++ 2sem\lab03\alex\project\text.h <iostream> <vector> -1749168172 c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.h +1749584700 c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.h <vector> <iostream> @@ -54,7 +55,7 @@ <iostream> <limits> -1749170885 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.cpp +1749584700 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.cpp "svg.h" "text.h" diff --git a/lab01.layout b/lab01.layout index 377667c..c21bab0 100644 --- a/lab01.layout +++ b/lab01.layout @@ -2,7 +2,7 @@ <CodeBlocks_layout_file> <FileVersion major="1" minor="0" /> <ActiveTarget name="Debug" /> - <File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> + <File name="main.cpp" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <Cursor> <Cursor1 position="214" topLine="0" /> </Cursor> diff --git a/main.cpp b/main.cpp index 3f8468f..7165ab0 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,10 @@ #include "histogram.h" #include "svg.h" +#include <sstream> int main() { - auto in = input_data(); + auto in = input_data(std::cin, true); auto bins = make_histogram(in.numbers, in.bin_count); show_histogram_svg(bins, in.width); return 0; } -//h hjhbhbjbh