code: добавлена стартовая версия программы

main
YusufovYB 2 лет назад
Сommit ff949949a1

6
.gitignore поставляемый

@ -0,0 +1,6 @@
/bin
/obj
/chtoto.depend
/chtoto.layout
/main.o
/main.exe

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="chtoto" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/chtoto" 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/chtoto" 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>

@ -0,0 +1,123 @@
#include <iostream>
#include <vector>
using namespace std;
int main() {
size_t number_count;
size_t height;
int maximum, minimum, max_count = 0, he_previous = -1, he_next = 0, he2_previous = -1, he2_next = 0 ;
float LL, LR;
cerr << "Enter number count = ";
cin >> number_count;
vector<double> numbers(number_count);
for (int i = 0; i < number_count; i++) {
cerr << "Vvedite element massiva = ";
cin >> numbers[i];
}
cerr << "Vvedite bin_count = ";
float bin_count;
cin >> bin_count;
maximum = numbers[number_count - 1];
minimum = numbers[number_count - 2];
vector <size_t> bins(bin_count);
for (int i = 0; i < number_count; i++) {
if (numbers[i] < minimum)
minimum = numbers[i];
if (numbers[i] > maximum)
maximum = numbers[i];
}
double bin_size = (maximum - minimum) / bin_count;
LL = minimum;
LR = minimum + bin_size;
for (int i = 0; i < bin_count; i++) {
if (i == 0) {
for (int b = 0; b < number_count; b++) {
if ((LL <= numbers[b]) && (numbers[b] < LR))
bins[i] += 1;
}
LL = LR;
LR = LL + bin_size;
}
if (i == (bin_count - 1)) {
LR = maximum;
for (int b = 0; b < number_count; b++) {
if ((LL < numbers[b]) && (numbers[b] <= LR))
bins[i] += 1;
}
break;
}
if ((i != 0) && (i != (bin_count - 1))) {
for (int b = 0; b < number_count; b++) {
if ((LL < numbers[b]) && (numbers[b] < LR))
bins[i] += 1;
}
LL = LR;
LR = LL + bin_size;
}
}
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
max_count = 0;
for (int i = 0; i < bin_count; i++) {
if (bins[i] > max_count)
max_count = bins[i];
}
for (int i = 0; i < bin_count; i++) {
if ((i + 1) < bin_count)
he_next = bins[i + 1];
else
he_next = -1;
if (bins[i] < 10) {
cout << " ";
}
if (bins[i] < 100) {
cout << " ";
}
cout << bins[i] << "|";
if (max_count > 76) {
height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
if ((i+1) < bin_count)
he2_next = MAX_ASTERISK * (static_cast<double>(bins[i + 1]) / max_count);
else
he2_next = -1;
for (int b = 0; b < height; b++) {
if (b == he2_previous)
cout << "^";
if (b == he2_next)
cout << "˅";
if ((b != (he2_previous - 1)) && (b != (he2_next - 1)))
cout << "*";
}
he2_previous = height;
}
else {
for (int b = 0; b < bins[i]; b++) {
if (b == (he_previous-1))
cout << "^";
if (b == (he_next - 1))
cout << "v";
if ((b != (he_previous - 1)) && (b != (he_next - 1)))
cout << "*";
}
}
cout << endl;
he_previous = bins[i];
}
return 0;
}
Загрузка…
Отмена
Сохранить