Yaroslav Spesivtsev 18 часов назад
Сommit 9f972c809b

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Histogram" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/Histogram" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/Histogram" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

Двоичные данные
Histogram/bin/Debug/Histogram.exe

Двоичный файл не отображается.

@ -0,0 +1,86 @@
#include <iostream>
#include <vector>
using namespace std;
int main()
{
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
int number_count, bucket;
cerr << "Enter number count: "; cin >> number_count;
std::cerr << "Enter numbers: \n";
vector <double> numbers(number_count);
for (int i = 0; i < number_count; i++) cin >> numbers[i];
float min = numbers[0];
float max = numbers[0];
for (float x : numbers)
{
if (x < min) min = x;
else if (x > max) max = x;
}
if (max == min) {// ïðîâåðêà íà àíîìàëèþ
std::cout << " Unable to create a histogram." << std::endl;
return 1;
}
cerr << "Enter bucket: "; cin >> bucket;
float k = (max - min) / bucket;
if (numbers.empty()) {//áûëè ëè ââåäåíû ÷èñëà
std::cout << "Empty. unable to create histogram." << std::endl;
return 1;
}
vector <int> stolb(bucket);
vector <int> proz(stolb);
for (int j = 0; j < bucket; j++) stolb[j] = 0;
for (int i = 0; i < number_count; i++)
{
bool flag = false;
for (int j = 0; (j < bucket && !flag); j++)
{
if (numbers[i] >= (min + k * j) && numbers[i] < (min + k * (1 + j)))
{
stolb[j]++;
flag = true;
}
}
if (!flag) stolb[bucket - 1]++;
}
int maxlen = 0;
for (int j = 0; j < bucket; j++)
{
if (maxlen < stolb[j]) maxlen = stolb[j];
}
for (int j = 0; j < bucket; j++)
{
if (stolb[j] < 100) cout << " ";
if (stolb[j] < 10) cout << "";
cout << stolb[j] << " |";
size_t height = stolb[j];
if (maxlen > MAX_ASTERISK)
{
if (maxlen != stolb[j]) height = MAX_ASTERISK * (static_cast <float>(stolb[j]) / maxlen);
else if (maxlen == stolb[j]) height = MAX_ASTERISK;
}
for (int i = 0; i < height; i++) cout << "*";
cout << "\n";
}
return 0;
}

Двоичные данные
Histogram/obj/Debug/main.o

Двоичный файл не отображается.
Загрузка…
Отмена
Сохранить