From cd935514e39ffc0ca99d97670428a86781b6a93d Mon Sep 17 00:00:00 2001 From: GaidaiAS Date: Wed, 11 Jun 2025 02:06:00 +0300 Subject: [PATCH] rebuild input_data --- histogram.cpp | 24 ++++++++++++------------ histogram.h | 4 ++-- lab01.depend | 7 ++++--- lab01.layout | 2 +- main.cpp | 4 ++-- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/histogram.cpp b/histogram.cpp index 659cddb..9354d92 100644 --- a/histogram.cpp +++ b/histogram.cpp @@ -2,26 +2,26 @@ #include #include -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& 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 #include struct Input { @@ -8,6 +8,6 @@ struct Input { int width; }; -Input input_data(); +Input input_data(std::istream& in, bool prompt); std::vector make_histogram(const std::vector& numbers, size_t bin_count); void show_histogram_text(const std::vector& 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 + 1749162416 c:\mpei\programming\c++ 2sem\lab03\alex\project\text.h -1749168172 c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.h +1749584700 c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.h @@ -54,7 +55,7 @@ -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 @@ - + 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 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