Родитель
b9e1b344e2
Сommit
c55781c051
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="C:\Users\Lis\source\repos\lab-03\" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="\\bin\Debug\C\Users\Lis\source\repos\lab-03\.exe" 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\C\Users\Lis\source\repos\lab-03\.exe" 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>
|
@ -1,74 +1,56 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include"histogram.h"
|
||||||
|
#include"text.h"
|
||||||
using namespace std;
|
struct Input {
|
||||||
|
std::vector <double> numbers;
|
||||||
int main()
|
size_t number_count;
|
||||||
{
|
std::vector <int> stolb;
|
||||||
|
size_t bucket;
|
||||||
const size_t SCREEN_WIDTH = 80;
|
const size_t SCREEN_WIDTH = 80;
|
||||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
Input
|
||||||
|
input_data() {
|
||||||
|
Input in;
|
||||||
|
in.number_count;
|
||||||
|
in.bucket;
|
||||||
|
|
||||||
int number_count, bucket;
|
std::cout << "Enter number count: "; std::cin >> in.number_count;
|
||||||
|
std::cout << "Enter bucket: "; std::cin >> in.bucket;
|
||||||
cout << "Enter number count: "; cin >> number_count;
|
|
||||||
cout << "Enter bucket: "; cin >> bucket;
|
|
||||||
|
|
||||||
vector <double> numbers(number_count);
|
in.numbers.resize(in.number_count);
|
||||||
for (int i = 0; i < number_count; i++) cin >> numbers[i];
|
|
||||||
|
|
||||||
float min = numbers[0];
|
for (size_t i = 0;i < in.number_count;i++)
|
||||||
float max = numbers[0];
|
|
||||||
|
|
||||||
for (float x : numbers)
|
|
||||||
{
|
{
|
||||||
if (x < min) min = x;
|
std::cin >> in.numbers[i];
|
||||||
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;
|
in.stolb.resize(in.bucket);
|
||||||
|
|
||||||
for (int i = 0; i < number_count; i++)
|
for (int j = 0; j < in.bucket; j++)
|
||||||
{
|
|
||||||
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]++;
|
in.stolb[j] = 0;
|
||||||
flag = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!flag) stolb[bucket-1]++;
|
|
||||||
|
return in;
|
||||||
}
|
}
|
||||||
|
int
|
||||||
|
main()
|
||||||
|
{
|
||||||
|
Input in = input_data();
|
||||||
|
|
||||||
int maxlen = 0;
|
double min=in.numbers[0];
|
||||||
|
double max=in.numbers[0];
|
||||||
|
|
||||||
for (int j = 0; j < bucket; j++)
|
find_minmax(in.numbers, min, max);
|
||||||
{
|
|
||||||
if (maxlen<stolb[j]) maxlen = stolb[j];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int j = 0; j < bucket; j++)
|
make_histogram(in.numbers,in.stolb,in.number_count,in.bucket, max, min);
|
||||||
{
|
|
||||||
if (stolb[j] < 100) cout << " ";
|
show_histogram_text(in.stolb, in.bucket, in.MAX_ASTERISK);
|
||||||
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Загрузка…
Ссылка в новой задаче