init
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
---
|
||||
Language: Cpp
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
ColumnLimit: 120
|
||||
TabWidth: 4
|
||||
IndentWidth: 2
|
||||
...
|
||||
@@ -0,0 +1,25 @@
|
||||
# debug: clangd --check=modules/iue-io/ccsv.h
|
||||
# debug: clangd --check=task1.hpp
|
||||
# debug: clangd --check=task1.test.cpp
|
||||
InlayHints:
|
||||
Enabled: No
|
||||
ParameterNames: Yes
|
||||
DeducedTypes: No
|
||||
---
|
||||
CompileFlags:
|
||||
Add:
|
||||
# - --target=x86_64-w64-windows-gnu
|
||||
# - --target=x86_64-pc-linux-gnu
|
||||
- -Wall
|
||||
- -Wno-unused-function
|
||||
- -Wno-unused-variable
|
||||
---
|
||||
If:
|
||||
PathMatch: [.*\.c, .*\.h]
|
||||
CompileFlags:
|
||||
Add: [-std=c11]
|
||||
---
|
||||
If:
|
||||
PathMatch: [.*\.cpp, .*\.hpp]
|
||||
CompileFlags:
|
||||
Add: [-std=c++20]
|
||||
@@ -0,0 +1,3 @@
|
||||
task1
|
||||
task2
|
||||
task3
|
||||
@@ -0,0 +1,3 @@
|
||||
task1.main.cpp
|
||||
task2.hpp
|
||||
task3.hpp
|
||||
@@ -0,0 +1,16 @@
|
||||
## source: https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings
|
||||
|
||||
# Set the default behavior, in case people don't have core.autocrlf set.
|
||||
* text=auto
|
||||
|
||||
# Explicitly declare text files you want to always be normalized and converted
|
||||
# to native line endings on checkout.
|
||||
*.h text
|
||||
*.hpp text
|
||||
*.c text
|
||||
*.cpp text
|
||||
*.py text
|
||||
*.ipynb text
|
||||
*.md text
|
||||
*.txt text
|
||||
*.csv text
|
||||
@@ -0,0 +1,358 @@
|
||||
# custom
|
||||
|
||||
build
|
||||
doc
|
||||
.cache
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
# https://github.com/github/gitignore/blob/main/CMake.gitignore
|
||||
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
|
||||
# ttps://github.com/github/gitignore/blob/main/C.gitignore
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# Kernel Module Compile Results
|
||||
*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# https://github.com/github/gitignore/blob/main/C%2B%2B.gitignore
|
||||
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
*.smod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
|
||||
# source: https://github.com/github/gitignore/blob/main/Python.gitignore
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.nox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
cover/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
.pybuilder/
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
# For a library or package, you might want to ignore these files since the code is
|
||||
# intended to run in multiple environments; otherwise, check them in:
|
||||
# .python-version
|
||||
|
||||
# pipenv
|
||||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
||||
# install all needed dependencies.
|
||||
#Pipfile.lock
|
||||
|
||||
# poetry
|
||||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
||||
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
||||
# commonly ignored for libraries.
|
||||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
||||
#poetry.lock
|
||||
|
||||
# pdm
|
||||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
||||
#pdm.lock
|
||||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
||||
# in version control.
|
||||
# https://pdm.fming.dev/#use-with-ide
|
||||
.pdm.toml
|
||||
|
||||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
||||
__pypackages__/
|
||||
|
||||
# Celery stuff
|
||||
celerybeat-schedule
|
||||
celerybeat.pid
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
# pytype static type analyzer
|
||||
.pytype/
|
||||
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# jetbrain IDEs: https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
# VSCODE source: https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
@@ -0,0 +1,47 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# define project metadata
|
||||
|
||||
project(exercise5 LANGUAGES CXX
|
||||
DESCRIPTION "exercise7"
|
||||
HOMEPAGE_URL "https://sgit.iue.tuwien.ac.at/360050/exercise7")
|
||||
|
||||
# setting required language standards
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
# misc settings
|
||||
|
||||
# avoid ctest dashboard targets
|
||||
set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)
|
||||
# generate a compile_commands.json
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
# make all symbols visible on windows (which is default on unix)
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
|
||||
# options
|
||||
|
||||
option(BUILD_TESTING "enable testing with ctest" ON)
|
||||
|
||||
# testing
|
||||
|
||||
include(CTest)
|
||||
|
||||
# get/setup dependencies
|
||||
|
||||
include_directories(modules)
|
||||
|
||||
# include own targets
|
||||
|
||||
add_executable(task1 task1.main.cpp)
|
||||
add_test(NAME task1 COMMAND task1 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
set_property(TEST task1 PROPERTY PASS_REGULAR_EXPRESSION ".*360050.*electromagnetic")
|
||||
|
||||
add_executable(task2 task2.test.cpp)
|
||||
add_test(NAME task2 COMMAND task2 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
|
||||
add_executable(task3 task3.test.cpp)
|
||||
add_test(NAME task3 COMMAND task3 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Hausübung 7 (3 Punkte)
|
||||
|
||||
**Ausgabe**: Donnerstag 02. Mai 2024, vormittags.
|
||||
|
||||
**Abgabe bis**: Montag 13. Mai 2024, Ende des Tages.
|
||||
|
||||
**Abgabe via**: git-Repository mit dem Namen **`exercise7`** auf unserem git-Server https://sgit.iue.tuwien.ac.at
|
||||
|
||||
Details zum Abgabeprozess via `git` finden Sie hier: https://sgit.iue.tuwien.ac.at/360050/git
|
||||
|
||||
# Aufgabenstellung
|
||||
|
||||
In dieser Hausübung werden folgende Themen erstmalig einfliessen:
|
||||
|
||||
- Arbeiten mit generischen Funktionen/Klassen (*templates*)
|
||||
- Implementierung einer Klasse, die den Anforderungen eine gegebenen Template-Schnittstelle (*concept*) erfüllt
|
||||
|
||||
**Die genaue Beschreibung und Anforderungen finden Sie in [`main.ipynb`](main.ipynb) und im Quellcode.**
|
||||
@@ -0,0 +1 @@
|
||||
-Imodules
|
||||
@@ -0,0 +1,193 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Aufgabe 1: Ein eigenes kleines C++-Programm (*function template*) (1 Punkt)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Erstellen Sie in [`task1.main.cpp`](task1.main.cpp) ein lauffähiges Ein-Dateien-Programm das folgende Struktur aufweist:\n",
|
||||
"\n",
|
||||
"- Einbinden benötigter Header-Dateien aus der Standardbibliothek, z.B.:\n",
|
||||
"\t```cpp\n",
|
||||
"\t#include <iostream> // std::cout, std::endl\n",
|
||||
"\t#include <vector> // std::vector\n",
|
||||
"\t...\n",
|
||||
"\t```\n",
|
||||
"- Definition/Implementierung einer eigenen Funktion in einem eigenen Namensraum, z.B.:\n",
|
||||
"\t```cpp\n",
|
||||
"\tnamespace task1 {\n",
|
||||
"\n",
|
||||
"\t...\n",
|
||||
"\n",
|
||||
"\t}\n",
|
||||
"\t``` \n",
|
||||
"- Definition/Implementierung einer `main`-Funktion, die Ihre selbst geschriebene Funktion verwendet, z.B.:\n",
|
||||
"\t```cpp\n",
|
||||
"\tint main(){\n",
|
||||
"\n",
|
||||
"\t ...\n",
|
||||
"\n",
|
||||
"\t return 0;\n",
|
||||
"\t}\n",
|
||||
"\t``` \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"- Eine genaue Beschreibung und Anforderungen finden Sie in [`task1.main.cpp`](task1.main.cpp)\n",
|
||||
"- Ihre Implementierung erfolgt ebenfalls in [`task1.main.cpp`](task1.main.cpp)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Aufgabe 2: Umschreiben gegebener Funktionen zur Funktions-Templates (1 Punkt)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"In dem Header [`task2.hpp`](task2.hpp) sind 4 Funktionen in Namensraum `task2` gegeben.\n",
|
||||
"Ihre Aufgabe besteht darin, diese so anzupassen, dass mindestens die im Test verwendeten Parametertypen unterstützt werden.\n",
|
||||
"\n",
|
||||
"Ihre Implementierung soll durch *verändern* der gegebenen Funktionen erfolgen: **Sie schreiben jede der Funktionen zu einem Funktions-Template um**.\n",
|
||||
"\n",
|
||||
"Hier ein Beispiel anhand einer Funktion `add`:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"```cpp\n",
|
||||
"namespace task2 {\n",
|
||||
"\n",
|
||||
"/// handout\n",
|
||||
"inline int add(int a, int b)\n",
|
||||
"{\n",
|
||||
" return a + b;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"/// solution\n",
|
||||
"template <typename T>\n",
|
||||
"inline T add(T a, T b)\n",
|
||||
"{\n",
|
||||
" return a + b;\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"} \n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"- Die vorgegebenen Funktionen und eine genaue Beschreibung und Anforderungen finden Sie in [`task2.hpp`](task2.hpp)\n",
|
||||
"- Ihre Implementierung erfolgt ebenfalls in [`task2.hpp`](task2.hpp)\n",
|
||||
"- Die zugeordneten Tests finden Sie in [`task2.test.cpp`](task2.test.cpp) \n",
|
||||
"- **Wichtig**: Nach erfolgter Implemenierung müssen Sie in [`task2.test.cpp`](task2.test.cpp) die Tests für varierende Parametertypen **manuell einkommentieren**."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Aufgabe 3: Implementierung einer eigenen Klasse, die gegebene Schnittstellenanforderungen erfüllt (1 Punkt)\n",
|
||||
"\n",
|
||||
"Für diese Aufgabe implementieren Sie eine Klasse `point`, welche die Schnittstellenanforderungen (*concept*) in [`task3.concept.hpp`](task3.concept.hpp) erfüllt. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"- Die vorgegebenen Deklaration und eine genaue Beschreibung und Anforderungen finden Sie in [`task3.hpp`](task3.hpp)\n",
|
||||
"- Ihre Implementierung erfolgt ebenfalls in [`task3.hpp`](task3.hpp)\n",
|
||||
"- Die zugeordneten Tests finden Sie in [`task3.test.cpp`](task3.test.cpp)\n",
|
||||
"- **Wichtig**: Nach erfolgter Implemenierung müssen Sie in [`task3.test.cpp`](task3.test.cpp) die Tests **manuell einkommentieren**."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Kompilieren/Testen\n",
|
||||
"\n",
|
||||
"So testen Sie Ihre Implementierung (direkter Aufruf von `g++`):\n",
|
||||
"\n",
|
||||
"```shell\n",
|
||||
"# prepare\n",
|
||||
"mkdir build\n",
|
||||
"# compile\n",
|
||||
"g++ -g -std=c++20 task1.main.cpp -o build/task1\n",
|
||||
"g++ -g -std=c++20 task2.test.cpp -o build/task2\n",
|
||||
"g++ -g -std=c++20 task3.test.cpp -o build/task3\n",
|
||||
"\n",
|
||||
"# run tests\n",
|
||||
"./build/task1\n",
|
||||
"./build/task2\n",
|
||||
"./build/task3\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Alternativ (mittels CMake-Configuration):\n",
|
||||
"\n",
|
||||
"```shell\n",
|
||||
"# prepare\n",
|
||||
"cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug\n",
|
||||
"# compile\n",
|
||||
"cmake --build build --config Debug --target task1\n",
|
||||
"cmake --build build --config Debug --target task2\n",
|
||||
"cmake --build build --config Debug --target task3\n",
|
||||
"cmake --build build --config Debug # all\n",
|
||||
"# run tests\n",
|
||||
"ctest --test-dir build -C Debug -R task1 --verbose\n",
|
||||
"ctest --test-dir build -C Debug -R task2 --verbose\n",
|
||||
"ctest --test-dir build -C Debug -R task3 --verbose\n",
|
||||
"ctest --test-dir build -C Debug # all\n",
|
||||
"``` \n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": ".venv",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.15"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/// @file
|
||||
/// @brief Task1: "single-file" executable C++ program
|
||||
|
||||
/// @todo Include standard library headers as needed
|
||||
|
||||
namespace task1 {
|
||||
|
||||
/// @todo Implement a function template 'print' for a template type T according to the description below:
|
||||
/// - a std::vector with elements of type T is received via a parameter (std::vector<T>)
|
||||
/// - the function then prints all elements to the console **without separation** (i.e. {1,2,3} => 123) ending with a
|
||||
/// new line
|
||||
/// - the function has no return value
|
||||
/// @note You can assume that the template type T is printable, i.e. this works:
|
||||
/// T value{};
|
||||
/// std::cout << value;
|
||||
|
||||
} // namespace task1
|
||||
|
||||
/// @todo Implement a 'main' function conducting the following tasks in this order:
|
||||
/// - fill a std::vector<int> with with the following sequence of values
|
||||
/// 3, 6, 0, 0, 5, 0
|
||||
/// - fill a std::vector<std::string> with with the following sequence of values
|
||||
/// "e", "lec", "tro", "mag", "net", "ic"
|
||||
/// - use your function to print both vectors to the console separately
|
||||
int main() { return 0; }
|
||||
@@ -0,0 +1,81 @@
|
||||
/// @file
|
||||
/// @brief Task2: Function Declaration & Definitions
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef> // std::size_t
|
||||
#include <set> // std::set
|
||||
#include <vector> // std::vector
|
||||
|
||||
namespace task2 {
|
||||
|
||||
/// @brief Sums the values
|
||||
/// @param vec sequence of values
|
||||
/// @return Sum of all values in the sequence
|
||||
/// @todo Adjust the function to accept a vector of arbitrary types:
|
||||
/// - You can assume that the arbitrary type supports the += operator
|
||||
/// - You need to uncomment respective lines in task2.test.cpp to test your implementation.
|
||||
inline int sum(const std::vector<int>& vec) {
|
||||
int sum{}; // inits with '0'
|
||||
|
||||
for (const int& x : vec) {
|
||||
sum += x;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
/// @brief Finds the minimum value
|
||||
/// @param vec Sequence of values (assume size() >= 1)
|
||||
/// @return Minimum value in the sequence
|
||||
/// @todo Adjust the function to accept a vector of arbitrary types:
|
||||
/// - You can assume that the arbitrary type supports the '<' operator
|
||||
/// - You need to uncomment respective lines in task2.test.cpp to test your implementation.
|
||||
inline int min(const std::vector<int>& vec) {
|
||||
int min = vec.front();
|
||||
|
||||
for (const int& x : vec) {
|
||||
if (x < min) {
|
||||
min = x;
|
||||
}
|
||||
}
|
||||
|
||||
return min;
|
||||
}
|
||||
|
||||
/// @brief Finds the number of unique values
|
||||
/// @param vec Sequence of values
|
||||
/// @return Number of unique values in the sequence
|
||||
/// @todo Adjust the function to accept a vector of arbitrary types:
|
||||
/// - You can assume that the arbitrary type can be inserted into a std::set (i.e. is less-compareable)
|
||||
/// - You need to uncomment respective lines in task2.test.cpp to test your implementation.
|
||||
inline std::size_t count_unique(const std::vector<int>& vec) {
|
||||
std::set<int> unique;
|
||||
|
||||
for (const int& x : vec) {
|
||||
unique.insert(x);
|
||||
}
|
||||
|
||||
return unique.size();
|
||||
}
|
||||
|
||||
/// @brief Generates a range of equidistant values in an interval
|
||||
/// @param start Start of the interval
|
||||
/// @param end End of the interval
|
||||
/// @param N number of values to generate
|
||||
/// @return Sequence of equidistant values
|
||||
/// @todo Adjust the function to accept any type (noy only 'float'):
|
||||
/// - You can assume that the arbitrary type support arithmetic operations
|
||||
/// - You need to uncomment respective lines in task2.test.cpp to test your implementation.
|
||||
inline std::vector<float> range(float start, float end, unsigned int N) {
|
||||
std::vector<float> rtn;
|
||||
const float step = (end - start) / (N - 1);
|
||||
|
||||
for (auto n = 0u; n < N; ++n) {
|
||||
rtn.emplace_back(start + step * n);
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
} // namespace task2
|
||||
@@ -0,0 +1,88 @@
|
||||
/// @file
|
||||
/// @brief Task2: tests
|
||||
|
||||
#include "task2.hpp" // task2::sum, task2::min, ...
|
||||
|
||||
#include <cassert> // assert
|
||||
#include <cmath> // std::abs
|
||||
#include <string> // std::string
|
||||
#include <iostream> // std::cout, sts::endl
|
||||
|
||||
///@brief task2::sum signature check: returns a T when passing a std::vector<T>
|
||||
template <typename T>
|
||||
concept sum_valid = requires(std::vector<T> vec) {
|
||||
{ task2::sum(vec) } -> std::same_as<T>;
|
||||
};
|
||||
|
||||
///@brief task2::min signature check: returns a T when passing a std::vector<T>
|
||||
template <typename T>
|
||||
concept min_valid = requires(std::vector<T> vec) {
|
||||
{ task2::min(vec) } -> std::same_as<T>;
|
||||
};
|
||||
|
||||
///@brief task2::count_unique signature check: returns an integer (std::size_t) when passing a std::vector<T>
|
||||
template <typename T>
|
||||
concept count_unique_valid = requires(std::vector<T> vec) {
|
||||
{ task2::count_unique(vec) } -> std::same_as<std::size_t>;
|
||||
};
|
||||
|
||||
///@brief task2::range signature check: returns a std::vector<T> when passing a type T as start and end
|
||||
template <typename T>
|
||||
concept range_valid = requires(T value) {
|
||||
{ task2::range(value, value, 0u) } -> std::same_as<std::vector<T>>;
|
||||
};
|
||||
|
||||
int main() {
|
||||
|
||||
{ // testing task2::sum
|
||||
|
||||
// testing formal interface
|
||||
static_assert(sum_valid<int>);
|
||||
// static_assert(sum_valid<float>); // todo: uncomment
|
||||
// static_assert(sum_valid<double>); // todo: uncomment
|
||||
|
||||
// testing functionality
|
||||
assert((task2::sum(std::vector<int>{1, 2, 3}) == 6));
|
||||
// assert(std::abs(task2::sum(std::vector<double>{0.1, 0.2, 0.3}) - 0.6) < 1e-9); // todo: uncomment
|
||||
// assert(std::abs(task2::sum(std::vector<float>{0.1f, 0.2f, 0.3f}) - 0.6f) < 1e-6f); // todo: uncomment
|
||||
}
|
||||
|
||||
{ // testing task2::min
|
||||
|
||||
// testing formal interface
|
||||
static_assert(min_valid<int>);
|
||||
// static_assert(min_valid<float>); // todo: uncomment
|
||||
// static_assert(min_valid<double>); // todo: uncomment
|
||||
|
||||
// testing functionality
|
||||
assert((task2::min(std::vector<int>{1, 2, 3}) == 1));
|
||||
// assert(std::abs(task2::min(std::vector<double>{0.1, 0.2, 0.3}) - 0.1) < 1e-9); // todo: uncomment
|
||||
// assert(std::abs(task2::min(std::vector<float>{0.1f, 0.2f, 0.3f}) - 0.1f) < 1e-6f); // todo: uncomment
|
||||
}
|
||||
|
||||
{ // testing task2::count_unique
|
||||
|
||||
// testing formal interface
|
||||
static_assert(count_unique_valid<int>);
|
||||
// static_assert(count_unique_valid<std::string>); // todo: uncomment
|
||||
|
||||
// testing functionality
|
||||
assert(task2::count_unique(std::vector<int>{1, 2, 3}) == 3);
|
||||
// assert(task2::count_unique(std::vector<std::string>{{"one", "one", "two"}}) == 2); // todo: uncomment
|
||||
}
|
||||
|
||||
{ // testing task2::range
|
||||
|
||||
// testing formal interface
|
||||
static_assert(range_valid<float>);
|
||||
// static_assert(range_valid<double>); // todo: uncomment
|
||||
|
||||
// testing functionality
|
||||
assert(std::abs(task2::range(0.0f, 10.0f, 3).at(1) - 5.0f) < 1e-6);
|
||||
// assert(std::abs(task2::range<double>(0.0, 10.0, 3).at(1) - 5.0) < 1e-9); // todo: uncomment
|
||||
}
|
||||
|
||||
std::cout << "task2.test.cpp: all asserts passed" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/// @file
|
||||
/// @brief Task3: Formal interface requirements
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <concepts> // std::same_as
|
||||
|
||||
namespace task3 {
|
||||
|
||||
/// @brief Formal interface requirements (concept) for your 'Point' class
|
||||
template <typename T>
|
||||
concept PointConcept = requires(T value, const T& const_ref, const T& const_other) {
|
||||
{ T(10, 20) }; ///< T can be constructed from two numerical values
|
||||
|
||||
{ const_ref.get_x() } -> std::same_as<double>; ///< T has const public member function `get_x` that returns `double`
|
||||
{ const_ref.get_y() } -> std::same_as<double>; ///< T has const public member function `get_y` that returns `double`
|
||||
|
||||
{ value.set_x(10) }; ///< T has public member function `set_x` that accepts number
|
||||
{ value.set_y(10) }; ///< T has public member function `set_y` that accepts number
|
||||
|
||||
{ const_ref == const_other } -> std::same_as<bool>; ///< T has const operator==() overload for another T that returns boolean.
|
||||
};
|
||||
|
||||
} // namespace task3
|
||||
@@ -0,0 +1,10 @@
|
||||
/// @file
|
||||
/// @brief Task3: Implementation of 'Point'
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace task3 {
|
||||
|
||||
/// @todo Implement a struct or class 'Point' that fulfills the concept task3::PointConcept (details see 'task3.concept.hpp')
|
||||
|
||||
} // namespace task3
|
||||
@@ -0,0 +1,17 @@
|
||||
/// @file
|
||||
/// @brief Task3: tests
|
||||
|
||||
#include "task3.hpp" // task3::Point
|
||||
#include "task3.concept.hpp" // task3::PointConcept
|
||||
#include <iostream> // std::cout, sts::endl
|
||||
|
||||
int main() {
|
||||
|
||||
using namespace task3;
|
||||
|
||||
// static_assert(PointConcept<Point>); // todo: uncomment
|
||||
|
||||
std::cout << "task3.test.cpp: all asserts passed" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user