{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Aufgabe 1: Ein eigenes kleines C-Programm (*array as function parameter*) (1 Punkt)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Erstellen Sie in [`task1.main.c`](task1.main.c) ein lauffähiges Ein-Dateien-Programm das folgende Struktur aufweist:\n", "\n", "- Einbinden benötigter Header-Dateien aus der Standardbibliothek, z.B.:\n", "\t```c\n", "\t#include // bool, true, false\n", "\t#include // printf\n", "\t...\n", "\t```\n", "- Definition/Implementierung einer eigenen Funktion, z.B.:\n", "\t```cpp\n", "\tint task1_func(...) {\n", "\t ...\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", "\t ...\t\n", "\t int res = task1_func(...);\n", "\t ...\t\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.c`](task1.main.c)\n", "- Ihre Implementierung erfolgt ebenfalls in [`task1.main.c`](task1.main.c)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Aufgabe 2: Reimplementierung von C++ Funktionalität in C (1 Punkt)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Sie reimplementieren die Funktionalität zweier Klassen, die Sie schon in Hausübung 4 (C++) implementiert:\n", "\n", "- [`exercise4::task2::BBox`](https://sgit.iue.tuwien.ac.at/360050/exercise4/src/commit/2e408ac941971e07971485282ef086d22cb0d974/task2.hpp#L13) \n", "- [`exercise4::task2::Circle`](https://sgit.iue.tuwien.ac.at/360050/exercise4/src/commit/2e408ac941971e07971485282ef086d22cb0d974/task2.hpp#L35)\n", "\n", "Diesmal verwenden Sie die Sprache C:\n", "\n", "- Statt Memberfunktionen kommen freie Funktionen zum Einsatz\n", "- Funktionsüberladungen werden durch Postfixe/Präfixe bei den Funktionsnamen realisiert\n", "- Typen aus der C++ Standardbibliothek (hier z.B. `std::array` ) werden durch eigene Typen ersetzt\n", "- Funktionalität aus der C++ Standardbibliothek (z.B. `std::cout`) wird mit entsprechender Funktionalität aus der C Standardbibliothek ( `printf` ) ersetzt." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "- Die vorgegebenen Strukturen/Funktionen und eine genaue Beschreibung und Anforderungen finden Sie in [`task2.h`](task2.h)\n", "- Ihre Implementierung erfolgt in [`task2.c`](task2.c)\n", "- Die zugeordneten Tests finden Sie in [`task2.test.c`](task2.test.c) " ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Aufgabe 3: Übergabe von Feldern von Strukturen an Funktionen (1 Punkt)\n", "\n", "Sie implementieren zwei Funktionen an die ein Feld von Strukturen (aus Aufgabe 2) übergeben wird:" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": { "vscode": { "languageId": "c" } }, "source": [ "```c\n", "// todo: implement\n", "unsigned int task3_count_inside(const struct BBox* box, const struct Circle circles[], unsigned int size);\n", "\n", "// todo: implement\n", "struct BBox task3_common_bbox(const struct Circle circles[], unsigned int size);\n", "```" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "- Die vorgegebenen Deklaration und eine genaue Beschreibung und Anforderungen finden Sie in [`task3.h`](task3.h)\n", "- Ihre Implementierung erfolgt ebenfalls in [`task3.c`](task3.c)\n", "- Die zugeordneten Tests finden Sie in [`task3.test.c`](task3.test.c)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Kompilieren/Testen\n", "\n", "So testen Sie Ihre Implementierung (direkter Aufruf von `gcc`):\n", "\n", "```shell\n", "# prepare\n", "mkdir build\n", "# compile\n", "gcc -g -std=c11 task1.main.c -o build/task1 -lm\n", "gcc -g -Imodules -std=c11 task2.c task2.test.c -o build/task2 -lm\n", "gcc -g -Imodules -std=c11 task2.c task3.c task3.test.c -o build/task3 -lm\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 }