code: программа уже с функциями

main
lab-03 (olisovEA) 1 неделю назад
Родитель b9e1b344e2
Сommit c55781c051

40
.cbp

@ -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;
cout << "Enter number count: "; cin >> number_count;
cout << "Enter bucket: "; cin >> bucket;
std::cout << "Enter number count: "; std::cin >> in.number_count;
std::cout << "Enter bucket: "; std::cin >> in.bucket;
vector <double> numbers(number_count);
for (int i = 0; i < number_count; i++) cin >> numbers[i];
in.numbers.resize(in.number_count);
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++)
{
bool flag = false;
for (int j = 0; (j < bucket && !flag); j++)
{
if (numbers[i] >= (min+k*j) && numbers[i] < (min+k*(1+j)))
for (int j = 0; j < in.bucket; j++)
{
stolb[j]++;
flag = true;
}
in.stolb[j] = 0;
}
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++)
{
if (maxlen<stolb[j]) maxlen = stolb[j];
}
find_minmax(in.numbers, min, max);
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";
}
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;
}

Загрузка…
Отмена
Сохранить