Добавлены исходный код и проект

main
ShevchukDS 4 месяцев назад
Сommit 4475c84c98

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="lab01" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/lab01" 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/lab01" 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,100 @@
#include <iostream>
#include <vector>
using namespace std;
int main()
{
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
char a,b,c;
cout << "viravnit = ";
cin >> a;
cout << "osi = ";
cin >> b;
cout << "risunok = ";
cin >> c;
cout << "viravnit = " << a << '\n'
<< "osi = " << b << '\n'
<< "risunok = " << c << '\n';
if (a == '\t' || a == '\n' || b == '\t' || b == '\n' || c == '\t' || c == '\n') {
cout << "ERROR!";
return 0;
}
int number_count, bucket;
do
{
cerr << "Enter number count: "; cin >> number_count;
}
while (number_count < 1);
do
{
cerr << "Enter bucket: "; cin >> bucket;
}
while (bucket < 1);
cerr << "\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;
}
float k = (max-min)/bucket;
vector <int> stolb(bucket);
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 << a;
if (stolb[j] < 10) cout << a;
cout << stolb[j] << b;
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 << c;
cout << "\n";
}
return 0;
}
Загрузка…
Отмена
Сохранить