Сommit
18907961f0
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<CodeBlocks_project_file>
|
||||
<FileVersion major="1" minor="6" />
|
||||
<Project>
|
||||
<Option title="fin_lab34" />
|
||||
<Option pch_mode="2" />
|
||||
<Option compiler="gcc" />
|
||||
<Build>
|
||||
<Target title="Debug">
|
||||
<Option output="bin/Debug/fin_lab34" 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/fin_lab34" 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,58 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <cmath>
|
||||
|
||||
const size_t WINDOW_WIDTH = 80;
|
||||
const size_t MAX_VALUE = WINDOW_WIDTH - 3 - 1;
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
size_t count, inters;
|
||||
cerr<< "The amount of numbers is: "; cin >> count;
|
||||
cerr << endl << "Numbers are: ";
|
||||
vector <float> numbers (count);
|
||||
for (int i = 0; i < count; i++){cin >> numbers[i];}
|
||||
cerr << endl << "The amounts of intervals: "; cin >> inters;
|
||||
|
||||
float min_number = numbers[0];
|
||||
float max_number = numbers[0];
|
||||
for (float now: numbers){
|
||||
if (now < min_number) {min_number = now;}
|
||||
if (now > max_number) {max_number = now;}
|
||||
}
|
||||
|
||||
float diff = (max_number - min_number) / inters;
|
||||
vector <size_t> bins(inters);
|
||||
float lo = min_number, hi = min_number + diff;
|
||||
|
||||
|
||||
for (int i = 0; i < inters; i++){
|
||||
for (float now : numbers){
|
||||
if (i == inters - 1) {
|
||||
if ((now >= lo) && (now <= hi)) {bins[i]++;}
|
||||
}
|
||||
else {
|
||||
if ((now >= lo) && (now < hi)) {bins[i]++;}
|
||||
}
|
||||
}
|
||||
lo = hi; hi += diff;
|
||||
}
|
||||
float max_count = 0;
|
||||
for (auto now : bins) {max_count += now;}
|
||||
int added = 0;
|
||||
for (size_t now : bins){
|
||||
int height = 0;
|
||||
added += now;
|
||||
if (added < 100) {cout << ' ';} if (added < 10) {cout << ' ';} //ôîðìàòèðîâàíèå ñòðîê
|
||||
|
||||
cout << added << "|";
|
||||
if (added == max_count) {height = MAX_VALUE * 1.0;}
|
||||
else {height = MAX_VALUE * (static_cast <double> (added) / max_count);}
|
||||
for (int i = 0; i < round(height); i++) {cout << "*";}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче