code: My last variant 3 laba
Этот коммит содержится в:
49
Laba N 1.cbp
Обычный файл
49
Laba N 1.cbp
Обычный файл
@@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="Laba N 1" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/Laba N 1" 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/Laba N 1" 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="histogram.cpp" />
|
||||||
|
<Unit filename="histogram.h" />
|
||||||
|
<Unit filename="ignor.gitignore" />
|
||||||
|
<Unit filename="main.cpp" />
|
||||||
|
<Unit filename="procent.cpp" />
|
||||||
|
<Unit filename="procent.h" />
|
||||||
|
<Unit filename="svg.cpp" />
|
||||||
|
<Unit filename="svg.h" />
|
||||||
|
<Unit filename="text.cpp" />
|
||||||
|
<Unit filename="text.h" />
|
||||||
|
<Extensions>
|
||||||
|
<lib_finder disable_auto="1" />
|
||||||
|
</Extensions>
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
|
#include <vector>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void
|
bool
|
||||||
find_minmax(const std::vector<double>& numbers, double& Min, double& Max) {
|
find_minmax(const std::vector<double>& numbers, double& Min, double& Max) {
|
||||||
|
bool flag=true;
|
||||||
|
if(numbers.size()==0 ){
|
||||||
|
flag=false;}else
|
||||||
|
{
|
||||||
Min = numbers[0];
|
Min = numbers[0];
|
||||||
Max = numbers[0];
|
Max = numbers[0];
|
||||||
for(size_t x : numbers)
|
|
||||||
|
for(double x : numbers)
|
||||||
{
|
{
|
||||||
if(x < Min)
|
if(x < Min)
|
||||||
{
|
{
|
||||||
@@ -19,6 +24,8 @@ find_minmax(const std::vector<double>& numbers, double& Min, double& Max) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<size_t> make_histogram(std::vector<double> numbers, size_t bin_count)
|
std::vector<size_t> make_histogram(std::vector<double> numbers, size_t bin_count)
|
||||||
|
|||||||
@@ -1,23 +1,11 @@
|
|||||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
|
||||||
void
|
#include <vector>
|
||||||
find_minmax(const std::vector<double>& numbers, double& Min, double& Max) {
|
#include <iostream>
|
||||||
Min = numbers[0];
|
using namespace std;
|
||||||
Max = numbers[0];
|
|
||||||
for(size_t x : numbers)
|
bool
|
||||||
{
|
find_minmax(const std::vector<double>& numbers, double& Min, double& Max);
|
||||||
if(x < Min)
|
|
||||||
{
|
|
||||||
Min = x;
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
if(x > Max)
|
|
||||||
{
|
|
||||||
Max = x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
||||||
|
|||||||
5
main.cpp
5
main.cpp
@@ -3,6 +3,7 @@
|
|||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
|
#include "procent.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
struct Input {
|
struct Input {
|
||||||
std::vector<double> numbers;
|
std::vector<double> numbers;
|
||||||
@@ -25,6 +26,7 @@ input_data() {
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
auto in = input_data();
|
auto in = input_data();
|
||||||
|
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
auto max_count=bins[0];
|
auto max_count=bins[0];
|
||||||
for(size_t x : bins){
|
for(size_t x : bins){
|
||||||
@@ -33,7 +35,8 @@ int main()
|
|||||||
max_count=x;
|
max_count=x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
vector<size_t> procent = make_histogram_proc(in.numbers, in.bin_count, bins);
|
||||||
show_histogram_text(bins,in.bin_count,in.numbers,max_count);
|
show_histogram_text(bins,in.bin_count,in.numbers,max_count);
|
||||||
//show_histogram_svg(bins, max_count);
|
//show_histogram_svg(bins, max_count,procent);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
51
svg.cpp
51
svg.cpp
@@ -1,6 +1,7 @@
|
|||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <math.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -17,8 +18,14 @@ void
|
|||||||
svg_text(double left, double baseline, std::string text) {
|
svg_text(double left, double baseline, std::string text) {
|
||||||
std::cout << "<text x='"<< left <<"' y='"<< baseline <<"'>"<< text <<"</text>";
|
std::cout << "<text x='"<< left <<"' y='"<< baseline <<"'>"<< text <<"</text>";
|
||||||
}
|
}
|
||||||
void svg_rect(double x, double y, double width, double height,std::string stroke = "black", std::string fil = "black"){
|
|
||||||
std::cout<< "<rect x='"<< x <<"' y='"<< y <<"' width='"<< width <<"' height='"<< height <<"' />";
|
void
|
||||||
|
svg_proc(double left, double baseline,size_t procent) {
|
||||||
|
std::cout << "<text x='"<< left <<"' y='"<< baseline <<"'>"<< procent <<"%</text>";
|
||||||
|
}
|
||||||
|
|
||||||
|
void svg_rect(double x, double y, double width, double height,std::string stroke = "black", std::string fill = "green"){
|
||||||
|
std::cout<< "<rect x='"<< x <<"' y='"<< y <<"' width='"<< width <<"' height='"<< height <<"' stroke = '" << stroke <<"' fill = '" << fill <<"' />";
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
svg_end() {
|
svg_end() {
|
||||||
@@ -26,23 +33,51 @@ svg_end() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
show_histogram_svg(std::vector<size_t> bins,size_t max_count) {
|
show_histogram_svg(std::vector<size_t> bins,size_t max_count, const std::vector<size_t> procent) {
|
||||||
const auto IMAGE_WIDTH = 400;
|
const auto IMAGE_WIDTH = 400;
|
||||||
const auto IMAGE_HEIGHT = 300;
|
const auto IMAGE_HEIGHT = 300;
|
||||||
const auto TEXT_LEFT = 20;
|
const auto TEXT_LEFT = 20;
|
||||||
const auto TEXT_BASELINE = 20;
|
const auto TEXT_BASELINE = 20;
|
||||||
const auto TEXT_WIDTH = 50;
|
const auto TEXT_WIDTH = 50;
|
||||||
const auto BIN_HEIGHT = 30;
|
const auto BIN_HEIGHT = 30;
|
||||||
const auto BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH)/max_count;
|
const auto SCALE = 10;
|
||||||
|
const auto BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH);
|
||||||
|
|
||||||
|
|
||||||
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||||
|
|
||||||
double top = 0;
|
double top = 0;
|
||||||
for (size_t bin : bins) {
|
|
||||||
const double bin_width = BLOCK_WIDTH * bin;
|
if((SCALE*max_count)>BLOCK_WIDTH)
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));
|
{
|
||||||
|
for (size_t i = 0; i < bins.size(); i++) {
|
||||||
|
const double bin_width = BLOCK_WIDTH * (bins[i]/max_count);
|
||||||
|
const auto TEXT_LEFT_PROCENT = SCALE+TEXT_WIDTH+20;
|
||||||
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
||||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
||||||
|
svg_proc(TEXT_LEFT_PROCENT, top + TEXT_BASELINE,procent[i]);
|
||||||
|
|
||||||
|
top += BIN_HEIGHT;
|
||||||
|
}}
|
||||||
|
else{
|
||||||
|
for (size_t i = 0; i < bins.size(); i++) {
|
||||||
|
const double bin_width = bins[i] * SCALE;
|
||||||
|
const auto TEXT_LEFT_PROCENT = (max_count*SCALE)+TEXT_WIDTH+20;
|
||||||
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
||||||
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
||||||
|
svg_proc(TEXT_LEFT_PROCENT, top + TEXT_BASELINE,procent[i]);
|
||||||
|
|
||||||
top += BIN_HEIGHT;
|
top += BIN_HEIGHT;
|
||||||
}
|
}
|
||||||
svg_end();
|
svg_end();
|
||||||
}
|
}
|
||||||
|
/*for (size_t i = 0; i < bins.size(); i++) {
|
||||||
|
const double bin_width = BLOCK_WIDTH * bins[i];
|
||||||
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
||||||
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
||||||
|
svg_proc(BLOCK_WIDTH*bins[i]+TEXT_LEFT+50, top + TEXT_BASELINE,procent[i]);
|
||||||
|
|
||||||
|
top += BIN_HEIGHT;
|
||||||
|
}
|
||||||
|
svg_end();
|
||||||
|
}*/}
|
||||||
|
|||||||
2
svg.h
2
svg.h
@@ -5,6 +5,6 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void
|
void
|
||||||
show_histogram_svg(std::vector<size_t> bins,size_t max_count);
|
show_histogram_svg(std::vector<size_t> bins,size_t max_count, const std::vector<size_t> procent);
|
||||||
|
|
||||||
#endif // SVG_H_INCLUDED
|
#endif // SVG_H_INCLUDED
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user