build: Выполнена пересборка проекта

main
Ишутина Елизавета 2 лет назад
Родитель 4cf6561976
Сommit b4a90ddfa7

@ -1,6 +1,8 @@
#include <iostream>
#include <vector>
#include <cmath>
#include "histogram.h"
#include "text.h"
const size_t WINDOW_WIDTH = 80;
const size_t MAX_VALUE = WINDOW_WIDTH - 3 - 1;
using namespace std;
@ -23,54 +25,6 @@ input_data(){
return in;
}
void
find_minmax(const vector <double> &numbers, double &min, double &max){
min = numbers[0];
max = numbers[0];
for (float now: numbers){
if (now < min) {min = now;}
if (now > max) {max = now;}
}
return;
}
vector <size_t>
make_histogram(vector <double> numbers, size_t bin_count){
vector <size_t> bins(bin_count);
double min = 0, max = 0;
find_minmax(numbers, min, max);
double bin_size = (max - min) / bin_count;
double lo = min, hi = min + bin_size;
for (size_t i = 0; i < bin_count; i++){
for (auto now : numbers){
if (i == bin_count - 1) {
if ((now >= lo) && (now <= hi)) {bins[i]++;}
}
else {
if ((now >= lo) && (now < hi)) {bins[i]++;}
}
}
lo = hi; hi += bin_size;
}
return bins;
}
void show_histogram_text(const vector <size_t> &bins){
size_t max_count = 0;
for (auto now: bins)
{if (now > max_count) {max_count = now;}}
cout << "mc = " << max_count << endl;
for (size_t now : bins){
if (now < 100) {cout << ' ';} if (now < 10) {cout << ' ';}
cout << now << "|";
int height;
if (now == max_count) {height = MAX_VALUE * 1.0;}
else {height = MAX_VALUE * (static_cast <double> (now) / max_count);}
for (int i = 0; i < round(height); i++) {cout << "*";}
cout << endl;
}
}
int
main(){
double min = 0, max = 0;

@ -0,0 +1,40 @@
#include <iostream>
#include <vector>
#include "histogram.h"
#include "histogram_internal.h"
using namespace std;
void
find_minmax(const vector <double> &numbers, double &min, double &max){
if (numbers.size() == 0){min = 0; max = 0;}
else{
min = numbers[0];
max = numbers[0];
for (float now: numbers){
if (now < min) {min = now;}
if (now > max) {max = now;}
}
return;
}
}
vector <size_t>
make_histogram(const vector <double> &numbers, size_t bin_count){
vector <size_t> bins(bin_count);
double min = 0, max = 0;
find_minmax(numbers, min, max);
double bin_size = (max - min) / bin_count;
double lo = min, hi = min + bin_size;
for (size_t i = 0; i < bin_count; i++){
for (auto now : numbers){
if (i == bin_count - 1) {
if ((now >= lo) && (now <= hi)) {bins[i]++;}
}
else {
if ((now >= lo) && (now < hi)) {bins[i]++;}
}
}
lo = hi; hi += bin_size;
}
return bins;
}

@ -0,0 +1,8 @@
#ifndef HISTOGRAM_H_INCLUDED
#define HISTOGRAM_H_INCLUDED
#include <vector>
#include "histogram_internal.h"
using namespace std;
vector <size_t> make_histogram(const vector <double> &numbers, size_t bin_count);
#endif // HISTOGRAM_H_INCLUDED

@ -0,0 +1,8 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
#include <vector>
using namespace std;
void find_minmax(const vector <double> &numbers, double &min, double &max);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -0,0 +1,23 @@
#include <iostream>
#include <vector>
#include <cmath>
#include "text.h"
const size_t WINDOW_WIDTH = 80;
const size_t MAX_VALUE = WINDOW_WIDTH - 3 - 1;
using namespace std;
void
show_histogram_text(const vector <size_t> &bins){
size_t max_count = 0;
for (auto now: bins)
{if (now > max_count) {max_count = now;}}
cout << "mc = " << max_count << endl;
for (size_t now : bins){
if (now < 100) {cout << ' ';} if (now < 10) {cout << ' ';} //ôîðìàòèðîâàíèå ñòðîê
cout << now << "|";
int height;
if (now == max_count) {height = MAX_VALUE * 1.0;}
else {height = MAX_VALUE * (static_cast <double> (now) / max_count);}
for (int i = 0; i < round(height); i++) {cout << "*";}
cout << endl;
}
}

@ -0,0 +1,7 @@
#ifndef TEXT_H_INCLUDED
#define TEXT_H_INCLUDED
#include <vector>
using namespace std;
void show_histogram_text(const vector <size_t> &bins);
#endif // TEXT_H_INCLUDED
Загрузка…
Отмена
Сохранить