code: пункт 3.3 исправление ошибок

master
Alexander (AntonovichAN) 7 месяцев назад
Родитель 4809308b5a
Сommit db7e3ea29b

@ -34,8 +34,8 @@ Input input_data() {
int main(){ int main(){
Input in = input_data(); Input in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count); auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins, in.bin_count);
show_histogram_text(bins); return 0;
} }

@ -7,16 +7,16 @@ using namespace std;
const size_t SCREEN_WIDTH = 80; const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 4; const size_t MAX_ASTERISK = SCREEN_WIDTH - 4;
void show_histogram_text(const vector<size_t> &bins){ void show_histogram_text(vector<size_t> &bins, size_t bin_count){
size_t maxbin = bins[0]; size_t maxbin = bins[0];
for (size_t i=1; i < bins.size(); i++){ for (size_t i=1; i < bin_count; i++){
if (maxbin < bins[i]){ if (maxbin < bins[i]){
maxbin = bins[i]; maxbin = bins[i];
} }
} }
if (maxbin <= MAX_ASTERISK){ if (maxbin <= MAX_ASTERISK){
for (size_t i = 0; i < bins.size(); i++) { for (size_t i = 0; i < bin_count; i++) {
cout.width(4); cout.width(4);
cout << bins[i] << "|"; cout << bins[i] << "|";
for (size_t j = 0; j < bins[i]; j++) { for (size_t j = 0; j < bins[i]; j++) {
@ -25,7 +25,7 @@ void show_histogram_text(const vector<size_t> &bins){
cout << endl; cout << endl;
} }
} else { } else {
for (size_t i = 0; i < bins.size(); i++) { for (size_t i = 0; i < bin_count; i++) {
cout.width(4); cout.width(4);
cout << bins[i] << "|"; cout << bins[i] << "|";
size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin)); size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin));

@ -3,7 +3,6 @@
#include <vector> #include <vector>
std::vector<std::size_t> void show_histogram_text(std::vector <std::size_t>& bins, std::size_t bin_count);
show_histogram_text(const std::vector <std::size_t>& bins);
#endif // TEXT_H_INCLUDED #endif // TEXT_H_INCLUDED

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