Родитель
							
								
									0004fb0018
								
							
						
					
					
						Сommit
						1d79fb1d77
					
				@ -1,2 +1,4 @@
 | 
				
			|||||||
/bin
 | 
					/bin
 | 
				
			||||||
/obj
 | 
					/obj
 | 
				
			||||||
 | 
					/unittest.depend
 | 
				
			||||||
 | 
					/unittest.layout
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,6 @@
 | 
				
			|||||||
 | 
					#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
 | 
				
			||||||
 | 
					#define HISTOGRAM_INTERNAL_H_INCLUDED
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					using namespace std;
 | 
				
			||||||
 | 
					void find_minmax(vector<double> numbers, double &min, double &max);
 | 
				
			||||||
 | 
					#endif // HISTOGRAM_INTERNAL_H_INCLUDED
 | 
				
			||||||
@ -0,0 +1,23 @@
 | 
				
			|||||||
 | 
					# depslib dependency file v1.0
 | 
				
			||||||
 | 
					1685290831 source:c:\users\kasma\desktop\lab03\lab01\main.cpp
 | 
				
			||||||
 | 
						<iostream>
 | 
				
			||||||
 | 
						<vector>
 | 
				
			||||||
 | 
						<conio.h>
 | 
				
			||||||
 | 
						"histogram.h"
 | 
				
			||||||
 | 
						"text.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1685289785 source:c:\users\kasma\desktop\lab03\lab01\text.cpp
 | 
				
			||||||
 | 
						<iostream>
 | 
				
			||||||
 | 
						<vector>
 | 
				
			||||||
 | 
						"text.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1685289785 c:\users\kasma\desktop\lab03\lab01\text.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1685291232 c:\users\kasma\desktop\lab03\lab01\histogram.h
 | 
				
			||||||
 | 
						<vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					1685292419 source:c:\users\kasma\desktop\lab03\lab01\histogram.cpp
 | 
				
			||||||
 | 
						"histogram.h"
 | 
				
			||||||
 | 
						<iostream>
 | 
				
			||||||
 | 
						<vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 | 
				
			||||||
 | 
					<CodeBlocks_layout_file>
 | 
				
			||||||
 | 
						<FileVersion major="1" minor="0" />
 | 
				
			||||||
 | 
						<ActiveTarget name="Debug" />
 | 
				
			||||||
 | 
						<File name="text.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 | 
				
			||||||
 | 
							<Cursor>
 | 
				
			||||||
 | 
								<Cursor1 position="0" topLine="0" />
 | 
				
			||||||
 | 
							</Cursor>
 | 
				
			||||||
 | 
						</File>
 | 
				
			||||||
 | 
						<File name="histogram_internal.h" open="1" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 | 
				
			||||||
 | 
							<Cursor>
 | 
				
			||||||
 | 
								<Cursor1 position="0" topLine="0" />
 | 
				
			||||||
 | 
							</Cursor>
 | 
				
			||||||
 | 
						</File>
 | 
				
			||||||
 | 
						<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 | 
				
			||||||
 | 
							<Cursor>
 | 
				
			||||||
 | 
								<Cursor1 position="582" topLine="2" />
 | 
				
			||||||
 | 
							</Cursor>
 | 
				
			||||||
 | 
						</File>
 | 
				
			||||||
 | 
						<File name="histogram.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 | 
				
			||||||
 | 
							<Cursor>
 | 
				
			||||||
 | 
								<Cursor1 position="60" topLine="0" />
 | 
				
			||||||
 | 
							</Cursor>
 | 
				
			||||||
 | 
						</File>
 | 
				
			||||||
 | 
						<File name="histogram.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 | 
				
			||||||
 | 
							<Cursor>
 | 
				
			||||||
 | 
								<Cursor1 position="278" topLine="0" />
 | 
				
			||||||
 | 
							</Cursor>
 | 
				
			||||||
 | 
						</File>
 | 
				
			||||||
 | 
						<File name="text.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 | 
				
			||||||
 | 
							<Cursor>
 | 
				
			||||||
 | 
								<Cursor1 position="57" topLine="0" />
 | 
				
			||||||
 | 
							</Cursor>
 | 
				
			||||||
 | 
						</File>
 | 
				
			||||||
 | 
					</CodeBlocks_layout_file>
 | 
				
			||||||
