master
MachulinaDV 2 лет назад
Сommit 489edd1815

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

@ -0,0 +1,2 @@
/bin
/obj

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

@ -0,0 +1,57 @@
#include <iostream>
#include <vector>
#include <math.h>
#include "histogram.h"
using namespace std;
static void find_minmax(const vector<double>& A, double& min, double& max)
{
min = A[0];
for (auto i = 0; i < A.size(); i++)
{
if (A[i] < min)
{
min = A[i];
}
}
max = A[0];
for (auto i = 0; i < A.size(); i++)
{
if (A[i] > max)
{
max = A[i];
}
}
return;
}
vector <size_t> make_histogram(const vector<double>& A, size_t bin)
{
vector<size_t>B(bin);
size_t max_count;
double max, min;
find_minmax(A, min, max);
double step = (max - min) / (bin);
for (size_t i = 0; i < A.size(); i++)
{
for (size_t j = 0; j < bin; j++)
{
if ((A[i] >= (min + j * step)) && (A[i] < (min + (j + 1)*step)))
{
B[j]++;
break;
}
}
}
for (size_t i = 0; i < A.size(); i++)
{
if (A[i] == max)
B[bin - 1]++;
}
return B;
}

@ -0,0 +1,9 @@
#ifndef HISTOGRAM_H_INCLUDED
#define HISTOGRAM_H_INCLUDED
#include <vector>
std::vector<size_t>
make_histogram(const std::vector<double>& A, size_t bin);
#endif // HISTOGRAM_H_INCLUDED

Двоичные данные
histogram.h.gch

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

@ -0,0 +1,10 @@
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
#define HISTOGRAM_INTERNAL_H_INCLUDED
#include <vector>
using namespace std;
using namespace std;
void find_minmax(const vector<double>& A, double& min, double& max);
#endif // HISTOGRAM_INTERNAL_H_INCLUDED

@ -0,0 +1,42 @@
#include <iostream>
#include <vector>
#include <math.h>
#include "histogram.h"
#include "text.h"
#include "svg.h"
using namespace std;
struct Input {
vector<double>A;
size_t bin{};
};
Input
input_data()
{
size_t n;
cerr<<"Marks: ";
cin>>n;
Input in;
in.A.resize(n);
for (size_t i=0; i<n; i++)
{
cerr<<"A["<<i<<"]=";
cin>>in.A[i];
}
cerr<<"Rows: ";
cin>>in.bin;
return in;
}
int main()
{
Input in = input_data();
auto B = make_histogram(in.A, in.bin);
show_histogram_svg (B);
return 0;
}

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="mainprog" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/mainprog" 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/mainprog" 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=".gitignore" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="histogram_internal.h" />
<Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Unit filename="text.cpp" />
<Unit filename="text.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Extensions />
</Project>
</CodeBlocks_project_file>

