init
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
---
|
||||
Language: Cpp
|
||||
AllowShortFunctionsOnASingleLine: Empty
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
ColumnLimit: 120
|
||||
TabWidth: 4
|
||||
IndentWidth: 2
|
||||
...
|
||||
@@ -0,0 +1,20 @@
|
||||
InlayHints:
|
||||
Enabled: No
|
||||
ParameterNames: Yes
|
||||
DeducedTypes: No
|
||||
---
|
||||
CompileFlags:
|
||||
Add:
|
||||
- -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,5 @@
|
||||
task1_py
|
||||
task1_c
|
||||
task1_cpp
|
||||
task2
|
||||
task3
|
||||
@@ -0,0 +1,5 @@
|
||||
info_python.txt
|
||||
info_c.txt
|
||||
info_cpp.txt
|
||||
task2.main.cpp
|
||||
task3.cpp
|
||||
@@ -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,360 @@
|
||||
# custom
|
||||
|
||||
*.csv
|
||||
*.png
|
||||
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,4 @@
|
||||
[submodule "modules"]
|
||||
path = modules
|
||||
url = https://sgit.iue.tuwien.ac.at/360050/modules
|
||||
branch = main
|
||||
@@ -0,0 +1,59 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# define project metadata
|
||||
|
||||
project(exercise3 LANGUAGES CXX C
|
||||
DESCRIPTION "exercise1"
|
||||
HOMEPAGE_URL "https://sgit.iue.tuwien.ac.at/360050/exercise1")
|
||||
|
||||
# setting required language standards
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED True)
|
||||
set(CMAKE_C_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
|
||||
|
||||
find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
||||
add_test(NAME task1_py COMMAND ${Python3_EXECUTABLE} task1.test.py WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
|
||||
add_executable(task1_c task1.test.c)
|
||||
add_test(NAME task1_c COMMAND task1_c WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
|
||||
add_executable(task1_cpp task1.test.cpp)
|
||||
add_test(NAME task1_cpp COMMAND task1_cpp WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
|
||||
add_custom_target(task1)
|
||||
add_dependencies(task1 task1_c task1_cpp)
|
||||
|
||||
add_executable(task2 task2.cpp)
|
||||
add_test(NAME task2 COMMAND task2 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
set_property(TEST task2 PROPERTY PROPERTY_REGULAR_EXPRESSION "6633")
|
||||
|
||||
add_executable(task3 task3.cpp task3.test.cpp)
|
||||
add_test(NAME task3 COMMAND task3 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
@@ -0,0 +1,19 @@
|
||||
# Hausübung 1 (3 Punkte)
|
||||
|
||||
**Ausgabe**: Donnerstag 7. März 2024, vormittags.
|
||||
|
||||
**Abgabe bis**: Montag 18. März 2024, Ende des Tages.
|
||||
|
||||
**Abgabe via**: git-Repository mit dem Namen **`exercise1`** 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:
|
||||
|
||||
- Konfiguration der benötigten Werkzeuge
|
||||
- Implementierung/Kompilierung/Ausführen eines lauffähigen Programms
|
||||
- Einfache Funktionen (ohne Bedingungen/Verzweigungen) mit Fundamentalen Typen als Parameter und Rückgabewert
|
||||
|
||||
**Die genaue Beschreibung und Anforderungen finden Sie in [`main.ipynb`](main.ipynb) und im Quellcode.**
|
||||
@@ -0,0 +1 @@
|
||||
-Imodules
|
||||
@@ -0,0 +1,4 @@
|
||||
os: Windows 11 10.0.22631
|
||||
py: CPython 3.12.2
|
||||
np: numpy 1.26.4
|
||||
mpl: matplotlib 3.8.3
|
||||
@@ -0,0 +1,204 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Aufgabe 1: Konfigurieren und Testen der eigenen Umgebung (1 Punkt)\n",
|
||||
"\n",
|
||||
"1. Konfigurieren Sie Ihr eigenes System: https://sgit.iue.tuwien.ac.at/360050/setup\n",
|
||||
"\n",
|
||||
"2. Nachdem Sie Ihre Konfiguration abgeschlossen haben, testen Sie Ihre Konfiguration indem Sie folgenden drei mitgelieferte Tests ausführen:\n",
|
||||
"\n",
|
||||
"\t- [task1.test.py](task1.test.py) testet die Python-Konfiguration. \n",
|
||||
"\t- [task1.test.c](task1.test.c) testet die C-Konfiguration.\n",
|
||||
"\t- [task1.test.cpp](task1.test.cpp) testet die C++-Konfiguration."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Kompilieren/Ausführen \n",
|
||||
"\n",
|
||||
"Mittels manueller Aufrufe (`gcc/g++/python`):\n",
|
||||
"```shell\n",
|
||||
"# prepare folder\n",
|
||||
"mkdir build\n",
|
||||
"# compile for task1\n",
|
||||
"gcc -Imodules -std=c11 -g task1.test.c -o build/task1_c.exe\n",
|
||||
"g++ -Imodules -std=c++20 -g task1.test.cpp -o build/task1_cpp.exe\n",
|
||||
"# run tests for task1\n",
|
||||
"python task1.test.py # produces \"info_python.txt\"\n",
|
||||
"./build/task1_c.exe # produces \"info_c.txt\"\n",
|
||||
"./build/task1_cpp.exe # produces \"info_cpp.txt\"\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Alternativ mittels *CMake* (optional):\n",
|
||||
"```shell\n",
|
||||
"# prepare compilation\n",
|
||||
"cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug\n",
|
||||
"# compile for task1\n",
|
||||
"cmake --build build --config Debug --target task1\n",
|
||||
"# run tests for task1\n",
|
||||
"ctest --test-dir build -C Debug -R task1\n",
|
||||
"```\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Aufgabe 2: Ein eigenes kleines C++-Programm (1 Punkt)\n",
|
||||
"\n",
|
||||
"Erstellen Sie 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|endl\n",
|
||||
"\t#include <...>\n",
|
||||
"\t```\n",
|
||||
"- Definition/Implementierung einer eigenen Funktion, z.B.:\n",
|
||||
"\t```cpp\n",
|
||||
"\tint sum(...){\n",
|
||||
"\t ...\n",
|
||||
"\t}\n",
|
||||
"\t``` \n",
|
||||
"- Definition/Implementierung einer `main`-Funktion (Einstiegspunkt für jedes lauffähige Programm), die Ihre selbest geschriebene Funktion verwendet und die berechneten Ergebnisse in der Konsole ausgibt, z.B.:\n",
|
||||
"\t```cpp\n",
|
||||
"\tint main(){\n",
|
||||
"\t ...\n",
|
||||
"\t auto res = sum(...)\t\n",
|
||||
"\t std::cout << res << std::endl;\n",
|
||||
"\t return 0;\n",
|
||||
"\t}\n",
|
||||
"\t``` "
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"- Eine genaue Beschreibung und Anforderungen finden Sie in [task2.main.cpp](task2.main.cpp)\n",
|
||||
"- Ihre Implementierung erfolgt ebenfalls in [task2.main.cpp](task2.main.cpp)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Kompilieren/Ausführen \n",
|
||||
"\n",
|
||||
"Mittels manueller Aufrufe (`gcc/g++/python`):\n",
|
||||
"```shell\n",
|
||||
"# prepare folder\n",
|
||||
"mkdir build\n",
|
||||
"# compile for task2\n",
|
||||
"g++ -std=c++20 -g task2.main.cpp -o build/task2.exe\n",
|
||||
"# run test (your output will be parsed when graded)\n",
|
||||
"./build/task2.exe\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Alternativ mittels *CMake* (optional):\n",
|
||||
"```shell\n",
|
||||
"# prepare compilation\n",
|
||||
"cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug\n",
|
||||
"# compile for task2\n",
|
||||
"cmake --build build --config Debug --target task2\n",
|
||||
"# run tests for task2\n",
|
||||
"ctest --test-dir build -C Debug -R task2\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Aufgabe 3: Einfache Funktionen ohne Verzweigungen (1 Punkt)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Implementieren Sie folgende Funktionen:\n",
|
||||
"\n",
|
||||
"```cpp\n",
|
||||
"double add(double x, double y, double z);\n",
|
||||
"double mul(double x, double y, double z);\n",
|
||||
"double frac(double x, double y);\n",
|
||||
"double mean(double x, double y, double z);\n",
|
||||
"double squared(double x);\n",
|
||||
"double cubed(double x);\n",
|
||||
"double eval(double x, double a, double b, double c);\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"- Die vorgegebenen Deklarationen und eine genaue Beschreibung und Anforderungen finden Sie in [`task3.hpp`](task3.hpp)\n",
|
||||
"- Ihre Implementierung erfolgt in [`task3.cpp`](task3.cpp)\n",
|
||||
"- Die zugeordneten Tests finden Sie in [`task3.test.cpp`](task3.test.cpp)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"#### Kompilieren/Ausführen \n",
|
||||
"\n",
|
||||
"Mittels manueller Aufrufe (`gcc/g++/python`):\n",
|
||||
"```shell\n",
|
||||
"# prepare folder\n",
|
||||
"mkdir build\n",
|
||||
"# compile for task3\n",
|
||||
"g++ -std=c++20 -g task3.cpp task3.test.cpp -o build/task3.exe\n",
|
||||
"# run test\n",
|
||||
"./build/task3.exe\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Alternativ mittels *CMake* (optional):\n",
|
||||
"```shell\n",
|
||||
"# prepare compilation\n",
|
||||
"cmake -S . -B build -D CMAKE_BUILD_TYPE=Debug\n",
|
||||
"# compile for task3\n",
|
||||
"cmake --build build --config Debug --target task3\n",
|
||||
"# run tests for task3\n",
|
||||
"ctest --test-dir build -C Debug -R task3\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
|
||||
}
|
||||
Submodule
+1
Submodule exercise1/modules added at b8ce24c87f
@@ -0,0 +1,27 @@
|
||||
/// @file
|
||||
/// @brief Task1: tests (support for C11 standard)
|
||||
|
||||
#include <assert.h> // assert
|
||||
#include <stdio.h> // FILE
|
||||
#include <stdlib.h> // EXIT_FAILURE|EXIT_SUCCESS
|
||||
|
||||
#include "iue-io/ccsv.h" // https://sgit.iue.tuwien.ac.at/360050/modules
|
||||
|
||||
int main(void) {
|
||||
|
||||
FILE* stream = fopen("info_c.txt", "w");
|
||||
if (stream == NULL)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
fprintf(stream, "This compilation unit was compiled\n");
|
||||
fprintf(stream, " - on %s at %s\n", __DATE__, __TIME__);
|
||||
fprintf(stream, " - using the C language standard %li\n", __STDC_VERSION__);
|
||||
fprintf(stream, " - the main-function was present in this file: %s\n", __FILE__);
|
||||
fclose(stream);
|
||||
|
||||
assert(__STDC_VERSION__ >= 201112L);
|
||||
|
||||
printf("task1.test.c: all asserts passed\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/// @file
|
||||
/// @brief Task1: tests (support for C++20 standard)
|
||||
|
||||
#include <cassert> // assert
|
||||
#include <filesystem> // std::filesystem::path
|
||||
#include <fstream> // std::ofstream
|
||||
#include <iostream> // std::cout|endl
|
||||
#include <sstream> // std::istringstream
|
||||
|
||||
#include <version> // https://en.cppreference.com/w/cpp/utility/feature_test
|
||||
|
||||
#include "iue-io/csv.hpp" // https://sgit.iue.tuwien.ac.at/360050/modules
|
||||
|
||||
int main() {
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
oss << "This compilation unit was compiled" << std::endl;
|
||||
oss << " - on " << __DATE__ << " at " << __TIME__ << std::endl;
|
||||
oss << " - using the C++ language standard " << __cplusplus << std::endl;
|
||||
oss << " - the main-function was present in this file: " << __FILE__ << std::endl;
|
||||
|
||||
std::filesystem::path filename = "info_cpp.txt";
|
||||
std::ofstream ofs(filename);
|
||||
ofs.exceptions(std::ios::failbit);
|
||||
ofs << oss.str();
|
||||
|
||||
assert(__cplusplus >= 202002L);
|
||||
assert(__cpp_lib_filesystem >= 201703L);
|
||||
assert(__cpp_concepts >= 201907L);
|
||||
|
||||
std::cout << "task1.test.cpp: all asserts passed" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
""" Task1: tests (support for python, numpy and matplotlib) """
|
||||
|
||||
import platform
|
||||
|
||||
def os_info():
|
||||
""" Collects basic info on the operating system and logs it to a file 'os_info.txt'. """
|
||||
os_type = platform.system()
|
||||
os_rel = platform.release()
|
||||
os_ver = platform.version()
|
||||
return f"os: {os_type} {os_rel} {os_ver}\n"
|
||||
|
||||
def python_info():
|
||||
""" Obtains information on Python installation in use and logs it to a file 'python_info.txt'. """
|
||||
python_ver = platform.python_version()
|
||||
python_impl = platform.python_implementation()
|
||||
return f"py: {python_impl} {python_ver}\n"
|
||||
|
||||
import numpy
|
||||
|
||||
def numpy_info():
|
||||
""" Obtains information on the numpy package in use and logs it to a file 'numpy_info.txt'. """
|
||||
numpy_name = numpy.__name__
|
||||
numpy_ver = numpy.__version__
|
||||
return f"np: {numpy_name} {numpy_ver}\n"
|
||||
|
||||
import matplotlib
|
||||
|
||||
def matplotlib_info():
|
||||
""" Obtains information on the matplotlib package in use and logs it to a file 'matplotlib_info.txt'. """
|
||||
matplotlib_name = matplotlib.__name__
|
||||
matplotlib_ver = matplotlib.__version__
|
||||
return f"mpl: {matplotlib_name} {matplotlib_ver}\n"
|
||||
|
||||
import unittest
|
||||
import os
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
|
||||
def test_python_env(self):
|
||||
with open("info_python.txt", "w") as f:
|
||||
f.write(os_info())
|
||||
f.write(python_info())
|
||||
f.write(numpy_info())
|
||||
f.write(matplotlib_info())
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,25 @@
|
||||
/// @file
|
||||
/// @brief Task2: "single-file" excutable C++ program
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/// @brief Calculate the sum of two integer values
|
||||
/// @param a first integer value
|
||||
/// @param b second integer value
|
||||
/// @return Sum of the two integer values
|
||||
int sum(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
|
||||
/// @brief main function (entry point) conducting the following tasks in this order
|
||||
/// - create two local variables holding the integer values 33 and 6600
|
||||
/// - call your function 'sum' and provide the prepared variables as arguments to the call
|
||||
/// - capture the result of your function call in a local variable and print it to the console
|
||||
int main() {
|
||||
int a = 33;
|
||||
int b = 6600;
|
||||
int result = sum(a, b);
|
||||
std::cout << "The sum of " << a << " and " << b << " is " << result << std::endl;
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/// @file
|
||||
/// @brief Task3: implementation
|
||||
|
||||
#include "task3.hpp" // add|mul|frac|mean|squared|cubed|eval
|
||||
|
||||
/// @todo Include standard library headers as needed
|
||||
|
||||
/// @brief Calculates the sum of three values
|
||||
/// @param x 1st value
|
||||
/// @param y 2nd value
|
||||
/// @param z 3rd value
|
||||
/// @return Sum of the three values
|
||||
double add(double x, double y, double z) {
|
||||
return x+y+z;
|
||||
}
|
||||
|
||||
/// @brief Calculates the product of three values
|
||||
/// @param x 1st value
|
||||
/// @param y 2nd value
|
||||
/// @param z 3rd value
|
||||
/// @return Product of the three values
|
||||
double mul(double x, double y, double z) {
|
||||
return x*y*z;
|
||||
}
|
||||
|
||||
/// @brief Calculates the fraction of two values
|
||||
/// @param x 1st value
|
||||
/// @param y 2nd value
|
||||
/// @return Fraction of x divided by y
|
||||
double frac(double x, double y) {
|
||||
return x/y;
|
||||
}
|
||||
|
||||
/// @brief Calculates the average (arithmetic mean) of three values
|
||||
/// @param x 1st value
|
||||
/// @param y 2nd value
|
||||
/// @param z 3rd value
|
||||
/// @return Average of the three values
|
||||
double mean(double x, double y, double z) {
|
||||
return (x+y+z)/3;
|
||||
}
|
||||
|
||||
/// @brief Calculates the square of a value
|
||||
/// @param x Value
|
||||
/// @return Square of x
|
||||
double squared(double x) {
|
||||
return x*x;
|
||||
}
|
||||
|
||||
/// @brief Calculates the third power of a value
|
||||
/// @param x Value
|
||||
/// @return Cube of x
|
||||
double cubed(double x) {
|
||||
return x*x*x;
|
||||
}
|
||||
|
||||
/// @brief Evaluates a polynomial 'f(x) = a*x^2 + b*x + c'
|
||||
/// @param x Variable
|
||||
/// @param a Coefficient
|
||||
/// @param b Coefficient
|
||||
/// @param c Coefficient
|
||||
/// @return Value of the polynomial at x
|
||||
double eval(double x, double a, double b, double c) {
|
||||
return a*x*x + b*x + c;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/// @file
|
||||
/// @brief Task3: function declarations
|
||||
|
||||
#pragma once
|
||||
|
||||
/// @brief Calculates the sum of three values
|
||||
/// @param x 1st value
|
||||
/// @param y 2nd value
|
||||
/// @param z 3rd value
|
||||
/// @return Sum of the three values
|
||||
double add(double x, double y, double z);
|
||||
|
||||
/// @brief Calculates the product of three values
|
||||
/// @param x 1st value
|
||||
/// @param y 2nd value
|
||||
/// @param z 3rd value
|
||||
/// @return Product of the three values
|
||||
double mul(double x, double y, double z);
|
||||
|
||||
/// @brief Calculates the fraction of two values
|
||||
/// @param x 1st value
|
||||
/// @param y 2nd value
|
||||
/// @return Fraction of x divided by y
|
||||
double frac(double x, double y);
|
||||
|
||||
/// @brief Calculates the average (arithmetic mean) of three values
|
||||
/// @param x 1st value
|
||||
/// @param y 2nd value
|
||||
/// @param z 3rd value
|
||||
/// @return Average of the three values
|
||||
double mean(double x, double y, double z);
|
||||
|
||||
/// @brief Calculates the square of a value
|
||||
/// @param x Value
|
||||
/// @return Square of x
|
||||
double squared(double x);
|
||||
|
||||
/// @brief Calculates the third power of a value
|
||||
/// @param x Value
|
||||
/// @return Cube of x
|
||||
double cubed(double x);
|
||||
|
||||
/// @brief Evaluates a polynomial 'f(x) = a*x^2 + b*x + c'
|
||||
/// @param x Variable
|
||||
/// @param a Coefficient
|
||||
/// @param b Coefficient
|
||||
/// @param c Coefficient
|
||||
/// @return Value of the polynomial at x
|
||||
double eval(double x, double a, double b, double c);
|
||||
@@ -0,0 +1,44 @@
|
||||
/// @file
|
||||
/// @brief Test for Task3
|
||||
|
||||
#include "task3.hpp" // add|mul|frac|mean|squared|cubed|eval
|
||||
|
||||
#include <cassert> // assert
|
||||
#include <cmath> // std::abs
|
||||
#include <iostream> // std::cout|endl
|
||||
|
||||
int main() {
|
||||
|
||||
{ // testing function 'add'
|
||||
double res = add(1, 2, -3);
|
||||
assert(std::abs(res - 0.0) < 1e-7);
|
||||
}
|
||||
{ // testing function 'mul'
|
||||
double res = mul(2, 3, 4);
|
||||
assert(std::abs(res - 24.0) < 1e-7);
|
||||
}
|
||||
{ // testing function 'frac'
|
||||
double res = frac(1, 3);
|
||||
assert(std::abs(res - 1.0 / 3.0) < 1e-7);
|
||||
}
|
||||
{ // testing function 'mean'
|
||||
double res = mean(10, 90, -10);
|
||||
assert(std::abs(res - 30.0) < 1e-7);
|
||||
}
|
||||
{ // testing function 'squared'
|
||||
double res = squared(3);
|
||||
assert(std::abs(res - 9.0) < 1e-7);
|
||||
}
|
||||
{ // testing function 'cubed'
|
||||
double res = cubed(3);
|
||||
assert(std::abs(res - 27.0) < 1e-7);
|
||||
}
|
||||
{ // testing function 'cubed'
|
||||
double res = eval(10.0, 3, -30, 77);
|
||||
assert(std::abs(res - 77) < 1e-7);
|
||||
}
|
||||
|
||||
std::cout << "task3.test.cpp: all asserts passed" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user