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,23 @@
|
||||
# debug: clangd --check=modules/iue-io/ccsv.h
|
||||
# debug: clangd --check=task1.hpp
|
||||
# debug: clangd --check=task1.test.cpp
|
||||
InlayHints:
|
||||
Enabled: No
|
||||
ParameterNames: No
|
||||
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,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
|
||||
+358
@@ -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,4 @@
|
||||
[submodule "modules"]
|
||||
path = modules
|
||||
url = https://sgit.iue.tuwien.ac.at/360050/modules
|
||||
branch = main
|
||||
@@ -0,0 +1,46 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
# define project metadata
|
||||
|
||||
project(lab1 LANGUAGES CXX
|
||||
DESCRIPTION "lab1"
|
||||
HOMEPAGE_URL "https://sgit.iue.tuwien.ac.at/360050/lab1")
|
||||
|
||||
# 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)
|
||||
|
||||
# global includes
|
||||
|
||||
include_directories(modules)
|
||||
|
||||
# include own targets
|
||||
|
||||
add_executable(taskA taskA.cpp)
|
||||
add_test(NAME taskA COMMAND taskA WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
|
||||
add_executable(taskB taskB.cpp)
|
||||
add_test(NAME taskB COMMAND taskB WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
|
||||
add_executable(taskC taskC.cpp)
|
||||
add_test(NAME taskC COMMAND taskC WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# Labor I: Abgabe (30min)
|
||||
|
||||
**Dieser Teil wird über [TUWEL, Labor I: Abgabe (30min)](https://tuwel.tuwien.ac.at/course/view.php?id=62042#coursecontentcollapse5)** abgewickelt.
|
||||
|
||||
# Labor I: Praxisteil (120min)
|
||||
|
||||
- **Fragen Sie frühzeitig nach, falls Unklarheiten bestehen**.
|
||||
- Fragen Sie alles, was Ihnen im Rahmen der Lehrveranstaltung wichtig erscheint.
|
||||
- Es gibt keine Einschränkungen für die Zusammenarbeit zwischen Studierenden beim Bearbeiten der untenstehenden Aufgaben.
|
||||
- Sie haben das Labor erfolgreich absolviert, wenn Sie alle drei Teilaufgaben bei einem Betreuer **demonstriert** haben.
|
||||
- Melden Sie sich bei einem Betreuer, sobald Sie sich in der Lage sehen alle drei Aufgaben zu demonstrieren.
|
||||
|
||||
---
|
||||
|
||||
Im heutigen Labor sollen Sie die folgende drei Aufgabengebiete bearbeiten.
|
||||
|
||||
### A. Namensräume zur Abgrenzung von Symbolen
|
||||
|
||||
### B. Zweidimensionale Felder lesen und schreiben (`std::vector<std::vector>`)
|
||||
|
||||
### C. Einbindung von lokalen Biblotheken
|
||||
|
||||
---
|
||||
|
||||
Details zu den Aufgaben finden Sie in [`main.ipynb`](main.ipynb).
|
||||
@@ -0,0 +1 @@
|
||||
-Imodules
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## A. Namensräume\n",
|
||||
"\n",
|
||||
"Namensräume (`namespace` s) sind eine Möglichkeit, um Quellcode besser zu organisieren und strukturieren: Namenskonflikte zwischen gleichnamigen Funktionen (wie es beim importieren mehrerer Bibliotheken auftreten kann) können vermieden werden.\n",
|
||||
"\n",
|
||||
"**Aufgabe 1:** Setzen Sie die folgenden Schritte in der Datei `taskA.cpp` um:\n",
|
||||
"\n",
|
||||
"1. Definieren Sie in einem Namensraum eine Funktion, die einen beliebigen Text (z.B. 'Hello from namespace XXX') in der Konsole ausgibt.\n",
|
||||
"2. Definieren Sie in einem anderen Namensraum eine zweite Funktion mit gleichem Namen, die einen anderen Text (z.B. 'Hello from namespace YYY') in der Konsole ausgibt\n",
|
||||
"3. Schreiben Sie eine `main`-Funktion, in der Sie beide Funktionen aufrufen.\n",
|
||||
"\n",
|
||||
"**Aufgabe 2:**\n",
|
||||
"\n",
|
||||
"Diskutieren Sie Vor- und Nachteile der folgenden drei Header-Dateien: Typen und Werte werden aus der Standardbibliothek inkludiert und für die Schnittstellen (Funktionsdeklarationen) verwendet:\n",
|
||||
"\n",
|
||||
"```cpp\n",
|
||||
"// Option1.hpp \n",
|
||||
"#include <numbers>\n",
|
||||
"#include <vector>\n",
|
||||
"\n",
|
||||
"using namespace std;\n",
|
||||
"using namespace std::numbers;\n",
|
||||
"\n",
|
||||
"vector<double> doSomething(vector<double> data, double ref = pi);\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"```cpp\n",
|
||||
"// Option2.hpp\n",
|
||||
"#include <numbers>\n",
|
||||
"#include <vector>\n",
|
||||
"\n",
|
||||
"std::vector<double> doSomething(std::vector<double> data, double ref = std::numbers::pi);\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"---\n",
|
||||
"\n",
|
||||
"```cpp\n",
|
||||
"// Option3.hpp\t\n",
|
||||
"#include <numbers>\n",
|
||||
"#include <vector>\n",
|
||||
"\n",
|
||||
"constexpr double Pi = std::numbers::pi;\n",
|
||||
"using Vector = std::vector<double>;\n",
|
||||
"\n",
|
||||
"Vector doSomething(Vector data, double ref = Pi);\t\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Demonstration:** Führen Sie Ihr Programm aus Teil 1 aus und fassen Sie Ihre Diskussion zu Teil 2 kurz zusammen."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## B. std::vector und Funktionen mit Schleifen und Bedingungen\n",
|
||||
"\n",
|
||||
"In der Datei `taskB.cpp` sind ein Vektor `vec` und eine Matrix (*vector of vectors*) `mat` gegeben:\n",
|
||||
"\n",
|
||||
"```cpp\n",
|
||||
"using Vector = std::vector<double>;\n",
|
||||
"using Matrix = std::vector<std::vector<int>>;\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"**Aufgabe:** Implementieren Sie die folgenden Funktionen:\n",
|
||||
"\n",
|
||||
" 1. `sum`: **Summe** aller Elemente eines `Vector`\n",
|
||||
" 2. `sum`: **Summe** aller Elemente einer `Matrix`\n",
|
||||
" 3. `print`: **Formatierte Ausgabe** (in der Konsole) eines `Vectors` (in einer Zeile) \n",
|
||||
" 3. `print`: **Formatierte Ausgabe** (in der Konsole) einer `Matrix` (Zeile für Zeile) \n",
|
||||
" 4. `cout_even`: **Abzählen** wie viele Elemente einer `Matrix` gerade sind\n",
|
||||
" 5. `mean`: **Durchschnitt aller Elemente** einer `Matrix`\n",
|
||||
"\n",
|
||||
"**Überlegen Sie sich,**\n",
|
||||
"- welche Typen die Parameter Ihrer Funktionen benötigen, und\n",
|
||||
"- ob Ihre Funktionen einen Rückgabewert liefern, und welchen Typ dieser haben soll.\n",
|
||||
"\n",
|
||||
"Rufen Sie Ihre Funktionen in der `main`-Funktion auf, und geben Sie jeweils deren Rückgabewert in der Konsole aus.\n",
|
||||
"\n",
|
||||
"**Demonstration:** Führen Sie Ihr Programm aus und interpretieren Sie die Ausgaben in der Konsole."
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## C. Nutzung der in `modules` bereitgestellten Bibliotheken\n",
|
||||
"\n",
|
||||
"Wir stellen Ihnen in diesem Semester im Repo [`modules`](https://sgit.iue.tuwien.ac.at/360050/modules) Funktionalität zur Verfügung, von der Sie in einigen der folgenden Hausübungen Gebrauch machen sollen. \n",
|
||||
"\n",
|
||||
"**Aufgabe:** Setzen Sie die folgenden Schritte in der Datei `taskC.cpp` um:\n",
|
||||
"\n",
|
||||
"- Schreiben Sie eine Funktion, die eine $m \\times n$-Matrix (*vector of vectors*) zurückgibt. Die Anzahl der Zeilen und Spalten soll als Funktionsparameter übergeben werden. Die Matrix soll mit aufsteigenden Werten vom Typ `double` gefüllt werden, wobei mit dem Wert `1.0` gestartet und dann reihenweise vorgegangen wird.\n",
|
||||
"\n",
|
||||
"- Schreiben Sie eine `main`-Funktion, rufen Sie von dort Ihre Funktion auf und speichern Sie deren Rückgabewert (Matrix) in einer lokalen Variable.\n",
|
||||
"\n",
|
||||
"- Rufen Sie die Funktion `iue::io::savetxt()`, die in [`modules/iue-io/csv.hpp`](modules/iue-io/csv.hpp) definiert ist, auf, um die Matrix in eine `.csv`-Datei zu schreiben.\n",
|
||||
"\n",
|
||||
"**Hinweise:**\n",
|
||||
"\n",
|
||||
"- Ein Beispiel für eine Matrix mit 4 Zeilen und 2 Spalten wäre:\n",
|
||||
"\n",
|
||||
" ```\n",
|
||||
" 1 2\n",
|
||||
" 3 4\n",
|
||||
" 5 6\n",
|
||||
" 7 8\n",
|
||||
" ```\n",
|
||||
"\n",
|
||||
"- Die Funktion `iue::io::savetxt(...)` befindet sich im *namespace* `iue::io` in der Datei [`modules/iue-io/csv.hpp`](modules/iue-io/csv.hpp).\n",
|
||||
"- Sie müssen die Header-Datei am Anfang Ihres Programms inkludieren (relativer Pfad), und wir empfehlen dazu folgende Vorgehensweise:\n",
|
||||
"\n",
|
||||
" ```cpp\n",
|
||||
" #include \"iue-io/csv.hpp\"\n",
|
||||
" ```\n",
|
||||
"\n",
|
||||
" und zudem den `modules`-Ordner als Include-Pfad (`-I`) beim Kompilieren angeben:\n",
|
||||
"\n",
|
||||
" ```shell\n",
|
||||
" g++ -std=c++20 -Imodules ...\n",
|
||||
" ```\n",
|
||||
"\n",
|
||||
"**Demonstration:** \n",
|
||||
" \n",
|
||||
"- Rufen Sie Ihr Programm auf und inspizieren Sie die resultierende `.csv`-Datei. \n",
|
||||
"- Ändern Sie die Anzahl an Zeilen oder Spalten, kompilieren Sie Ihr Programm erneut und erzeugen Sie eine weitere `.csv`-Datei."
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"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.9"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Created by e12302343 on 3/20/24.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
int mul(int a, int b, int c) {
|
||||
return a*b*c;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << mul(1,2,3) << std::endl;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/// @file
|
||||
/// @brief task A
|
||||
/// g++ -std=c++20 taskA.cpp -o taskA && ./taskA
|
||||
|
||||
#include <iostream>
|
||||
|
||||
/// @todo create a namespace with one function in it
|
||||
namespace taskA {
|
||||
void print() {
|
||||
std::cout << "Hello from taskA" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/// @todo create a second namespace with one function in it, use the same function name as above
|
||||
namespace taskB {
|
||||
void print() {
|
||||
std::cout << "Hello from taskB" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/// @todo write a main-function and call the two functions you defined above
|
||||
int main() {
|
||||
taskA::print();
|
||||
taskB::print();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/// @file
|
||||
/// @brief task B
|
||||
/// g++ -std=c++20 taskB.cpp -o taskB && ./taskB
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
/// @todo implement your functions here, details see main.ipynb
|
||||
/// @todo " 1. `sum`: **Summe** aller Elemente eines `Vector'",
|
||||
int sum(std::vector<double> vector) {
|
||||
double sum = 0;
|
||||
for (auto i : vector) {
|
||||
sum += i;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/// @todo " 2. `sum`: **Summe** aller Elemente einer `Matrix`",
|
||||
int sum(std::vector<std::vector<int>> matrix) {
|
||||
int sum = 0;
|
||||
for (auto row : matrix) {
|
||||
for (auto i : row) {
|
||||
sum += i;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
/// @todo " 3. `print`: **Formatierte Ausgabe** (in der Konsole) eines `Vectors` (in einer Zeile)",
|
||||
void printVector(std::vector<double> vector) {
|
||||
for (auto i : vector) {
|
||||
std::cout << i << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/// @todo " 3. `print`: **Formatierte Ausgabe** (in der Konsole) einer `Matrix` (Zeile für Zeile)",
|
||||
void printMatrix(std::vector<std::vector<int>> matrix) {
|
||||
for (auto row : matrix) {
|
||||
for (auto i : row) {
|
||||
std::cout << i << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/// @todo " 4. `cout_even`: **Abzählen** wie viele Elemente einer `Matrix` gerade sind",
|
||||
int countEven(std::vector<std::vector<int>> matrix) {
|
||||
int count = 0;
|
||||
for (auto row : matrix) {
|
||||
for (auto i : row) {
|
||||
if (i % 2 == 0) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/// @todo " 5. `mean`: **Durchschnitt aller Elemente** einer `Matrix`",
|
||||
float meanMatrix(std::vector<std::vector<int>> matrix) {
|
||||
int sum = 0;
|
||||
int count = 0;
|
||||
for (auto row : matrix) {
|
||||
for (auto i : row) {
|
||||
sum += i;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return (float)sum / count;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
// one-dimensional sequence (vector) with 5 values
|
||||
std::vector<double> vec{1.2, 2.5, 3., 4.1, 5.9};
|
||||
|
||||
// two-dimensional sequence, here we call it a matrix, with 3 rows with 4 values in each row
|
||||
std::vector<std::vector<int>> mat{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
|
||||
|
||||
/// @todo call your functions using 'vec' or 'mat' as arguments and print the results
|
||||
|
||||
std::cout << "Sum of vector: " << sum(vec) << std::endl;
|
||||
std::cout << "Sum of matrix: " << sum(mat) << std::endl;
|
||||
std::cout << "Print vector: ";
|
||||
printVector(vec);
|
||||
std::cout << "Print matrix: ";
|
||||
printMatrix(mat);
|
||||
std::cout << "Count even: " << countEven(mat) << std::endl;
|
||||
std::cout << "Mean of matrix: " << meanMatrix(mat) << std::endl;
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/// @file
|
||||
/// @brief task C
|
||||
/// g++ -std=c++20 -Imodules taskC.cpp -o taskC && ./taskC
|
||||
|
||||
/// @todo include modules library header for using iue::io::savetxt
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
/// @todo write a function initalizing a 'vector of vectors' with an integer sequence, details see main.ipynb
|
||||
std::vector<std::vector<double>> initMatrix(int m, int n) {
|
||||
std::vector<std::vector<double>> matrix;
|
||||
double value = 1.0;
|
||||
for (int i = 0; i < m; i++) {
|
||||
std::vector<double> row;
|
||||
for (int j = 0; j < n; j++) {
|
||||
row.push_back(value);
|
||||
value++;
|
||||
}
|
||||
matrix.push_back(row);
|
||||
}
|
||||
return matrix;
|
||||
}
|
||||
|
||||
/// @todo write a function to write a 'vector of vectors' to a csv-file, details see main.ipynb
|
||||
void writeMatrix(std::vector<std::vector<double>> matrix, std::string filename) {
|
||||
std::ofstream file(filename);
|
||||
for (auto row : matrix) {
|
||||
for (auto i : row) {
|
||||
file << i << ",";
|
||||
}
|
||||
file << std::endl;
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
/// @todo write a main-function and use your function to
|
||||
/// - init a 'vector of vectors' to initialize a table and
|
||||
/// - write the table to a csv-file using iue::io::savetxt
|
||||
int main() {
|
||||
std::vector<std::vector<double>> matrix = initMatrix(3, 4);
|
||||
writeMatrix(matrix, "matrix.csv");
|
||||
}
|
||||
Reference in New Issue
Block a user