Сравнить коммиты
3 Коммитов
e1879070ee
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| b1812bf7a8 | |||
| a1a63a7b14 | |||
| 7949840782 |
4
.gitignore
поставляемый
Обычный файл
4
.gitignore
поставляемый
Обычный файл
@@ -0,0 +1,4 @@
|
||||
/bin
|
||||
/obj
|
||||
lab01.cpp
|
||||
lab_01.layout
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "histogram.h"
|
||||
using namespace std;
|
||||
void
|
||||
find_minmax(vector<double> numbers, double& min, double& max) {
|
||||
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
||||
min = numbers[0];
|
||||
max = numbers[0];
|
||||
for (double x : numbers) {
|
||||
@@ -20,7 +20,7 @@ vector<size_t> make_histogram(vector<double> numbers, size_t bin_count) {
|
||||
vector <size_t> bins(bin_count);
|
||||
double min, max;
|
||||
find_minmax(numbers, min, max);
|
||||
size_t countt;
|
||||
size_t count;
|
||||
double bin_size = (max - min) / bin_count;
|
||||
for (size_t i = 0; i < numbers.size(); i++) {
|
||||
bool found = false;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
<Unit filename="histogram.h" />
|
||||
<Unit filename="histogram_internal.h" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="marks.txt" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h" />
|
||||
<Unit filename="text.cpp" />
|
||||
|
||||
2
main.cpp
2
main.cpp
@@ -16,7 +16,7 @@ input_data(){
|
||||
cin >> number_count;
|
||||
Input in;
|
||||
in.numbers.resize(number_count);
|
||||
for(int i;i<number_count;i++)
|
||||
for(size_t i=0;i<number_count;i++)
|
||||
{
|
||||
cin >> in.numbers[i];
|
||||
}
|
||||
|
||||
65
svg.cpp
Обычный файл
65
svg.cpp
Обычный файл
@@ -0,0 +1,65 @@
|
||||
#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, string fill) {
|
||||
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 = 10;
|
||||
const auto TEXT_BASELINE = 20;
|
||||
const auto TEXT_WIDTH = 50;
|
||||
const auto BIN_HEIGHT = 30;
|
||||
const auto BLOCK_WIDTH = 10;
|
||||
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 (bins[i] > max_count)
|
||||
max_count = bins[i];
|
||||
}
|
||||
for (size_t bin : bins) {
|
||||
const double bin_width = MAX_WIDTH * (bin/max_count);
|
||||
const double emptiness_width = MAX_WIDTH - bin_width;
|
||||
svg_rect(0, top, emptiness_width, BIN_HEIGHT, "white", "#ffffff");
|
||||
svg_text(TEXT_LEFT + MAX_WIDTH, top + TEXT_BASELINE, to_string(bin));
|
||||
svg_rect(emptiness_width, top, bin_width, BIN_HEIGHT, "red", "#aaffaa");
|
||||
top += BIN_HEIGHT;
|
||||
}
|
||||
|
||||
svg_end();
|
||||
}
|
||||
7
svg.h
Обычный файл
7
svg.h
Обычный файл
@@ -0,0 +1,7 @@
|
||||
#ifndef SVG_H_INCLUDED
|
||||
#define SVG_H_INCLUDED
|
||||
#include <vector>
|
||||
void
|
||||
show_histogram_svg(const std::vector<size_t>& bins);
|
||||
|
||||
#endif // SVG_H_INCLUDED
|
||||
@@ -3,11 +3,12 @@
|
||||
#include "doctest.h"
|
||||
#include "histogram_internal.h"
|
||||
|
||||
|
||||
TEST_CASE("distinct positive numbers") {
|
||||
double min = 0;
|
||||
double max = 0;
|
||||
find_minmax({1, 2}, min, max);
|
||||
std::vector<double>v{2,1};
|
||||
find_minmax(v, min, max);
|
||||
CHECK(min == 1);
|
||||
CHECK(max == 2);
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user