@ -0,0 +1,81 @@
# depslib dependency file v1.0
1682181974 source:c:\users\user\desktop\main\mainprog\main.cpp
<iostream>
<vector>
<math.h>
"histogram.h"
"text.h"
"svg.h"
1682104083 c:\users\user\desktop\main\mainprog\histogram.h
<vector>
1682102022 c:\users\user\desktop\main\mainprog\text.h
<vector>
1682182215 source:c:\users\user\desktop\main\mainprog\histogram.cpp
<iostream>
<vector>
<math.h>
"histogram.h"
1682181846 source:c:\users\user\desktop\main\mainprog\svg.cpp
<math.h>
<iostream>
<conio.h>
<vector>
<string>
"svg.h"
1682181891 c:\users\user\desktop\main\mainprog\svg.h
<vector>
1682104083 source:c:\users\user\desktop\main\mainprog\histogram.h
<vector>
1682102022 source:c:\users\user\desktop\main\mainprog\text.h
<vector>
1682182215 source:c:\users\user\desktop\main\mainprog\text.cpp
<iostream>
<vector>
<math.h>
"text.h"
1682182215 source:c:\users\Ïîäâîéñêàÿ\desktop\lab_34\histogram.cpp
<iostream>
<vector>
<math.h>
"histogram.h"
1682104083 c:\users\Ïîäâîéñêàÿ\desktop\lab_34\histogram.h
<vector>
1682185693 source:c:\users\Ïîäâîéñêàÿ\desktop\lab_34\main.cpp
<iostream>
<vector>
<math.h>
"histogram.h"
"text.h"
"svg.h"
1682102022 c:\users\Ïîäâîéñêàÿ\desktop\lab_34\text.h
<vector>
1682181891 c:\users\Ïîäâîéñêàÿ\desktop\lab_34\svg.h
<vector>
1682185797 source:c:\users\Ïîäâîéñêàÿ\desktop\lab_34\svg.cpp
<math.h>
<iostream>
<conio.h>
<vector>
<string>
"svg.h"
1682182215 source:c:\users\Ïîäâîéñêàÿ\desktop\lab_34\text.cpp
<iostream>
<vector>
<math.h>
"text.h"

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="histogram.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="119" topLine="3" />
</Cursor>
</File>
<File name=".gitignore" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="7" topLine="0" />
</Cursor>
</File>
<File name="svg.cpp" open="1" top="1" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="478" topLine="8" />
</Cursor>
</File>
<File name="text.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="51" topLine="0" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="580" topLine="13" />
</Cursor>
</File>
<File name="text.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="104" topLine="0" />
</Cursor>
</File>
<File name="histogram.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -0,0 +1,63 @@
#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>& B) {
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 MAX_WIDTH = IMAGE_WIDTH-TEXT_WIDTH;
svg_begin(IMAGE_WIDTH,IMAGE_HEIGHT);
double top = 0;
double max_count = B[0];
for (size_t i = 0; i < B.size(); i++) {
if (B[i] > max_count)
max_count = B[i];
}
for (size_t bin : B) {
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH)*(bin/max_count);
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "red", "#aaffaa");
top += BIN_HEIGHT;
}
svg_end();
}

@ -0,0 +1,8 @@
#ifndef SVG_H_INCLUDED
#define SVG_H_INCLUDED
#include <vector>
void
show_histogram_svg(const std::vector<size_t>& B);
#endif // SVG_H_INCLUDED

@ -0,0 +1,29 @@
#include <iostream>
#include <vector>
#include <math.h>
#include "text.h"
using namespace std;
void show_histogram(vector<size_t>B, size_t bin)
{
for (size_t i = 0; i < bin; i++)
{
if (B[i] < 10)
{
cout << " ";
}
else if (B[i] < 100)
{
cout << " ";
}
cout << B[i] << "|";
for (size_t j = 0; j < B[i]; j++)
{
cout << "*";
}
cout << endl;
}
return;
}

@ -0,0 +1,6 @@
#pragma once
#include <vector>
void show_histogram(std::vector<size_t>B, size_t bin);

Двоичные данные
text.h.gch

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

@ -0,0 +1,40 @@
<?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="doctest.h" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram_internal.h" />
<Unit filename="unittest.cpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>

@ -0,0 +1,16 @@
#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;
std::vector<double>A{1,2,3,4};
CHECK(A.size() !=0 );
CHECK(A.size() !=1 );
find_minmax(A, min, max);
CHECK(min == 1);
CHECK(max == 4);
CHECK(min!=max);
}

@ -0,0 +1,62 @@
# depslib dependency file v1.0
1682111062 source:c:\users\user\desktop\main\mainprog\histogram.cpp
<iostream>
<vector>
<math.h>
"histogram.h"
1682104083 c:\users\user\desktop\main\mainprog\histogram.h
<vector>
1682179349 source:c:\users\user\desktop\main\mainprog\unittest.cpp
"doctest.h"
"histogram_internal.h"
1682111212 c:\users\user\desktop\main\mainprog\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>
1682111057 c:\users\user\desktop\main\mainprog\histogram_internal.h
<vector>

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="unittest.cpp" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="260" topLine="0" />
</Cursor>
</File>
<File name="doctest.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="61423" topLine="1387" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Загрузка…
Отмена
Сохранить