code:пункт 4.3 (перенос функции show_histogram_text в файл)

main
BezhenarAN 1 год назад
Родитель a45df45b1b
Сommit 33c59ab153

@ -1,10 +1,9 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "histogram.h" #include "histogram.h"
#include "text.h"
using namespace std; using namespace std;
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
struct Input { struct Input {
vector<double> numbers; vector<double> numbers;
@ -35,60 +34,7 @@ Input input_data() {
} }
void show_histogram_text(const vector<size_t> &bins){
size_t maxbin = bins[0];
for (size_t i=1; i < bins.size(); i++){
if (maxbin < bins[i]){
maxbin = bins[i];
}
}
if (maxbin <=MAX_ASTERISK){
for ( size_t i=0; i < bins.size(); 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 < bins.size(); 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;
}
}
}
}
int main(){ int main(){

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