code: реализовано разбиение функций на файлы
Этот коммит содержится в:
94
main.cpp
94
main.cpp
@@ -1,9 +1,9 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
using namespace std;
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
|
||||
struct Input {
|
||||
vector<double> numbers;
|
||||
@@ -33,95 +33,15 @@ Input input_data() {
|
||||
return in;
|
||||
}
|
||||
|
||||
void find_minmax(const vector<double> &numbers, double &min, double &max){
|
||||
min = numbers[0];
|
||||
max = numbers[0];
|
||||
for ( double x : numbers ){
|
||||
if ( x < min ){
|
||||
min = x;
|
||||
} else if ( x > max ){
|
||||
max = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
Input in = input_data();
|
||||
|
||||
vector<size_t> bins ( in.bin_count );
|
||||
double min = in.numbers[0];
|
||||
double max = in.numbers[0];
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
|
||||
find_minmax(in.numbers, min, max);
|
||||
show_histogram_text(bins);
|
||||
|
||||
|
||||
double bin_size = ( max - min ) / in.bin_count;
|
||||
for (size_t i=0; i < in.numbers.size(); i++ ){
|
||||
bool found = false;
|
||||
for (size_t j = 0; ( j < in.bin_count - 1 ) && !found; j++ ){
|
||||
auto lo = min + j * bin_size;
|
||||
auto hi = min + ( j + 1 ) * bin_size;
|
||||
if (lo <= in.numbers[i] && ( in.numbers[i] < hi )){
|
||||
bins[j]++;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if ( !found ){
|
||||
bins[in.bin_count-1]++;
|
||||
}
|
||||
}
|
||||
//
|
||||
size_t maxbin = bins[0];
|
||||
for (size_t i=1; i < in.bin_count; i++){
|
||||
if (maxbin < bins[i]){
|
||||
maxbin = bins[i];
|
||||
}
|
||||
}
|
||||
if (maxbin <=MAX_ASTERISK){
|
||||
for ( size_t i=0; i < in.bin_count; i++ ){
|
||||
if ((bins[i] < 1000)&&(bins[i] > 99)){
|
||||
cout << bins[i] << "|";
|
||||
for ( size_t j=0; j < bins[i]; j++ ){
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
} else if ((bins[i] < 100)&&(bins[i]>9)) {
|
||||
cout << " " << bins[i] << "|";
|
||||
for ( size_t j=0; j < bins[i]; j++ ){
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
} else if ( bins[i] < 10 ){
|
||||
cout << " " << bins[i]<< "|";
|
||||
for ( size_t j=0; j < bins[i]; j++ ){
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (size_t i=0; i < in.bin_count; i++){
|
||||
size_t heightG= MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin);
|
||||
if ((bins[i] < 1000)&&(bins[i] > 99)){
|
||||
cout << bins[i] << "|";
|
||||
for ( size_t j=0; j < heightG; j++ ){
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
} else if ((bins[i] < 100)&&(bins[i]>9)) {
|
||||
cout << " " << bins[i] << "|";
|
||||
for ( size_t j=0; j < heightG; j++ ){
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
} else if ( bins[i] < 10 ){
|
||||
cout << " " << bins[i]<< "|";
|
||||
for ( size_t j=0; j < heightG; j++ ){
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user