Skip to content
Snippets Groups Projects
Commit 74d19301 authored by Hendrik Haidmann's avatar Hendrik Haidmann :space_invader:
Browse files

feat: aufgabe10

parent 61e6108e
No related branches found
No related tags found
No related merge requests found
# CMakeList.txt: CMake-Projekt für "aufgabe10". Schließen Sie die Quelle ein, und definieren Sie
# projektspezifische Logik hier.
#
cmake_minimum_required (VERSION 3.8)
# Aktivieren Sie Hot Reload für MSVC-Compiler, sofern unterstützt.
if (POLICY CMP0141)
cmake_policy(SET CMP0141 NEW)
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()
project ("aufgabe10")
# Fügen Sie der ausführbaren Datei dieses Projekts eine Quelle hinzu.
add_executable (aufgabe10 "aufgabe10.cpp" "aufgabe10.h")
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET aufgabe10 PROPERTY CXX_STANDARD 20)
endif()
# TODO: Fügen Sie bei Bedarf Tests hinzu, und installieren Sie Ziele.
{
"version": 3,
"configurePresets": [
{
"name": "windows-base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
},
{
"name": "x64-debug",
"displayName": "x64 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x64-release",
"displayName": "x64 Release",
"inherits": "x64-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "x86-debug",
"displayName": "x86 Debug",
"inherits": "windows-base",
"architecture": {
"value": "x86",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "x86-release",
"displayName": "x86 Release",
"inherits": "x86-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "linux-debug",
"displayName": "Linux Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
},
{
"name": "macos-debug",
"displayName": "macOS Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
},
"vendor": {
"microsoft.com/VisualStudioRemoteSettings/CMake/1.0": {
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
}
}
}
]
}
#include "aufgabe10.h"
using namespace std;
int main()
{
const int managedArraySize = 3;
int managedArray[managedArraySize];
int currentIndex = 0;
char subProgramChoice = 'x';
for (int i = 0; i < managedArraySize; i++)
{
managedArray[i] = -1;
}
while (subProgramChoice != 'q')
{
cout << endl << "Sie verwalten ein statisches C-Array mit " << managedArraySize << " Elementen." << endl << "Das sind Ihre Optionen:" << endl;
cout << "[i]nput: Neuen Wert eingeben und hinten anfuegen" << endl;
cout << "[s]ize: Anzahl belegter Felder ausgeben" << endl;
cout << "[o]utput: Alle belegten Felder ausgeben" << endl;
cout << "[d]elete: Erstes Element entfernen" << endl;
cout << "[q]uit: Programm beenden" << endl;
cin >> subProgramChoice;
subProgramChoice = tolower(subProgramChoice);
switch (subProgramChoice)
{
case 'i':
if (!(currentIndex >= managedArraySize))
{
cout << "Geben Sie nun einen neuen Wert ein:" << endl;
cin >> managedArray[currentIndex];
currentIndex++;
}
else
{
cerr << "ERROR: Alle Felder des Arrays sind bereits belegt!" << endl;
}
break;
case 's':
cout << "Anzahl derzeit belegter Felder: " << currentIndex << endl;
break;
case 'o':
if (currentIndex != 0)
{
cout << "Derzeit befinden sich folgende Werte in den Feldern:" << endl;
for (int i = 0; i < currentIndex; i++)
{
cout << managedArray[i] << ", ";
}
cout << endl;
}
else
{
cerr << "WARNING: Alle Felder des Arrays sind aktuell leer!" << endl;
}
break;
case 'd':
if (currentIndex != 0)
{
for (int i = 0; i < currentIndex-1; i++)
{
managedArray[i] = managedArray[i + 1];
}
currentIndex--;
cout << "Das erste Element wurde erfolgreich entfernt." << endl;
}
else
{
cerr << "ERROR: Alle Felder des Arrays sind aktuell leer!" << endl;
}
break;
case 'q':
cout << "Auf Wiedersehen!" << endl;
break;
default:
cerr << "ERROR: Die Eingabe entspricht keiner der Optionen." << endl << "Bitte versuchen Sie es erneut:" << endl;
break;
}
}
return 0;
}
// aufgabe10.h: Includedatei für Include-Standardsystemdateien
// oder projektspezifische Includedateien.
#pragma once
#include <iostream>
// TODO: Verweisen Sie hier auf zusätzliche Header, die Ihr Programm erfordert.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment