code: ввод из произвольного потока

master
lab01(PokhilAA) 12 месяцев назад
Родитель e27d41c5c4
Сommit 7b2e36c398

@ -1,8 +1,8 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "histogram.h" #include "histogram.h"
#include "text.h"
#include "svg.h" #include "svg.h"
using namespace std; using namespace std;
struct Input { struct Input {
@ -11,29 +11,34 @@ struct Input {
}; };
Input Input
input_data() { input_data(istream& _cin){
bool prompt = true;
size_t number_count; size_t number_count;
cout << "Enter number count: "; if (prompt){
cin >> number_count; cerr << "Enter number count:" << endl;
}
_cin >> number_count;
Input in; Input in;
in.numbers.resize(number_count); in.numbers.resize(number_count);
vector<double> numbers(number_count); vector<double> numbers(number_count);
for (size_t i = 0; i < number_count; i++) if (prompt){
{ cerr << "Enter numbers:" << endl;
cin >> in.numbers[i]; }
for (size_t i = 0; i < number_count; i++) {
_cin >> in.numbers[i];
}
if (prompt){
cerr << "Enter bin count:" << endl;
} }
size_t bin_count; _cin >> in.bin_count;
cout << "Enter count bin : ";
cin >> in.bin_count;
return in; return in;
} }
int main(){ int
const size_t SCREEN_WIDTH = 80; main() {
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1; auto in = input_data(cin);
auto in = input_data(); auto bins = make_histogram(in.numbers, in.bin_count);
const std::vector<double> bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins); show_histogram_svg(bins);
return 0; return 0;
} }

Загрузка…
Отмена
Сохранить