Вы не можете выбрать более 25 тем
Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
63 строки
1.8 KiB
C++
63 строки
1.8 KiB
C++
//main.cpp -- the program gets number count, numbers and bin size, then builds a histogram.
|
|
//Task 15 -- make a scale under the histogram.
|
|
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include <curl/curl.h>
|
|
#include "histogram.h"
|
|
#include "text.h"
|
|
#include "svg.h"
|
|
|
|
using namespace std;
|
|
|
|
struct Input { //data input
|
|
vector<double> numbers;
|
|
size_t bin_count{};
|
|
size_t interval_task{};
|
|
};
|
|
|
|
|
|
Input
|
|
input_data(istream& in, bool prompt) { //input data structure
|
|
|
|
if (prompt == false) { //prompt output
|
|
cerr.rdbuf(NULL);
|
|
}
|
|
|
|
size_t number_count;
|
|
cerr << "Enter number count: \n";
|
|
cerr.flush();
|
|
in >> number_count;
|
|
|
|
Input in_data_struct;
|
|
|
|
in_data_struct.numbers.resize(number_count);
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
cerr << "Enter number "<< i << " : \n";
|
|
in >> in_data_struct.numbers[i];
|
|
}
|
|
|
|
cerr << "Enter bin count: \n";
|
|
in >> in_data_struct.bin_count;
|
|
|
|
cerr << "Enter interval from task: \n";
|
|
in >> in_data_struct.interval_task;
|
|
|
|
if ((in_data_struct.interval_task >= 2.0) && (in_data_struct.interval_task <= 9.0)) { //scale interval size check
|
|
return in_data_struct;
|
|
} else {
|
|
std::cout << "ERROR"; //error situation and program exit
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
|
|
int main() {
|
|
//curl_global_init(CURL_GLOBAL_ALL);
|
|
auto in = input_data(cin, true); //input data
|
|
auto bins = make_histogram(in.numbers, in.bin_count); //calculating bin size for the histogram
|
|
show_histogram_svg(bins, in.interval_task); //histogram output in the format svg code
|
|
|
|
return 0;
|
|
}
|