code: добавлены .h и .cpp (text) файлы и также изменене main.cpp

Этот коммит содержится в:
2025-04-16 17:58:22 +03:00
родитель 0ee2bcf903
Коммит 24e2e418f2
3 изменённых файлов: 51 добавлений и 37 удалений

Просмотреть файл

@@ -1,6 +1,7 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "histogram.h" #include "histogram.h"
#include "text.h"
using namespace std; using namespace std;
struct Input { struct Input {
@@ -27,44 +28,7 @@ input_data(){
void show_histogram_text(vector<size_t> bins, size_t bin_count){
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
size_t max_bin = bins[0];
for(size_t i = 0; i < bin_count; i++)
{
if(bins[i] > max_bin)
{
max_bin = bins[i];
}
}
for (size_t bin: bins)
{
size_t height = bin;
if (max_bin > MAX_ASTERISK)
{
height = MAX_ASTERISK * (static_cast<double>(bin) / max_bin);
}
if (bin < 100)
{
cout << ' ';
}
if (bin < 10)
{
cout << ' ';
}
cout << bin << "|";
for(size_t i = 0; i < height; i++)
{
cout << "*";
}
cout << endl;
}
}
int main() int main()
{ {
auto in = input_data(); auto in = input_data();

44
text.cpp Обычный файл
Просмотреть файл

@@ -0,0 +1,44 @@
#include <iostream>
#include <vector>
#include "text.h"
using namespace std;
void show_histogram_text(vector<size_t> bins, size_t bin_count){
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
size_t max_bin = bins[0];
for(size_t i = 0; i < bin_count; i++)
{
if(bins[i] > max_bin)
{
max_bin = bins[i];
}
}
for (size_t bin: bins)
{
size_t height = bin;
if (max_bin > MAX_ASTERISK)
{
height = MAX_ASTERISK * (static_cast<double>(bin) / max_bin);
}
if (bin < 100)
{
cout << ' ';
}
if (bin < 10)
{
cout << ' ';
}
cout << bin << "|";
for(size_t i = 0; i < height; i++)
{
cout << "*";
}
cout << endl;
}
}

6
text.h Обычный файл
Просмотреть файл

@@ -0,0 +1,6 @@
#ifndef TEXT_H_INCLUDED
#define TEXT_H_INCLUDED
#include <vector>
void show_histogram_text(std::vector<size_t> bins, size_t bin_count);
#endif // TEXT_H_INCLUDED