Родитель
							
								
									1c9dd6081f
								
							
						
					
					
						Сommit
						ba019ecd59
					
				@ -0,0 +1,38 @@
 | 
				
			||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 | 
				
			||||
<CodeBlocks_project_file>
 | 
				
			||||
	<FileVersion major="1" minor="6" />
 | 
				
			||||
	<Project>
 | 
				
			||||
		<Option title="cs-lab34" />
 | 
				
			||||
		<Option pch_mode="2" />
 | 
				
			||||
		<Option compiler="gcc" />
 | 
				
			||||
		<Build>
 | 
				
			||||
			<Target title="Debug">
 | 
				
			||||
				<Option output="bin/Debug/cs-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/cs-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 />
 | 
				
			||||
	</Project>
 | 
				
			||||
</CodeBlocks_project_file>
 | 
				
			||||
@ -0,0 +1,10 @@
 | 
				
			||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 | 
				
			||||
<CodeBlocks_layout_file>
 | 
				
			||||
	<FileVersion major="1" minor="0" />
 | 
				
			||||
	<ActiveTarget name="Debug" />
 | 
				
			||||
	<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 | 
				
			||||
		<Cursor>
 | 
				
			||||
			<Cursor1 position="757" topLine="16" />
 | 
				
			||||
		</Cursor>
 | 
				
			||||
	</File>
 | 
				
			||||
</CodeBlocks_layout_file>
 | 
				
			||||
@ -0,0 +1,34 @@
 | 
				
			||||
#include "histogram.h"
 | 
				
			||||
#include <vector>
 | 
				
			||||
 | 
				
			||||
using namespace std;
 | 
				
			||||
 | 
				
			||||
void find_minmax(const vector<double>& numbers, double& min, double& max) {
 | 
				
			||||
    min = numbers[0];
 | 
				
			||||
    max = numbers[0];
 | 
				
			||||
    for (float x : numbers) {
 | 
				
			||||
        if (x < min) min = x;
 | 
				
			||||
        else if (x > max) max = x;
 | 
				
			||||
    }
 | 
				
			||||
}
 | 
				
			||||
 | 
				
			||||
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
 | 
				
			||||
    double min, max;
 | 
				
			||||
    find_minmax(numbers, min, max);
 | 
				
			||||
 | 
				
			||||
    float k = (max - min) / bin_count;
 | 
				
			||||
    vector<size_t> bins(bin_count, 0);
 | 
				
			||||
 | 
				
			||||
    for (double number : numbers) {
 | 
				
			||||
        bool flag = false;
 | 
				
			||||
        for (size_t j = 0; (j < bin_count && !flag); j++) {
 | 
				
			||||
            if (number >= (min + k * j) && number < (min + k * (j + 1))) {
 | 
				
			||||
                bins[j]++;
 | 
				
			||||
                flag = true;
 | 
				
			||||
            }
 | 
				
			||||
        }
 | 
				
			||||
        if (!flag) bins[bin_count - 1]++;
 | 
				
			||||
    }
 | 
				
			||||
 | 
				
			||||
    return bins;
 | 
				
			||||
}
 | 
				
			||||
@ -0,0 +1,4 @@
 | 
				
			||||
#pragma once
 | 
				
			||||
#include <vector>
 | 
				
			||||
 | 
				
			||||
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count);
 | 
				
			||||
@ -0,0 +1,33 @@
 | 
				
			||||
#include "text.h"
 | 
				
			||||
#include <iostream>
 | 
				
			||||
 | 
				
			||||
using namespace std;
 | 
				
			||||
 | 
				
			||||
void show_histogram_text(const vector<size_t>& bins) {
 | 
				
			||||
    const size_t SCREEN_WIDTH = 80;
 | 
				
			||||
    const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
 | 
				
			||||
 | 
				
			||||
    size_t max_count = 0;
 | 
				
			||||
    for (size_t count : bins) {
 | 
				
			||||
        if (count > max_count) {
 | 
				
			||||
            max_count = count;
 | 
				
			||||
        }
 | 
				
			||||
    }
 | 
				
			||||
 | 
				
			||||
    for (size_t bin : bins) {
 | 
				
			||||
        if (bin < 100) cout << " ";
 | 
				
			||||
        if (bin < 10) cout << " ";
 | 
				
			||||
        cout << bin << "|";
 | 
				
			||||
 | 
				
			||||
        size_t height = bin;
 | 
				
			||||
        if (max_count > MAX_ASTERISK) {
 | 
				
			||||
            if (max_count != bin)
 | 
				
			||||
                height = MAX_ASTERISK * (static_cast<float>(bin) / max_count);
 | 
				
			||||
            else
 | 
				
			||||
                height = MAX_ASTERISK;
 | 
				
			||||
        }
 | 
				
			||||
 | 
				
			||||
        for (size_t i = 0; i < height; i++) cout << "*";
 | 
				
			||||
        cout << "\n";
 | 
				
			||||
    }
 | 
				
			||||
}
 | 
				
			||||
@ -0,0 +1,4 @@
 | 
				
			||||
#pragma once
 | 
				
			||||
#include <vector>
 | 
				
			||||
 | 
				
			||||
void show_histogram_text(const std::vector<size_t>& bins);
 | 
				
			||||
					Загрузка…
					
					
				
		Ссылка в новой задаче