Родитель
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 <vector>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
#include"histogram.h"
|
||||
#include"text.h"
|
||||
struct Input {
|
||||
std::vector <double> numbers;
|
||||
size_t number_count;
|
||||
std::vector <int> stolb;
|
||||
size_t bucket;
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
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;
|
||||
in.numbers.resize(in.number_count);
|
||||
|
||||
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)
|
||||
for (size_t i = 0;i < in.number_count;i++)
|
||||
{
|
||||
if (x < min) min = x;
|
||||
else if (x > max) max = x;
|
||||
std::cin >> in.numbers[i];
|
||||
}
|
||||
|
||||
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]++;
|
||||
flag = true;
|
||||
|
||||
}
|
||||
}
|
||||
if (!flag) stolb[bucket-1]++;
|
||||
in.stolb[j] = 0;
|
||||
}
|
||||
|
||||
int maxlen = 0;
|
||||
return in;
|
||||
}
|
||||
int
|
||||
main()
|
||||
{
|
||||
Input in = input_data();
|
||||
|
||||
for (int j = 0; j < bucket; j++)
|
||||
{
|
||||
if (maxlen<stolb[j]) maxlen = stolb[j];
|
||||
}
|
||||
double min=in.numbers[0];
|
||||
double max=in.numbers[0];
|
||||
|
||||
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";
|
||||
}
|
||||
find_minmax(in.numbers, min, max);
|
||||
|
||||
make_histogram(in.numbers,in.stolb,in.number_count,in.bucket, max, min);
|
||||
|
||||
show_histogram_text(in.stolb, in.bucket, in.MAX_ASTERISK);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче