{"id":2720,"date":"2025-11-13T08:00:00","date_gmt":"2025-11-13T07:00:00","guid":{"rendered":"https:\/\/www.fuhselab.de\/?p=2720"},"modified":"2025-11-05T08:29:19","modified_gmt":"2025-11-05T07:29:19","slug":"c-und-arrays-und-container","status":"publish","type":"post","link":"https:\/\/www.fuhselab.de\/index.php\/2025\/11\/13\/c-und-arrays-und-container\/","title":{"rendered":"C++ und Arrays und Container"},"content":{"rendered":"\n<p><br>Das Thema Arrays und Container wird in diesem Artikel mit zwei Codes f\u00fcr den Mittelwert und das Maximum vorgestellt&#8230;<\/p>\n\n\n\n<!--more-->\n\n\n\n<p><strong>Das C++ Mittelwert Programm:<\/strong><\/p>\n\n\n\n<p>Der folgende C++ Code nimmt zehn Werte des Benutzers entgegen und ermittelt daraus den Mittelwert.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\nint main()\n{\ndouble werte&#91;10];\nint loop;\n\nfor(loop = 0; loop &lt; 10; ++loop)\n{\nstd::cout &lt;&lt; \" Geben Sie einen Wert ein: \";\nstd::cin >> werte&#91;loop];\n}\n\ndouble mittelwert = 0;\n\nfor(loop = 0; loop &lt; 10; ++loop)\n{\nmittelwert += werte&#91;loop];\n}\n\nstd::cout &lt;&lt; \"Mittelwert: \"\n&lt;&lt; mittelwert\/10.0\n&lt;&lt; std::endl;\n\nreturn 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>Das C++ Maximum Programm:<\/strong><\/p>\n\n\n\n<p>Das erste C++ Maximum Programm nimmt solange Werte des Benutzers entgegen bis eine negative Zahl eingegeben wird und ermittelt dann das Maximum der eingegebenen Zahlen.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\n#include &lt;vector>\n\nint main()\n{\nstd::vector&lt;double> werte;\n\ndouble wert;\nwhile(true)\n{\nstd::cout &lt;&lt; \"Geben Sie einen Wert ein: \";\nstd::cin >> wert;\n\nif (wert &lt; 0)\nbreak;\nelse\nwerte.push_back(wert);\n}\n\ndouble maximum = 0;\n\nfor(std::vector&lt;double>::const_iterator p = werte.begin(); p != werte.end(); ++p)\n{\nif (*p >= maximum)\nmaximum = *p;\n}\n\nstd::cout &lt;&lt; \" Maximum: \" &lt;&lt; maximum &lt;&lt; std::endl;\nreturn 0;\n}\n<\/code><\/pre>\n\n\n\n<p><strong>Das C++ Maximum Programm Version 2:<\/strong><\/p>\n\n\n\n<p>Das zweite C++ Maximum Programm nimmt nur 10 Werte vom Benutzer entgegen und ermittelt daraus das Maximum.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream>\n#include &lt;vector>\n\nint main() {\nstd::vector&lt;double> werte;\ndouble wert;\ndouble maximum = 0.0; \n\nfor (int i = 0; i &lt; 10; ++i) { \nstd::cout &lt;&lt; \"Geben Sie einen Wert ein: \";\nstd::cin >> wert;\n\nif (wert >= maximum)\nmaximum = wert;\n\nwerte.push_back(wert);\n}\n\nfor (auto p = werte.cbegin(); p != werte.cend(); ++p) {\nif (*p >= maximum)\nmaximum = *p;\n}\n\nstd::cout &lt;&lt; \"Maximum: \" &lt;&lt; maximum &lt;&lt; std::endl;\nreturn 0;\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Das Thema Arrays und Container wird in diesem Artikel mit zwei Codes f\u00fcr den Mittelwert und das Maximum vorgestellt&#8230;<\/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-2720","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\/2720","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=2720"}],"version-history":[{"count":3,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/2720\/revisions"}],"predecessor-version":[{"id":2910,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/posts\/2720\/revisions\/2910"}],"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=2720"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/categories?post=2720"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fuhselab.de\/index.php\/wp-json\/wp\/v2\/tags?post=2720"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}