Сравнить коммиты
3 Коммитов
a60b3a0445
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 81ff18f02d | |||
| f37d1cd25c | |||
| 332a78f708 |
4
Lab1.cbp
4
Lab1.cbp
@@ -47,6 +47,10 @@
|
|||||||
<Option target="<{~None~}>" />
|
<Option target="<{~None~}>" />
|
||||||
</Unit>
|
</Unit>
|
||||||
<Unit filename="main.cpp" />
|
<Unit filename="main.cpp" />
|
||||||
|
<Unit filename="prot.cpp" />
|
||||||
|
<Unit filename="prot.h" />
|
||||||
|
<Unit filename="svg.cpp" />
|
||||||
|
<Unit filename="svg.h" />
|
||||||
<Unit filename="text.cpp">
|
<Unit filename="text.cpp">
|
||||||
<Option target="Debug" />
|
<Option target="Debug" />
|
||||||
</Unit>
|
</Unit>
|
||||||
|
|||||||
@@ -26,9 +26,13 @@ std::vector<size_t> make_histogram(std::vector<double> numbers, size_t bin_count
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void find_minmax(std::vector<double> numbers, double& min, double& max) {
|
bool find_minmax(std::vector<double> numbers, double& min, double& max) {
|
||||||
|
if(numbers.size()==0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
min = numbers[0];
|
min = numbers[0];
|
||||||
max = numbers[0];
|
max = numbers[0];
|
||||||
|
|
||||||
for (double number : numbers) {
|
for (double number : numbers) {
|
||||||
if (min > number) {
|
if (min > number) {
|
||||||
min = number;
|
min = number;
|
||||||
@@ -37,5 +41,5 @@ void find_minmax(std::vector<double> numbers, double& min, double& max) {
|
|||||||
max = number;
|
max = number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
void find_minmax(std::vector<double> numbers, double& min, double& max);
|
bool find_minmax(std::vector<double> numbers, double& min, double& max);
|
||||||
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);
|
||||||
|
|
||||||
#endif // HISTOGRAM_H_INCLUDED
|
#endif // HISTOGRAM_H_INCLUDED
|
||||||
|
|||||||
12
main.cpp
12
main.cpp
@@ -2,12 +2,13 @@ using namespace std;
|
|||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
|
#include "prot.h"
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
|
|
||||||
struct Input {
|
struct Input {
|
||||||
std::vector<double> numbers;
|
std::vector<double> numbers;
|
||||||
size_t bin_count{};
|
size_t bin_count{};
|
||||||
|
int width;
|
||||||
};
|
};
|
||||||
|
|
||||||
Input input_data();
|
Input input_data();
|
||||||
@@ -17,10 +18,13 @@ int main()
|
|||||||
|
|
||||||
Input in = input_data();
|
Input in = input_data();
|
||||||
std::vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
std::vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
||||||
show_histogram_svg(bins);
|
show_histogram_svg(bins, in.width);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Input input_data() {
|
Input input_data() {
|
||||||
|
|
||||||
Input input_struct;
|
Input input_struct;
|
||||||
size_t countOfNumbers;
|
size_t countOfNumbers;
|
||||||
cerr << "Input your count of numbers:\n";
|
cerr << "Input your count of numbers:\n";
|
||||||
@@ -35,6 +39,10 @@ Input input_data() {
|
|||||||
cerr << endl;
|
cerr << endl;
|
||||||
cerr << "Input bin count:\n";
|
cerr << "Input bin count:\n";
|
||||||
cin >> input_struct.bin_count;
|
cin >> input_struct.bin_count;
|
||||||
|
|
||||||
|
input_struct.width = input_width(countOfNumbers);
|
||||||
|
|
||||||
|
|
||||||
return input_struct;
|
return input_struct;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
25
prot.cpp
Обычный файл
25
prot.cpp
Обычный файл
@@ -0,0 +1,25 @@
|
|||||||
|
#include "prot.h"
|
||||||
|
int input_width(int countOfNumbers){
|
||||||
|
const int BLOCK_WIDTH = 10;
|
||||||
|
bool check = false;
|
||||||
|
int width =0;
|
||||||
|
while(check == false){
|
||||||
|
std::cout << "Input width:"<<std::endl;
|
||||||
|
std::cin >> width;
|
||||||
|
if(width < 70){
|
||||||
|
std::cout << "width less 70" << std::endl;
|
||||||
|
}
|
||||||
|
else if(width > 800){
|
||||||
|
std::cout << "width more 800" << std::endl;
|
||||||
|
}
|
||||||
|
else if(width < countOfNumbers*BLOCK_WIDTH / 3.0){
|
||||||
|
std::cout << "ìåíåå òðåòè êîëè÷åñòâà ÷èñåë, óìíîæåííûõ íà øèðèíó áëîêà " << std::endl;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
check = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return width;
|
||||||
|
|
||||||
|
}
|
||||||
8
prot.h
Обычный файл
8
prot.h
Обычный файл
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef PROT_H_INCLUDED
|
||||||
|
#define PROT_H_INCLUDED
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int input_width(int countOfNumbers);
|
||||||
|
|
||||||
|
#endif // PROT_H_INCLUDED
|
||||||
5
svg.cpp
5
svg.cpp
@@ -13,14 +13,13 @@ void svg_end() {
|
|||||||
std::cout << "</svg>\n";
|
std::cout << "</svg>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void show_histogram_svg(const std::vector<size_t>& bins) {
|
void show_histogram_svg(const std::vector<size_t>& bins, int TEXT_WIDTH) {
|
||||||
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 BIN_HEIGHT = 30;
|
const auto BIN_HEIGHT = 30;
|
||||||
const auto BLOCK_WIDTH = 10;
|
|
||||||
svg_begin(400, 300);
|
svg_begin(400, 300);
|
||||||
|
|
||||||
size_t maxCount = maxBin(bins);
|
size_t maxCount = maxBin(bins);
|
||||||
|
|||||||
2
svg.h
2
svg.h
@@ -5,7 +5,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
void svg_begin(double width, double height);
|
void svg_begin(double width, double height);
|
||||||
void svg_end();
|
void svg_end();
|
||||||
void show_histogram_svg(const std::vector<size_t>& bins);
|
void show_histogram_svg(const std::vector<size_t>& bins, int width);
|
||||||
void svg_text(double left, double baseline, std::string text);
|
void svg_text(double left, double baseline, std::string text);
|
||||||
void svg_rect(double x, double y, double width, double height,std::string stroke, std::string fills);
|
void svg_rect(double x, double y, double width, double height,std::string stroke, std::string fills);
|
||||||
|
|
||||||
|
|||||||
44
unittest.cpp
Обычный файл
44
unittest.cpp
Обычный файл
@@ -0,0 +1,44 @@
|
|||||||
|
#define DOCTEST_CONFIG_NO_MULTITHREADING
|
||||||
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
#include "doctest.h"
|
||||||
|
#include "histogram_internal.h"
|
||||||
|
|
||||||
|
TEST_CASE("distinct positive numbers") {
|
||||||
|
double min = 0;
|
||||||
|
double max = 0;
|
||||||
|
find_minmax({1, 2}, min, max);
|
||||||
|
CHECK(min == 1);
|
||||||
|
CHECK(max == 2);
|
||||||
|
|
||||||
|
}
|
||||||
|
TEST_CASE("empty vector") {
|
||||||
|
std::vector<double> numbers{};
|
||||||
|
double min=0, max=0;
|
||||||
|
CHECK(!find_minmax(numbers, min, max));
|
||||||
|
}
|
||||||
|
TEST_CASE("1 val") {
|
||||||
|
std::vector<double> numbers{1};
|
||||||
|
double min=0, max=0;
|
||||||
|
find_minmax(numbers, min, max);
|
||||||
|
CHECK(min == 1);
|
||||||
|
CHECK(max == 1);
|
||||||
|
}
|
||||||
|
TEST_CASE("- val") {
|
||||||
|
std::vector<double> numbers{-1,-2};
|
||||||
|
double min=0, max=0;
|
||||||
|
find_minmax(numbers, min, max);
|
||||||
|
CHECK(min == -2);
|
||||||
|
CHECK(max == -1);
|
||||||
|
}
|
||||||
|
TEST_CASE("same val") {
|
||||||
|
std::vector<double> numbers{2,2};
|
||||||
|
double min=0, max=0;
|
||||||
|
find_minmax(numbers, min, max);
|
||||||
|
CHECK(min == 2);
|
||||||
|
CHECK(max == 2);
|
||||||
|
}
|
||||||
|
TEST_CASE("check prot1") {
|
||||||
|
check(input_width(int countOfNumbers, 10));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Ссылка в новой задаче
Block a user