@ -0,0 +1,76 @@
 | 
				
			|||||||
 | 
					#include <math.h>
 | 
				
			||||||
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <conio.h>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					#include <string>
 | 
				
			||||||
 | 
					#include "svg.h"
 | 
				
			||||||
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					svg_begin(double width, double height)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
 | 
				
			||||||
 | 
					    cout << "<svg ";
 | 
				
			||||||
 | 
					    cout << "width='" << width << "' ";
 | 
				
			||||||
 | 
					    cout << "height='" << height << "' ";
 | 
				
			||||||
 | 
					    cout << "viewBox='0 0 " << width << " " << height << "' ";
 | 
				
			||||||
 | 
					    cout << "xmlns='http://www.w3.org/2000/svg'>\n";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					svg_end()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    cout << "</svg>\n";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					svg_text(double left, double baseline, string text)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black")
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    cout << "<rect x='"<<x<<"' y='"<<y<<"' width='"<<width<<"' height='"<<height<<"' stroke='"<<stroke<<"' fill='"<<fill<<"' />";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					show_histogram_svg(const vector<size_t>& bins)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    const auto IMAGE_WIDTH = 400;
 | 
				
			||||||
 | 
					    const auto IMAGE_HEIGHT = 300;
 | 
				
			||||||
 | 
					    const auto TEXT_LEFT = 20;
 | 
				
			||||||
 | 
					    const auto TEXT_BASELINE = 20;
 | 
				
			||||||
 | 
					    const auto TEXT_WIDTH = 50;
 | 
				
			||||||
 | 
					    const auto BIN_HEIGHT = 30;
 | 
				
			||||||
 | 
					    const auto BLOCK_WIDTH = 10;
 | 
				
			||||||
 | 
					    const auto BLACK = "black";
 | 
				
			||||||
 | 
					    const auto RED = "red";
 | 
				
			||||||
 | 
					    const auto MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    double top = 0;
 | 
				
			||||||
 | 
					    double max_count = bins[0];
 | 
				
			||||||
 | 
					    for (size_t i = 0; i < bins.size(); i++)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if (max_count<bins[i])
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            max_count=bins[i];
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (size_t bin : bins)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        double bin_width = (MAX_WIDTH)*(bin/max_count);
 | 
				
			||||||
 | 
					        svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
 | 
				
			||||||
 | 
					        svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, BLACK, RED);
 | 
				
			||||||
 | 
					        top += BIN_HEIGHT;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    svg_end();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					#ifndef SVG_H_INCLUDED
 | 
				
			||||||
 | 
					#define SVG_H_INCLUDED
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					show_histogram_svg(const std::vector<size_t>& bins);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif // SVG_H_INCLUDED
 | 
				
			||||||
@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 | 
				
			||||||
 | 
					<CodeBlocks_project_file>
 | 
				
			||||||
 | 
						<FileVersion major="1" minor="6" />
 | 
				
			||||||
 | 
						<Project>
 | 
				
			||||||
 | 
							<Option title="unittest" />
 | 
				
			||||||
 | 
							<Option pch_mode="2" />
 | 
				
			||||||
 | 
							<Option compiler="gcc" />
 | 
				
			||||||
 | 
							<Build>
 | 
				
			||||||
 | 
								<Target title="Debug">
 | 
				
			||||||
 | 
									<Option output="bin/Debug/unittest" 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/unittest" 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" />
 | 
				
			||||||
 | 
							</Compiler>
 | 
				
			||||||
 | 
							<Unit filename="histogram.cpp" />
 | 
				
			||||||
 | 
							<Unit filename="histogram_internal.h" />
 | 
				
			||||||
 | 
							<Unit filename="unittest.cpp" />
 | 
				
			||||||
 | 
							<Extensions>
 | 
				
			||||||
 | 
								<lib_finder disable_auto="1" />
 | 
				
			||||||
 | 
							</Extensions>
 | 
				
			||||||
 | 
						</Project>
 | 
				
			||||||
 | 
					</CodeBlocks_project_file>
 | 
				
			||||||
					Загрузка…
					
					
				
		Ссылка в новой задаче