Сравнить коммиты
1 Коммитов
main
...
0ff87f78ba
| Автор | SHA1 | Дата | |
|---|---|---|---|
|
|
0ff87f78ba |
6
.gitignore
поставляемый
6
.gitignore
поставляемый
@@ -1,6 +1,4 @@
|
|||||||
bin/
|
bin/
|
||||||
obj/
|
obj/
|
||||||
*.cbp
|
*.o
|
||||||
*.depend
|
*.exe
|
||||||
*.layout
|
|
||||||
*.user
|
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
#include "histogram.h"
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
// Ðåàëèçàöèÿ find_minmax
|
|
||||||
void
|
|
||||||
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
||||||
if (numbers.empty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
min = numbers[0];
|
|
||||||
max = numbers[0];
|
|
||||||
|
|
||||||
for (double x : numbers) {
|
|
||||||
if (x < min) {
|
|
||||||
min = x;
|
|
||||||
}
|
|
||||||
if (x > max) {
|
|
||||||
max = x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ðåàëèçàöèÿ make_histogram
|
|
||||||
vector<size_t>
|
|
||||||
make_histogram(const vector<double>& numbers, size_t bin_count) {
|
|
||||||
double min, max;
|
|
||||||
find_minmax(numbers, min, max);
|
|
||||||
|
|
||||||
vector<size_t> bins(bin_count);
|
|
||||||
double bin_size = (max - min) / bin_count;
|
|
||||||
|
|
||||||
for (double x : numbers) {
|
|
||||||
size_t bin_index = 0;
|
|
||||||
if (x == max) {
|
|
||||||
bin_index = bin_count - 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
bin_index = static_cast<size_t>((x - min) / bin_size);
|
|
||||||
}
|
|
||||||
bins[bin_index]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return bins;
|
|
||||||
}
|
|
||||||
12
histogram.h
12
histogram.h
@@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#ifndef HISTOGRAM_H_INCLUDED
|
|
||||||
#define HISTOGRAM_H_INCLUDED
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
// Îáúÿâëÿåì ÎÁÅ ôóíêöèè: è find_minmax, è make_histogram
|
|
||||||
void find_minmax(const std::vector<double>& numbers, double& min, double& max);
|
|
||||||
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
|
||||||
|
|
||||||
#endif // HISTOGRAM_H_INCLUDED
|
|
||||||
|
|
||||||
1
lab01
Подмодуль
1
lab01
Подмодуль
Submodule lab01 added at ed81237874
44
text.cpp
44
text.cpp
@@ -1,44 +0,0 @@
|
|||||||
#include "text.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
void
|
|
||||||
show_histogram_text(const vector<size_t>& bins) {
|
|
||||||
const size_t SCREEN_WIDTH = 80;
|
|
||||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
||||||
|
|
||||||
size_t max_count = 0;
|
|
||||||
for (size_t count : bins) {
|
|
||||||
if (count > max_count) {
|
|
||||||
max_count = count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t count : bins) {
|
|
||||||
// Âûâîäèì êîëè÷åñòâî ñ âûðàâíèâàíèåì
|
|
||||||
if (count < 10) {
|
|
||||||
cout << " " << count << "|";
|
|
||||||
}
|
|
||||||
else if (count < 100) {
|
|
||||||
cout << " " << count << "|";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cout << count << "|";
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t height = 0;
|
|
||||||
if (max_count <= MAX_ASTERISK) {
|
|
||||||
height = count;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
height = MAX_ASTERISK * (static_cast<double>(count) / max_count);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < height; i++) {
|
|
||||||
cout << "*";
|
|
||||||
}
|
|
||||||
cout << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
9
text.h
9
text.h
@@ -1,9 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#ifndef TEXT_H_INCLUDED
|
|
||||||
#define TEXT_H_INCLUDED
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
void show_histogram_text(const std::vector<size_t>& bins);
|
|
||||||
|
|
||||||
#endif // TEXT_H_INCLUDED
|
|
||||||
Ссылка в новой задаче
Block a user