From 5b682d5310a17dcaa3ea3d5b7e9554b968c7d55b Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Sun, 25 Nov 2018 11:42:25 +0100 Subject: [PATCH] =?UTF-8?q?Dokumentation=20mit=20Doxygen=20hinzugef=C3=BCg?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + CMakeLists.txt | 11 +++ Doxyfile | 42 +++++++++ src/05_OO/a/CMakeLists.txt | 32 ++----- src/07_STD/CMakeLists.txt | 2 +- src/07_STD/MP/BinaryOctet.cpp | 162 +++++++++++++++++++++++++++++++++ src/07_STD/MP/BinaryOctet.h | 21 +++++ src/07_STD/MP/grundgeruest.cpp | 25 +++-- src/07_STD/MP/grundgeruest.hpp | 8 ++ 9 files changed, 268 insertions(+), 36 deletions(-) create mode 100644 Doxyfile create mode 100644 src/07_STD/MP/BinaryOctet.cpp create mode 100644 src/07_STD/MP/BinaryOctet.h diff --git a/.gitignore b/.gitignore index efe4796..632e0be 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ CMakeCache.txt cmake_install.cmake Makefile /C +doc/ diff --git a/CMakeLists.txt b/CMakeLists.txt index b1f0080..160b4e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,17 @@ cmake_minimum_required(VERSION 3.3) project(C/C++) +# add a target to generate API documentation with Doxygen +find_package(Doxygen) +if(DOXYGEN_FOUND) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) + add_custom_target(doc + ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating API documentation with Doxygen" VERBATIM + ) +endif(DOXYGEN_FOUND) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") SET(CMAKE_BUILD_TYPE Debug) diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 0000000..01df912 --- /dev/null +++ b/Doxyfile @@ -0,0 +1,42 @@ +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +PROJECT_NAME = C/C++ +PROJECT_NUMBER = +OUTPUT_DIRECTORY = @CMAKE_CURRENT_SOURCE_DIR@/doc +CREATE_SUBDIRS = NO +OUTPUT_LANGUAGE = German +... +JAVADOC_AUTOBRIEF = YES +... +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +EXTRACT_ALL = NO +... +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/ +FILE_PATTERNS = +RECURSIVE = YES +EXCLUDE = +... +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +... +... + +GENERATE_LATEX = NO +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +SEARCHENGINE = YES + + diff --git a/src/05_OO/a/CMakeLists.txt b/src/05_OO/a/CMakeLists.txt index 8a3ac13..600c750 100644 --- a/src/05_OO/a/CMakeLists.txt +++ b/src/05_OO/a/CMakeLists.txt @@ -1,33 +1,13 @@ +file(GLOB 05_00a_MP_SRC "MP/*.h" "MP/*.cpp") + add_executable(05_OOa_MP - MP/shapes_main.cpp - MP/Shape.cpp - MP/Position.h - MP/Shape.h - MP/Point.cpp - MP/Point.h - MP/Circle.cpp - MP/Circle.h - MP/Rectangle.cpp - MP/Rectangle.h - MP/Scene.cpp - MP/Scene.h + ${05_00a_MP_SRC} ../../helpers/AnsiConsole.cpp ) +file(GLOB 05_00a_Testat_SRC "Testat/*.h" "Testat/*.cpp") + add_executable(05_OOa_Testat - Testat/shapes_main.cpp - Testat/Shape.cpp - Testat/Position.h - Testat/Shape.h - Testat/Point.cpp - Testat/Point.h - Testat/Circle.cpp - Testat/Circle.h - Testat/Rectangle.cpp - Testat/Rectangle.h - Testat/Scene.cpp - Testat/Scene.h - Testat/Sign.cpp - Testat/Sign.h + ${05_00a_Testat_SRC} ../../helpers/AnsiConsole.cpp ) \ No newline at end of file diff --git a/src/07_STD/CMakeLists.txt b/src/07_STD/CMakeLists.txt index 1c1d2b1..bdde11f 100644 --- a/src/07_STD/CMakeLists.txt +++ b/src/07_STD/CMakeLists.txt @@ -1,2 +1,2 @@ -add_executable(07_STD_MP MP/grundgeruest.cpp) +add_executable(07_STD_MP MP/grundgeruest.cpp MP/BinaryOctet.cpp MP/BinaryOctet.h) add_executable(07_STD_Testat Testat/grundgeruest.cpp) \ No newline at end of file diff --git a/src/07_STD/MP/BinaryOctet.cpp b/src/07_STD/MP/BinaryOctet.cpp new file mode 100644 index 0000000..a4e9231 --- /dev/null +++ b/src/07_STD/MP/BinaryOctet.cpp @@ -0,0 +1,162 @@ +#include +#include +#include +#include "BinaryOctet.h" + +BinaryOctet::BinaryOctet(int x) { + for (char &bitsAsDigit : bitsAsDigits) { + bitsAsDigit = '0'; + } + + int remainder; + int temp = 0; + while (x != 0) { + remainder = x % 2; + x /= 2; + bitsAsDigits[temp] = static_cast(remainder + '0'); + temp++; + } + + std::reverse(std::begin(bitsAsDigits), std::end(bitsAsDigits)); + + int ones = 0; + for (char c : bitsAsDigits) { + if (c == '1') ones++; + } + + evenParity = ones % 2 == 0; +} + +const BinaryOctet BinaryOctet::operator--(int) { + return operator-(*new BinaryOctet(1)); +} + +const BinaryOctet BinaryOctet::operator++(int) { + return operator+(*new BinaryOctet(1)); +} + +BinaryOctet BinaryOctet::operator+(BinaryOctet a) { + BinaryOctet result; + bool over = false; + for (int i = bitsPerOctet - 1; i >= 0; --i) { + //Arbeitsvariablen anlegen und char in int umwandeln für einfachere Rechnung + int tmp; + int aI = a.bitsAsDigits[i] - '0'; + int bI = bitsAsDigits[i] - '0'; + + + if(over) tmp = aI + bI + 1; + else tmp = aI + bI; + over = false; + + + if(tmp >= 2) { + over = true; + if (tmp % 2 == 0) tmp = 0; + else tmp = 1; + } + + //Umwandlung in char und ins Ergebnis schreiben + result.bitsAsDigits[i] = static_cast(tmp + '0'); + } + return result; +} + +BinaryOctet BinaryOctet::operator-(BinaryOctet a) { + BinaryOctet result; + bool over = false; + for(int i = bitsPerOctet - 1; i >= 0; --i) { + int tmp; + int aI = a.bitsAsDigits[i] - '0'; + int bI = bitsAsDigits[i] - '0'; + + if(over) tmp = bI - aI - 1; + else tmp = bI - aI; + over = false; + + if(tmp < 0) { + over = true; + tmp = tmp + 1; + } + result.bitsAsDigits[i] = static_cast(tmp + '0'); + } + return result; +} + +BinaryOctet BinaryOctet::operator/(BinaryOctet &a) { + BinaryOctet result = *new BinaryOctet(0); + + while(*this >= a) { + *this = *this - a; + result = result + 1; + } + return result; +} + +bool BinaryOctet::operator!=(BinaryOctet &a) { + if (a.evenParity !=evenParity) return false; + for (int i = 0; i < bitsPerOctet; ++i) { + if (a.bitsAsDigits[i] != bitsAsDigits[i]) return false; + } + return true; +} + +bool BinaryOctet::operator>=(BinaryOctet &a) { + + int power = 8; + int aI = 0; + for(int i = 0; i <= bitsPerOctet - 1; i++) { + power--; + aI = aI + (a.bitsAsDigits[i] - '0') * pow(2, power); + } + + power = 8; + int bI = 0; + for(int i = 0; i <= bitsPerOctet - 1; i++) { + power--; + bI = bI + (bitsAsDigits[i] - '0') * pow(2, power); + } + return bI >= aI; +} + +BinaryOctet doCalculation(BinaryOctet a, BinaryOctet b) { + BinaryOctet result; + for (; a != b; b--) { + a = a + 1; + a = a / b; + } + result = a + b; + return result; +} + +// for println(); +std::string as_string(BinaryOctet a) { + std::string result = "("; + for (char c : a.bitsAsDigits) { + result += c; + } + result += ")"; + return result; +} + + +std::string as_string(BinaryOctet *a) { + std::string result = "("; + for (char c : a->bitsAsDigits) { + result += c; + } + result += ")"; + return result; +} + +// for std::cout +std::ostream &operator<<(std::ostream &os, const BinaryOctet &toBePrinted) { + os << as_string(toBePrinted); + return os; +} + + +std::ostream &operator<<(std::ostream &os, BinaryOctet *toBePrinted) { + os << as_string(toBePrinted); + return os; +} \ No newline at end of file diff --git a/src/07_STD/MP/BinaryOctet.h b/src/07_STD/MP/BinaryOctet.h new file mode 100644 index 0000000..849952d --- /dev/null +++ b/src/07_STD/MP/BinaryOctet.h @@ -0,0 +1,21 @@ +#ifndef C_C_BINARYOCTET_H +#define C_C_BINARYOCTET_H + +const int bitsPerOctet = 8; + +struct BinaryOctet { + bool evenParity; + char bitsAsDigits[bitsPerOctet]{}; + + BinaryOctet(int x = 0); + BinaryOctet(const BinaryOctet&) = default; + const BinaryOctet operator--(int); + const BinaryOctet operator++(int); + bool operator!=(BinaryOctet &a); + bool operator>=(BinaryOctet &a); + BinaryOctet operator-(BinaryOctet a); + BinaryOctet operator+(BinaryOctet a); + BinaryOctet operator/(BinaryOctet &a); +}; + +#endif //C_C_BINARYOCTET_H diff --git a/src/07_STD/MP/grundgeruest.cpp b/src/07_STD/MP/grundgeruest.cpp index 85ee0d3..876094f 100644 --- a/src/07_STD/MP/grundgeruest.cpp +++ b/src/07_STD/MP/grundgeruest.cpp @@ -8,17 +8,9 @@ #include #include #include +#include #include "grundgeruest.hpp" -struct BinaryOctet { - bool evenParity; - char bitsAsDigits[8]; - - BinaryOctet(int i) { - - } -}; - int main() { std::srand(static_cast(std::time(nullptr))); int array[41]; @@ -32,6 +24,21 @@ int main() { } unittest_stringSimilarity(); + + std::vector vector; + for (int i = 0; i <= 41; i++) { + int rnd = distribution(generator); + auto found = std::find(vector.begin(), vector.end(), rnd); + if(found == vector.end()) { + vector.push_back(rnd); + } + std::sort(vector.begin(), vector.end()); + } + for (int ai : vector) { + std::cout << ai << ","; + } + std::cout << std::endl; + } diff --git a/src/07_STD/MP/grundgeruest.hpp b/src/07_STD/MP/grundgeruest.hpp index 26b44a2..9f48fa6 100644 --- a/src/07_STD/MP/grundgeruest.hpp +++ b/src/07_STD/MP/grundgeruest.hpp @@ -1,2 +1,10 @@ +/** + * @param string1 ein String + * @param string2 noch ein String + */ int stringSimilarity(std::string string1, std::string string2); + +/** + * Ein test + */ void unittest_stringSimilarity(); \ No newline at end of file