code: создание text.h и text.cpp
Этот коммит содержится в:
@@ -34,6 +34,8 @@
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h" />
|
||||
<Extensions />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
|
||||
58
main.cpp
58
main.cpp
@@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
using namespace std;
|
||||
struct Input
|
||||
{
|
||||
@@ -25,63 +26,6 @@ input_data()
|
||||
}
|
||||
return in;
|
||||
}
|
||||
void
|
||||
show_histogram_text(const vector <size_t> &bins)
|
||||
{
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
int max_count = bins[0];
|
||||
for (size_t i = 0; i < bins.size(); i++)
|
||||
{
|
||||
if (bins[i] > max_count)
|
||||
{
|
||||
max_count = bins[i];
|
||||
}
|
||||
}
|
||||
if (max_count > MAX_ASTERISK)
|
||||
{
|
||||
for (int i = 0; i < bins.size(); i++)
|
||||
{
|
||||
size_t height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
||||
if (bins[i] < 100)
|
||||
{
|
||||
cout << " ";
|
||||
if (bins[i] < 10)
|
||||
{
|
||||
cout << " ";
|
||||
}
|
||||
}
|
||||
cout << bins[i] << "|";
|
||||
for (size_t j = 0; j < height; j++)
|
||||
{
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < bins.size(); i++)
|
||||
{
|
||||
if (bins[i] < 100)
|
||||
{
|
||||
cout << " ";
|
||||
if (bins [i] < 10)
|
||||
{
|
||||
cout << " ";
|
||||
}
|
||||
}
|
||||
cout << bins[i] << "|";
|
||||
for (int j = 0; j < bins[i]; j++)
|
||||
{
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
|
||||
61
text.cpp
Обычный файл
61
text.cpp
Обычный файл
@@ -0,0 +1,61 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "text.h"
|
||||
|
||||
const std::size_t SCREEN_WIDTH = 80;
|
||||
const std::size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
void
|
||||
show_histogram_text(const std::vector <std::size_t> &bins)
|
||||
{
|
||||
std::size_t max_count = bins[0];
|
||||
for (std::size_t i = 0; i < bins.size(); i++)
|
||||
{
|
||||
if (bins[i] > max_count)
|
||||
{
|
||||
max_count = bins[i];
|
||||
}
|
||||
}
|
||||
if (max_count > MAX_ASTERISK)
|
||||
{
|
||||
for (std::size_t i = 0; i < bins.size(); i++)
|
||||
{
|
||||
std::size_t height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
||||
if (bins[i] < 100)
|
||||
{
|
||||
std::cout << " ";
|
||||
if (bins[i] < 10)
|
||||
{
|
||||
std::cout << " ";
|
||||
}
|
||||
}
|
||||
std::cout << bins[i] << "|";
|
||||
for (std::size_t j = 0; j < height; j++)
|
||||
{
|
||||
std::cout << "*";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < bins.size(); i++)
|
||||
{
|
||||
if (bins[i] < 100)
|
||||
{
|
||||
std::cout << " ";
|
||||
if (bins [i] < 10)
|
||||
{
|
||||
std::cout << " ";
|
||||
}
|
||||
}
|
||||
std::cout << bins[i] << "|";
|
||||
for (int j = 0; j < bins[i]; j++)
|
||||
{
|
||||
std::cout << "*";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
text.h
Обычный файл
8
text.h
Обычный файл
@@ -0,0 +1,8 @@
|
||||
#ifndef TEXT_H_INCLUDED
|
||||
#define TEXT_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
void show_histogram_text(const std::vector <std::size_t> &bins);
|
||||
|
||||
#endif // TEXT_H_INCLUDED
|
||||
Ссылка в новой задаче
Block a user