TU-Programmieren_2/exercise2/main.ipynb
2025-04-09 10:22:44 +02:00

193 lines
5.7 KiB
Plaintext

{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cheatsheets\n",
"\n",
"- [exercise1](https://sgit.iue.tuwien.ac.at/360050/cheatsheet/raw/branch/master/exercise1.pdf)\n",
"- [exercise2](https://sgit.iue.tuwien.ac.at/360050/cheatsheet/raw/branch/master/exercise2.pdf)\n",
"\n",
"## Aufgabe 1: Ein eigenes kleines C++-Programm (*vector in/ scalar out*) (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 <...>\n",
"\t```\n",
"- Definition/Implementierung einer eigenen Funktion, z.B.:\n",
"\t```cpp\n",
"\tint func(...){\n",
"\t ...\n",
"\t}\n",
"\t``` \n",
"- Definition/Implementierung einer `main`-Funktion (Einstiegspunkt für jedes lauffähige Programm), die Ihre selbst 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 = func(...)\t\n",
"\t std::cout << res << std::endl;\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: Funktion mit Sequenzen von Werten als Parameter (`std::vector`), internen Verzweigungen (`if`/`else`), und mehreren Rückgabewerten (`std::tuple`) (1 Punkt)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Implementieren Sie die folgenden Funktionen:\n",
"\n",
"```cpp\n",
"// type aliases\n",
"using Vector = std::vector<double>;\n",
"using Tuple2 = std::tuple<double,double>;\n",
"\n",
"int count_gt(Vector data, double ref);\n",
"int count_lt(Vector data, double ref);\n",
"\n",
"Vector select_gt(Vector data, double ref);\n",
"Vector select_lt(Vector data, double ref);\n",
"Vector select_gt_and_lt(Vector data, double lower, double upper);\n",
"\n",
"double mean(Vector data);\n",
"double median(Vector data);\n",
"\n",
"Tuple2 minmax(Vector data);\n",
"```"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"- Die vorgegebenen Deklarationen und eine genaue Beschreibung und Anforderungen finden Sie in [`task2.hpp`](task2.hpp)\n",
"- Ihre Implementierung erfolgt in [`task2.cpp`](task2.cpp)\n",
"- Die zugeordneten Tests finden Sie in [`task2.test.cpp`](task2.test.cpp)\n"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Aufgabe 3: Kapselung einer Berechnung mittels einer Funktion mit mehreren Rückgabewerten (1 Punkt)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Sie kapseln die Berechnung der Lösungen zu einer quadratischen Gleichung $ax^2 + bx + c = 0$ in einer Funktion.\n",
"\n",
"\n",
"Implementieren Sie folgenden beiden Funktionen (überladener Funktionsname):\n",
"\n",
"```cpp\n",
"std::tuple<double, double> solve_quadratic_equation(double a, double b, double c);\n",
"std::tuple<double, double> solve_quadratic_equation(std::tuple<double, double, double> abc);\n",
"```"
]
},
{
"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 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/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.exe\n",
"g++ -g -std=c++20 task2.cpp task2.test.cpp -o build/task2.exe\n",
"g++ -g -std=c++20 task3.cpp task3.test.cpp -o build/task3.exe\n",
"# run tests \n",
"./build/task1.exe\n",
"./build/task2.exe\n",
"./build/task3.exe\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",
"# run tests \n",
"ctest --test-dir build -C Debug -R task1\n",
"ctest --test-dir build -C Debug -R task2\n",
"ctest --test-dir build -C Debug -R task3\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
}