Сравнить коммиты

...

11 Коммитов

4
.gitignore поставляемый

@ -2,3 +2,7 @@
/obj /obj
/*.depend /*.depend
/*.layout /*.layout
<<<<<<< HEAD
/unittest
=======
>>>>>>> origin/main

Разница между файлами не показана из-за своего большого размера Загрузить разницу

@ -1,5 +1,22 @@
#include "histogram.h" #include "histogram.h"
<<<<<<< HEAD
bool find_minmax(vector<double> vec, double& min, double& max) {
if (vec.size()== 0){
cerr<<"Empty vec";
return false;
}
min = vec[0];
max = vec[0];
for (double x : vec) {
if (x < min) min = x;
if (x > max) max = x;
}
return true;
=======
void find_minmax(vector<double> vec, double& min, double& max) { void find_minmax(vector<double> vec, double& min, double& max) {
min = vec[0]; min = vec[0];
max = vec[0]; max = vec[0];
@ -12,13 +29,23 @@ void find_minmax(vector<double> vec, double& min, double& max) {
max = x; max = x;
} }
} }
>>>>>>> origin/main
} }
vector<size_t> make_histogram(size_t number, vector<double> vec) { vector<size_t> make_histogram(size_t number, vector<double> vec) {
vector<size_t> bins(number); vector<size_t> bins(number);
<<<<<<< HEAD
if (vec.empty()) return bins;
double mn, mx;
find_minmax(vec, mn, mx);
float bin_size = (mx - mn) / number;
=======
double mn, mx; double mn, mx;
find_minmax(vec, mn, mx); find_minmax(vec, mn, mx);
float bin_size = (mx - mn) / number; float bin_size = (mx - mn) / number;
>>>>>>> origin/main
for (size_t i = 0; i < vec.size(); i++) { for (size_t i = 0; i < vec.size(); i++) {
bool fl = false; bool fl = false;
for (size_t j = 0; (j < number - 1) && !fl; j++) { for (size_t j = 0; (j < number - 1) && !fl; j++) {
@ -31,7 +58,10 @@ vector<size_t> make_histogram(size_t number, vector<double> vec) {
} }
if (!fl) { if (!fl) {
bins[number - 1]++; bins[number - 1]++;
<<<<<<< HEAD
=======
>>>>>>> origin/main
} }
} }
return bins; return bins;

@ -1,7 +1,14 @@
#ifndef HISTOGRAM_H_INCLUDED #ifndef HISTOGRAM_H_INCLUDED
#define HISTOGRAM_H_INCLUDED #define HISTOGRAM_H_INCLUDED
<<<<<<< HEAD
#include <vector>
#include <iostream>
=======
#include <vector> #include <vector>
#include <iostream> #include <iostream>
>>>>>>> origin/main
using namespace std; using namespace std;
vector<size_t> make_histogram(size_t number, vector<double> vec); vector<size_t> make_histogram(size_t number, vector<double> vec);

@ -1,6 +1,11 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED #ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED #define HISTOGRAM_INTERNAL_H_INCLUDED
<<<<<<< HEAD
using namespace std;
bool find_minmax(vector<double> vec, double& min, double& max);
=======
void find_minmax(std::vector<double> vec, double& min, double& max); void find_minmax(std::vector<double> vec, double& min, double& max);
>>>>>>> origin/main
#endif // HISTOGRAM_INTERNAL_H_INCLUDED #endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="laba01" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/laba01" 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/laba01" 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="main.cpp" />
<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,38 +1,64 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
<<<<<<< HEAD
#include "histogram.h"
#include "text.h"
#include "svg.h"
=======
using namespace std; using namespace std;
>>>>>>> origin/main
struct Input { struct Input {
vector<double> numbers; vector<double> numbers;
size_t bin_count{}; size_t bin_count{};
}; };
<<<<<<< HEAD
Input input_data() {
Input in;
size_t number_count;
=======
Input Input
input_data() { input_data() {
size_t number_count, bin_count; size_t number_count, bin_count;
double minl, maxl, bin_size; double minl, maxl, bin_size;
>>>>>>> origin/main
cerr << "Enter the number of elements: "; cerr << "Enter the number of elements: ";
cin >> number_count; cin >> number_count;
<<<<<<< HEAD
in.numbers.resize(number_count);
=======
Input in; Input in;
in.numbers.resize(number_count); in.numbers.resize(number_count);
vector<double> numbers(number_count); vector<double> numbers(number_count);
>>>>>>> origin/main
cerr << "\nEnter " << number_count << " elements:" << endl; cerr << "\nEnter " << number_count << " elements:" << endl;
for (size_t i = 0; i < number_count; i++) { for (size_t i = 0; i < number_count; i++) {
cin >> in.numbers[i]; cin >> in.numbers[i];
} }
<<<<<<< HEAD
=======
>>>>>>> origin/main
cerr << "Enter the number of bins: "; cerr << "Enter the number of bins: ";
cin >> in.bin_count; cin >> in.bin_count;
return in; return in;
} }
<<<<<<< HEAD
int main() {
auto in = input_data();
auto bins = make_histogram(in.bin_count, in.numbers);
show_histogram_svg(bins);
=======
void void
find_minmax(const vector<double>& numbers, double& minl, double& maxl) { find_minmax(const vector<double>& numbers, double& minl, double& maxl) {
minl = numbers[0]; minl = numbers[0];
@ -154,5 +180,6 @@ int main() {
auto bins = make_histogram(in.numbers, in.bin_count); auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins, in.bin_count); show_histogram_text(bins, in.bin_count);
>>>>>>> origin/main
return 0; return 0;
} }

@ -0,0 +1,73 @@
#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 YELLOW = "yellow";
const auto PURPLE = "purple";
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, YELLOW, PURPLE);
top += BIN_HEIGHT;
}
svg_end();
}

11
svg.h

@ -0,0 +1,11 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;
void show_histogram_svg(const vector<size_t>& bins);
#endif // SVG_H_INCLUDED

@ -1,4 +1,51 @@
#include "text.h" #include "text.h"
<<<<<<< HEAD
#include <iostream>
void show_histogram(const std::vector<size_t>& bins) {
bool gigant = false;
auto spaces = 0;
size_t mx_count = 0;
for (auto x : bins) {
if (x > 76) gigant = true;
if (x > mx_count) mx_count = x;
auto len = 0;
auto num = x;
while (num > 0) {
num /= 10;
len++;
}
if (len > spaces) spaces = len;
}
for (size_t i = 0; i < bins.size(); i++) {
int len = 1;
auto num = bins[i];
for (; num /= 10; ++len);
while (len < spaces) {
std::cout << " ";
len++;
}
std::cout << bins[i] << "|";
if (gigant) {
size_t stars = (mx_count > 0) ? (76 * bins[i] / mx_count) : 0;
for (size_t j = 0; j < stars; j++) {
std::cout << "*";
}
} else {
for (size_t j = 0; j < bins[i]; j++) {
std::cout << "*";
}
}
std::cout << std::endl;
=======
void show_histogram(std::vector<size_t> bins) { void show_histogram(std::vector<size_t> bins) {
bool gigant = false; bool gigant = false;
@ -79,5 +126,6 @@ void show_histogram(std::vector<size_t> bins) {
} }
std::cout << std::endl; std::cout << std::endl;
} }
>>>>>>> origin/main
} }
} }

@ -1,8 +1,14 @@
#ifndef TEXT_H_INCLUDED #ifndef TEXT_H_INCLUDED
#define TEXT_H_INCLUDED #define TEXT_H_INCLUDED
<<<<<<< HEAD
#include <vector>
using namespace std;
void show_histogram(const std::vector<size_t>& bins);
=======
#include <iostream> #include <iostream>
#include <vector> #include <vector>
void show_histogram(std::vector<size_t> bins); void show_histogram(std::vector<size_t> bins);
>>>>>>> origin/main
#endif // TEXT_H_INCLUDED #endif // TEXT_H_INCLUDED

@ -0,0 +1,55 @@
#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("distinct negative numbers"){
double min = 0;
double max = 0;
find_minmax({-1, -2}, min, max);
CHECK(min == -2);
CHECK(max == -1);
}
TEST_CASE("vector of the same elements"){
double min = 0;
double max = 0;
find_minmax({3,3,3}, min, max);
CHECK(min == 3);
CHECK(max == 3);
}
TEST_CASE("vector of one elements"){
double min = 0;
double max = 0;
find_minmax({3}, min, max);
CHECK(min == max);
}
TEST_CASE("empty vector") {
double min = 0;
double max = 0;
vector<double>empty;
bool result = find_minmax(empty, min, max);
CHECK(!result);
}
TEST_CASE("vector with all negative numbers") {
double min = 0;
double max = 0;
find_minmax({-5, -10, -2}, min, max);
CHECK(min == -10);
CHECK(max == -2);
}
TEST_CASE("vector with zero") {
double min = 0;
double max = 0;
find_minmax({0, -1, 1}, min, max);
CHECK(min == -1);
CHECK(max == 1);
}

Двоичные данные
unittest/bin/Debug/unittest.exe

Двоичный файл не отображается.

Двоичные данные
unittest/obj/Debug/histogram.o

Двоичный файл не отображается.

Двоичные данные
unittest/obj/Debug/svg.o

Двоичный файл не отображается.

Двоичные данные
unittest/obj/Debug/unittest.o

Двоичный файл не отображается.

@ -31,6 +31,19 @@
<Compiler> <Compiler>
<Add option="-Wall" /> <Add option="-Wall" />
</Compiler> </Compiler>
<<<<<<< HEAD
<Unit filename="../doctest.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="../histogram.cpp" />
<Unit filename="../histogram_internal.h" />
<Unit filename="../svg.cpp" />
<Unit filename="../svg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="../unittest.cpp" />
=======
>>>>>>> origin/main
<Extensions> <Extensions>
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />
</Extensions> </Extensions>

@ -1,4 +1,207 @@
# depslib dependency file v1.0 # depslib dependency file v1.0
<<<<<<< HEAD
1748243702 source:c:\users\home\desktop\lab34\laba01\histogram.cpp
"histogram.h"
1748243652 c:\users\home\desktop\lab34\laba01\histogram.h
<vector>
<iostream>
1748213519 source:c:\users\home\desktop\lab34\laba01\unittest.cpp
"doctest.h"
"histogram_internal.h"
1748211324 c:\users\home\desktop\lab34\laba01\doctest.h
<signal.h>
<ciso646>
<cstddef>
<ostream>
<istream>
<type_traits>
"doctest_fwd.h"
<ctime>
<cmath>
<climits>
<math.h>
<new>
<cstdio>
<cstdlib>
<cstring>
<limits>
<utility>
<fstream>
<sstream>
<iostream>
<algorithm>
<iomanip>
<vector>
<atomic>
<mutex>
<set>
<map>
<unordered_set>
<exception>
<stdexcept>
<csignal>
<cfloat>
<cctype>
<cstdint>
<string>
<sys/types.h>
<unistd.h>
<sys/sysctl.h>
<AfxWin.h>
<windows.h>
<io.h>
<sys/time.h>
<unistd.h>
1748243717 c:\users\home\desktop\lab34\laba01\histogram_internal.h
1748242437 source:c:\users\home\desktop\lab34\laba01\svg.cpp
"svg.h"
1748242437 c:\users\home\desktop\lab34\laba01\svg.h
<iostream>
<vector>
<string>
<math.h>
1748439317 source:c:\users\u111-15\desktop\lab34\laba01\histogram.cpp
"histogram.h"
1748243654 c:\users\u111-15\desktop\lab34\laba01\histogram.h
<vector>
<iostream>
1748437296 source:c:\users\u111-15\desktop\lab34\laba01\svg.cpp
"svg.h"
1748436616 c:\users\u111-15\desktop\lab34\laba01\svg.h
<iostream>
<vector>
<string>
<math.h>
1748439285 source:c:\users\u111-15\desktop\lab34\laba01\unittest.cpp
"doctest.h"
"histogram_internal.h"
1748430259 c:\users\u111-15\desktop\lab34\laba01\doctest.h
<signal.h>
<ciso646>
<cstddef>
<ostream>
<istream>
<type_traits>
"doctest_fwd.h"
<ctime>
<cmath>
<climits>
<math.h>
<new>
<cstdio>
<cstdlib>
<cstring>
<limits>
<utility>
<fstream>
<sstream>
<iostream>
<algorithm>
<iomanip>
<vector>
<atomic>
<mutex>
<set>
<map>
<unordered_set>
<exception>
<stdexcept>
<csignal>
<cfloat>
<cctype>
<cstdint>
<string>
<sys/types.h>
<unistd.h>
<sys/sysctl.h>
<AfxWin.h>
<windows.h>
<io.h>
<sys/time.h>
<unistd.h>
1748439317 c:\users\u111-15\desktop\lab34\laba01\histogram_internal.h
1748850515 source:c:\users\home\desktop\lab3444\laba01\histogram.cpp
"histogram.h"
1748850541 c:\users\home\desktop\lab3444\laba01\histogram.h
<vector>
<iostream>
1748439286 source:c:\users\home\desktop\lab3444\laba01\unittest.cpp
"doctest.h"
"histogram_internal.h"
1748430260 c:\users\home\desktop\lab3444\laba01\doctest.h
<signal.h>
<ciso646>
<cstddef>
<ostream>
<istream>
<type_traits>
"doctest_fwd.h"
<ctime>
<cmath>
<climits>
<math.h>
<new>
<cstdio>
<cstdlib>
<cstring>
<limits>
<utility>
<fstream>
<sstream>
<iostream>
<algorithm>
<iomanip>
<vector>
<atomic>
<mutex>
<set>
<map>
<unordered_set>
<exception>
<stdexcept>
<csignal>
<cfloat>
<cctype>
<cstdint>
<string>
<sys/types.h>
<unistd.h>
<sys/sysctl.h>
<AfxWin.h>
<windows.h>
<io.h>
<sys/time.h>
<unistd.h>
1748439318 c:\users\home\desktop\lab3444\laba01\histogram_internal.h
1748850295 source:c:\users\home\desktop\lab3444\laba01\svg.cpp
"svg.h"
1748850424 c:\users\home\desktop\lab3444\laba01\svg.h
<iostream>
<vector>
<string>
<math.h>
=======
1748415920 source:c:\users\home\desktop\laba34\histogram.cpp 1748415920 source:c:\users\home\desktop\laba34\histogram.cpp
"histogram.h" "histogram.h"
@ -6,3 +209,4 @@
<vector> <vector>
<iostream> <iostream>
>>>>>>> origin/main

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="..\svg.cpp" 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="..\unittest.cpp" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="858" topLine="10" />
</Cursor>
</File>
<File name="..\histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="208" topLine="0" />
</Cursor>
</File>
<File name="..\histogram.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="216" topLine="0" />
</Cursor>
</File>
<File name="..\doctest.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="112412" topLine="2388" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Загрузка…
Отмена
Сохранить