{"id":1805,"date":"2024-09-19T08:00:00","date_gmt":"2024-09-19T06:00:00","guid":{"rendered":"https:\/\/www.fuhselab.de\/?p=1805"},"modified":"2025-05-28T07:15:54","modified_gmt":"2025-05-28T05:15:54","slug":"coding-workshop-03","status":"publish","type":"post","link":"https:\/\/www.fuhselab.de\/index.php\/2024\/09\/19\/coding-workshop-03\/","title":{"rendered":"Coding Workshop 03"},"content":{"rendered":"\n<p><br>Der C++ Workshop geht in die dritte Runde und wirft einen kleinen Blick auf Variablen\u2026<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><strong>Dateneingabe und Datenausgabe:<\/strong><\/p>\n\n\n\n<p>Bereits unsere ersten Schritte in die Welt von C++ brachten uns das &#8222;Hallo Welt-Programm&#8220; und eine erste Variable die wir sogar dynamisch per Tastatureingabe gef\u00fcllt haben.<\/p>\n\n\n\n<p>Hier nochmal der Code f\u00fcr die Eingabe und Ausgabe:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1) #include &lt;iostream&gt;\n2) \n3) int main()\n4) {\n5) int Ganzzahl;\n6) std::cout &lt;&lt; \"Benutzereingabe: \";\n7) std::cin &gt;&gt; Ganzzahl;\n8) std::cout &lt;&lt; \"Sie haben \" &lt;&lt; Ganzzahl &lt;&lt; \" eingegeben.\";\n9) }<\/code><\/pre>\n\n\n\n<p>Der Grundaufbau von C++ erinnert stark an den Arduino-Code.<\/p>\n\n\n\n<p>In Zeile 1wird per include-Befehl die iostream-Bibliothek eingebunden.<\/p>\n\n\n\n<p>In Zeile 3 beginnt mit int main eine Integer-Funktion. Es ist die Hauptfunktion des Programms.<\/p>\n\n\n\n<p>In Zeile 5 wird dann die Variable &#8222;Ganzzahl&#8220; vom Typ Integer angelegt.<\/p>\n\n\n\n<p>In Zeile 6 beschreibt &#8222;std::cout&#8220; den Standardausgabe-Strom. Dabei wird der Text meist in einem Terminal angezeigt (wenn die Ausgabe nicht in eine Datei oder an ein anderes Programm umgeleitet wird). Die beiden Pfeile (&lt;&lt;) signalisieren, dass der dahinterstehende Text auf die Standardausgabe \u201egeschoben\u201c wird.<\/p>\n\n\n\n<p>In Zeile 7 wird \u00fcber die Funktion &#8222;cin&#8220; (C Input) dem Programm gesagt: Schiebe den Inhalt der Tastatureingabe in die Variable Ganzzahl.<\/p>\n\n\n\n<p>In Zeile 8 erfolgt dann wieder die Ausgabe mit C Output. Im Terminal wird also angezeigt welche Zahl ich eingegeben habe.<\/p>\n\n\n\n<p><strong>Kommentare in C++<\/strong><\/p>\n\n\n\n<p>Grundprinzip f\u00fcr Kommentare im Code ist identisch zu PHP und Arduino-Code. Der doppelte Schr\u00e4gstrich soll aber (zumindest in C++) die bessere Methode sein.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Ein Kommentar, der mit zwei Schr\u00e4gstrichen eingeleitet wird, geht bis zum Zeilenende.\n\n\/*\nEin Kommentar dieser Art kann\nsich \u00fcber mehrere Zeilen erstrecken...\n*\/<\/code><\/pre>\n\n\n\n<p><strong>Beispiel f\u00fcr String Variablen:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\n#include &lt;string&gt;\nint main()\n{\nstd::string myName;\nstd::cout &lt;&lt; \"Wie hei\u00dft Du?: \";\nstd::cin &gt;&gt; myName;\nstd::cout &lt;&lt; \"Dein Name lautet: \" &lt;&lt; myName\n&lt;&lt; std::endl;\n}<\/code><\/pre>\n\n\n\n<p><strong>Beispiel f\u00fcr Bolean Variablen:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\nint main()\n{\nbool isAdmin = true; \/\/ declare a boolean variable named \"isAdmin\" with initial value true\nstd::cout &lt;&lt; \"Ich bin ein Administrator: \" &lt;&lt; (isAdmin ? \"ja\" : \"nein\")\n&lt;&lt; std::endl;\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Der C++ Workshop geht in die dritte Runde und wirft einen kleinen Blick auf Variablen\u2026<\/p>\n","protected":false},"author":1,"featured_media":543,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[32],"class_list":["post-1805","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-coding-club","tag-coding-club-peine"],"_links":{"self":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/1805","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/comments?post=1805"}],"version-history":[{"count":2,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/1805\/revisions"}],"predecessor-version":[{"id":2844,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/1805\/revisions\/2844"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media\/543"}],"wp:attachment":[{"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/media?parent=1805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/categories?post=1805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/tags?post=1805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}