This commit is contained in:
2025-04-09 10:22:44 +02:00
commit 96ff5392c8
330 changed files with 28300 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
---
BasedOnStyle: LLVM
---
Language: Cpp
AllowShortFunctionsOnASingleLine: Empty
DerivePointerAlignment: false
PointerAlignment: Left
ColumnLimit: 120
TabWidth: 4
IndentWidth: 2
...
+23
View File
@@ -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]
+16
View File
@@ -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
View File
@@ -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
+4
View File
@@ -0,0 +1,4 @@
[submodule "modules"]
path = modules
url = https://sgit.iue.tuwien.ac.at/360050/modules
branch = main
+26
View File
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.20)
# define project metadata
project(lab2 LANGUAGES CXX
DESCRIPTION "lab2"
HOMEPAGE_URL "https://sgit.iue.tuwien.ac.at/360050/lab2")
# setting required language standards
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)
# misc settings
# 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)
# include own targets
add_executable(taskA taskA.cpp)
add_executable(taskB taskB.cpp)
add_executable(taskC taskC.cpp)
+25
View File
@@ -0,0 +1,25 @@
# Labor II: Abgabe (30min)
**Dieser Teil wird über [TUWEL, Labor II: Abgabe (30min)](https://tuwel.tuwien.ac.at/course/view.php?id=62042#coursecontentcollapse7)** abgewickelt.
# Labor II: 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. Debugging
### B. Klassen
### C. Überladen von Operatoren
---
Details zu den Aufgaben finden Sie in [`main.ipynb`](main.ipynb).
+1
View File
@@ -0,0 +1 @@
-Imodules
Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

+25
View File
@@ -0,0 +1,25 @@
//
// Created by maxi2 on 17.04.2024.
//
#include <iostream>
#include <vector>
bool checkIsSequence(std::vector<int> vec) {
if (vec.size() <= 2)
return false;
int fac = vec[1] / vec[0];
for (int i = 1; i < vec.size() - 1; ++i) {
if (vec[i] != (vec[i - 1] * fac))
return false;
}
return true;
}
int main() {
std::vector<int> vec = {1, 2, 4, 8, 16};
std::vector<int> vec2 = {5,25,125,625,3125};
std::cout << "Is sequence: " << checkIsSequence(vec) << std::endl;
std::cout << "Is sequence: " << checkIsSequence(vec2) << std::endl;
return 0;
}
+144
View File
@@ -0,0 +1,144 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## A. Debugging\n",
"\n",
"In der Datei [taskA.cpp](taskA.cpp) ist ein (fehlerfreies) Programm gegeben.\n",
"\n",
"### Debugging mittels Konsolenausgaben\n",
"\n",
"Die wohl einfachste Methode des Debuggings ist das hinzufügen von *print statements* (std::cout <<) die beim Ausführen Aufschluss über den Verlauf des Programms liefern. In [taskA.cpp](taskA.cpp) in der Funktion `doubleVec` sehen Sie beispielsweise wie diese aussehen könnten.\n",
"\n",
"**Aufgabe 1:** Fuegen Sie in der Funktion `findMax` aequivalente Debug-Ausgaben hinzu (am Anfang der Funktion, in der Schleife und am Ende der Funktion).\n",
"\n",
"**Demonstration 1:** Kompilieren Sie die Datei [taskA.cpp](taskA.cpp), führen Sie das Programm aus und inspizieren Sie die Konsolen Ausgabe. \n",
"\n",
"---\n",
"\n",
"### Debugging mittels Debugger\n",
"\n",
"Eine weitere Methode ist das Verwenden eines Debuggers. Dieser ermöglicht es Haltepunkte (*breakpoints*) zu setzen an denen das Programm angehalten wird und von denen aus man Zeile für Zeile durch das Programm gehen kann. \n",
"\n",
"**Einrichten CMake-basiertes Debuggen mit VSCode:**\n",
"\n",
"- Installieren Sie die `CMake tools`-Erweiterung für VSCode:\n",
"\n",
" ```bash\n",
" code --install-extension ms-vscode.cmake-tools\n",
" ```\n",
"\n",
"- Fügen Sie in der Datei, die Sie debuggen wollen *breakpoints* hinzu:\n",
"\n",
"<img src=\"images/01.jpg\" width=700>\n",
"\n",
"- Drücken Sie `F1` und geben Sie in der VSCode Suchleiste `CMake: Configure` ein:\n",
"\n",
"<img src=\"images/02.jpg\" width=700>\n",
"\n",
"- Wählen Sie im Menü den `GCC` Compiler aus. Eventuell wird dieser bereits automatisch ausgewählt.\n",
"\n",
"<img src=\"images/03.jpg\" width=700>\n",
"\n",
"- Drücken Sie `F1` und geben Sie in der VSCode Suchleiste `CMake: Set Debug Target` ein:\n",
"\n",
"<img src=\"images/04.jpg\" width=700>\n",
"\n",
"- Wählen Sie im Menü die Datei aus die Sie debuggen möchten:\n",
"\n",
"<img src=\"images/05.jpg\" width=700>\n",
"\n",
"- Drücken Sie wieder `F1` und geben Sie in der VSCode Suchleiste `CMake: Debug` ein:\n",
"\n",
"<img src=\"images/06.jpg\" width=700>\n",
"\n",
"**Hinweis:**\n",
" - Das Debuggen mit CMake ist nur möglich wenn eine entsprechend konfigurierte [CMakeLists.txt](CMakeLists.txt) im aktuellen Verzeichnis vorhanden ist.\n",
"\n",
"**Aufgabe 2:** Setzen Sie in der Datei [taskA.cpp](taskA.cpp) dort *breakpoints* wo sich die Debug-Ausgaben aus Aufgabe 1 befinden. Debuggen Sie Ihr Programm indem Sie entweder Zeile fuer Zeile oder von *breakpoint* zu *breakpoint* durch das Programm gehen.\n",
"\n",
"**Demonstration:** Debuggen Sie Ihr Programm und zeigen Sie, dass Sie mit der Debugger-Navigation umgehen koennen."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## B. Klassen\n",
"\n",
"In der Datei [taskB.cpp](taskB.cpp) sind zwei *namespaces* `one` und `two` gegeben. In `namespace one` ist eine Klasse `Particle` mit drei Member-Variablen (Geschwindigkeit in x- und y-Richtung und Masse), welche ein Partikel darstellen soll, gegeben.\n",
"\n",
"**Aufgabe (Details siehe [taskB.cpp](taskB.cpp)):**\n",
" - Erweitern Sie die Klasse `Particle` in `namespace one` um folgende Member-Funktionen: `energy()`, `print()`\n",
" - Erstellen Sie die Klasse `Particle` in `namespace two` mit folgenden Eigenschaften: \n",
" - Gleiche Member-Variablen wie die Klasse in `namespace one` diese sollen aber **privat** sein\n",
" - **Konstruktor** `Particle(...)` mit x- und y-Richtung und Masse als Parameter,\n",
" - **Member Funktionen**: `set()`, `get()`, `energy()`, `print()`\n",
" \n",
" - In der `main` Funktion:\n",
" - Erstellen Sie jeweils ein Objekt der beiden Klassen und rufen Sie alle Funktionen auf.\n",
"\n",
"**Hinweis:**\n",
" - Formel für die kinetische Energie: $E_{kin} = \\frac{1}{2} \\cdot m \\cdot (v_x^2 + v_y^2)$\n",
"\n",
"\n",
"**Demonstration:** Erklären Sie den Unterschied zwischen einem `struct` und einer Klasse (`class`). Was bedeutet `public` bzw. `private` in diesem Zusammenhang?"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## C. Überladen von Operatoren\n",
"\n",
"Sie sollen eine Klasse implementieren um Polynome der Form $p(x) = a_0x^0 + a_1x^1 + a_2x^2 + ...$ darzustellen.\\\n",
"Das Verwenden der Klasse könnte dann in etwa so aussehen:\n",
"\n",
"\n",
"```cpp\n",
"int main(){\n",
" auto poly = Polynom({4, 2, 3}); // this represents the polynomial p(x) = 4 + 2*x + 3*x**2 + ... \n",
" double x = 1.0;\n",
" double eval = poly(x); // using overloaded operator to evaluate polynomial at x = 1\n",
" std::cout << eval << std::endl;\n",
"}\n",
"```\n",
"\n",
"**Aufgabe (Details siehe [taskC.cpp](taskC.cpp)):**\n",
" - Erstellen Sie eine Klasse `Polynomial` mit folgenden Eigenschaften:\n",
" - Member-Variable vom Typ `std::vector`, die die Koeffizienten $a_i$ des Polynoms beinhaltet\n",
" - Ausgabefunktion `print()`\n",
" - Überladener Operator `operator()` zum Evaluieren des Polynoms.\n",
" - Erstellen Sie ein Objekt der Klasse `Polynomial`, rufen sie die `print()` Funktion auf und verwenden Sie den `()` Operator um das Polynom zu evaluieren.\n",
"\n",
"**Demonstration:** Erklaeren Sie Ihre Implementierung kurz. Nennen Sie moegliche Vor- und Nachteile die durch das Ueberladen von Operatoren entstehen."
]
}
],
"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.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
+29
View File
@@ -0,0 +1,29 @@
#include <iostream>
#include <vector>
#include <cmath>
std::vector<double> addSequenz(std::vector<double> a, std::vector<double> b){
int shortest = a.size();
std::vector<double> erg={};
if(a.size()>b.size()) {
shortest=b.size();
}
for (int i = 0 ; i < shortest ; i++){
double ad = a[i];
double bd = b[i];
erg.push_back(ad+bd);
}
return erg;
};
int main(){
std::vector<double> a = {5,10,20,30};
std::vector<double> b = {5,3,8};
//expect 10,13,28
std::vector<double> c = addSequenz(a,b);
std::cout << c[0] << ',' << c[1] << ',' << c[2] << std::endl;
return 1;
}
+62
View File
@@ -0,0 +1,62 @@
/// @file
/// @brief task A
/// compile/run: g++ -g -std=c++20 taskA.cpp -o taskA && ./taskA
/// @todo add debug statements in function findMax
/// @todo compile and run this file, inspect output
/// @todo runtime debug the program and add breakpoints
/// - at the beginning of each function
/// - inside the loops
/// - at the end of each function
#include <iostream>
#include <vector>
// prints a vector to the console
void print(const std::vector<int>& vec) {
std::cout << "[ ";
for (int i = 0; i < vec.size(); ++i) {
std::cout << vec[i] << " ";
}
std::cout << "]" << std::endl;
}
// takes an input vector and returns a vector where each element is doubled
std::vector<int> doubleVec(std::vector<int> vec) {
std::cout << "'doubleVec' input: ";
print(vec);
for (int i = 0; i < vec.size(); ++i) {
vec[i] *= 2;
std::cout << " loop(i=" << i << "): " << std::endl;
std::cout << " ";
print(vec);
}
std::cout << "'doubleVec' output: ";
print(vec);
return vec;
}
// returns the greatest element of a vector
int findMax(const std::vector<int>& vec) {
int max = vec[0];
for (int i = 1; i < vec.size(); ++i) {
std::cout << " loop(i=" << i << "): " << std::endl;
std::cout << " current: " << vec[i] << std::endl;
if (vec[i] > max) {
max = vec[i];
std::cout << " new max: " << max << std::endl;
}
}
return max;
}
int main() {
std::vector<int> vec = {3, 7, 12, 9, 15};
vec = doubleVec(vec);
int max = findMax(vec);
std::cout << "max: " << max << std::endl;
return 0;
}
+76
View File
@@ -0,0 +1,76 @@
/// @file
/// @brief task B
/// g++ -std=c++20 taskB.cpp -o taskB && ./taskB
#include <iostream>
namespace one {
struct Particle {
double vx; // velocity in x-direction
double vy; // velocity in y-direction
double m; // mass
/// @todo implement the following member functions:
/// - energy(): returns the kinetic energy of the particle (formula, see main.ipynb)
/// - print(): prints the values of the member variables to the console
double energy() {
return 0.5 * m * (vx * vx + vy * vy);
}
void print() {
std::cout << "vx: " << vx << ", vy: " << vy << ", m: " << m << std::endl;
}
};
} // end namespace one
namespace two {
/// @todo implement a class with the following properties:
/// - private member variables vx, vy, m
/// - constructor with three parameters (for the three member variables)
/// - set(): function to change the values of all three member variables
/// - get(): returns the values of the member variables in a tuple
/// - energy(): returns the kinetic energy of the particle (formula, see main.ipynb)
/// - print(): prints the values of the member variables to the console
class Particle {
double vx; // velocity in x-direction
double vy; // velocity in y-direction
double m; // mass
void set(double vx, double vy, double m) {
this->vx = vx;
this->vy = vy;
this->m = m;
}
std::tuple<double, double, double> get() {
return std::make_tuple(vx, vy, m);
}
double energy() {
return 0.5 * m * (vx * vx + vy * vy);
}
void print() {
std::cout << "vx: " << vx << ", vy: " << vy << ", m: " << m << std::endl;
}
};
} // end namespace two
int main() {
/// @todo create objects from both classes and use their member functions
one::Particle p1;
p1.vx = 1.0;
p1.vy = 2.0;
p1.m = 3.0;
p1.print();
std::cout << "energy: " << p1.energy() << std::endl;
return 0;
}
+44
View File
@@ -0,0 +1,44 @@
/// @file
/// @brief task C
/// g++ -std=c++20 taskC.cpp -o taskC && ./taskC
#include <iostream>
#include <valarray>
#include <vector>
/// @todo implement the class 'Polynomial' with the following properties:
/// - std::vector member variable to store the coefficients of the polynomial
/// - print(): prints the polynomial including the actual coefficients to the console
/// - overloaded '()' operator to evaluate polynomial at 'x'
class Polynomial {
public:
std::vector<double> coefficients;
void print() {
for (int i = 0; i < coefficients.size(); ++i) {
std::cout << coefficients[i] << "x^" << i;
if (i < coefficients.size() - 1) {
std::cout << " + ";
}
}
std::cout << std::endl;
}
double operator()(double x) {
double result = 0;
for (int i = 0; i < coefficients.size(); ++i) {
result += coefficients[i] * pow(x, i);
}
return result;
}
};
int main() {
/// @todo create an object from your class and use its member function and overloaded operator
Polynomial p;
p.coefficients = {1, 2, 3};
p.print();
std::cout << "p(2) = " << p(2) << std::endl;
return 0;
}