{"id":966,"date":"2019-06-16T21:40:23","date_gmt":"2019-06-17T02:40:23","guid":{"rendered":"http:\/\/dragonlordwarlock.com\/blog\/?p=966"},"modified":"2019-06-16T21:52:47","modified_gmt":"2019-06-17T02:52:47","slug":"c-hello-world-using-oop","status":"publish","type":"post","link":"https:\/\/dragonlordwarlock.com\/blog\/?p=966","title":{"rendered":"C++ Hello World using OOP"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\"><div style=\"background: white; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><table><tr><td><pre style=\"background: antiquewhite; margin: 0; line-height: 125%\"> 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69<\/pre><\/td><td><pre style=\"background: antiquewhite; margin: 0; line-height: 125%\"><span style=\"color: #557799\">#include &lt;iostream&gt;<\/span>\n<span style=\"color: #557799\">#include &lt;iomanip&gt;<\/span>\n<span style=\"color: #557799\">#include &lt;sstream&gt;<\/span>\n\n<span style=\"color: #008800; font-weight: bold\">using<\/span> <span style=\"color: #008800; font-weight: bold\">namespace<\/span> std;\n\n<span style=\"color: #008800; font-weight: bold\">class<\/span> <span style=\"color: #BB0066; font-weight: bold\">hello<\/span>\n{\n\t<span style=\"color: #333399; font-weight: bold\">unsigned<\/span> <span style=\"color: #333399; font-weight: bold\">int<\/span> limit;\n\texec();\n\texec(<span style=\"color: #333399; font-weight: bold\">int<\/span> i);\n\tstring greet;\n<span style=\"color: #997700; font-weight: bold\">public:<\/span>\n\thello();\n\t<span style=\"color: #008800; font-weight: bold\">operator<\/span><span style=\"color: #333333\">=<\/span>(<span style=\"color: #333399; font-weight: bold\">unsigned<\/span> <span style=\"color: #333399; font-weight: bold\">int<\/span> i);\n\trun();\n\trun(<span style=\"color: #333399; font-weight: bold\">int<\/span> i);\n};\n\nhello<span style=\"color: #333333\">::<\/span>exec()\n{\n\tcout <span style=\"color: #333333\">&lt;&lt;<\/span> greet <span style=\"color: #333333\">&lt;&lt;<\/span> endl;\n}\n\nhello<span style=\"color: #333333\">::<\/span>exec(<span style=\"color: #333399; font-weight: bold\">int<\/span> i)\n{\n\tcout <span style=\"color: #333333\">&lt;&lt;<\/span> <span style=\"background-color: #fff0f0\">&quot;[&quot;<\/span> <span style=\"color: #333333\">&lt;&lt;<\/span> setfill(<span style=\"color: #0044DD\">&#39;0&#39;<\/span>) <span style=\"color: #333333\">&lt;&lt;<\/span> setw(<span style=\"color: #0000DD; font-weight: bold\">4<\/span>) <span style=\"color: #333333\">&lt;&lt;<\/span> i <span style=\"color: #333333\">&lt;&lt;<\/span> <span style=\"background-color: #fff0f0\">&quot;] &quot;<\/span>;\n\texec();\n}\n\nhello<span style=\"color: #333333\">::<\/span>hello()\n{\n\tlimit<span style=\"color: #333333\">=<\/span><span style=\"color: #0000DD; font-weight: bold\">10<\/span>;\n\tgreet <span style=\"color: #333333\">=<\/span> <span style=\"background-color: #fff0f0\">&quot;Hello World.&quot;<\/span>;\n}\n\nhello<span style=\"color: #333333\">::<\/span><span style=\"color: #008800; font-weight: bold\">operator<\/span><span style=\"color: #333333\">=<\/span>(<span style=\"color: #333399; font-weight: bold\">unsigned<\/span> <span style=\"color: #333399; font-weight: bold\">int<\/span> i)\n{\n\t<span style=\"color: #008800; font-weight: bold\">if<\/span>(i<span style=\"color: #333333\">&gt;<\/span><span style=\"color: #0000DD; font-weight: bold\">0<\/span>) limit<span style=\"color: #333333\">=<\/span>i;\n}\n\nhello<span style=\"color: #333333\">::<\/span>run()\n{\n\trun(<span style=\"color: #0000DD; font-weight: bold\">1<\/span>);\n}\n\nhello<span style=\"color: #333333\">::<\/span>run(<span style=\"color: #333399; font-weight: bold\">int<\/span> i)\n{\n\t<span style=\"color: #008800; font-weight: bold\">if<\/span>(i<span style=\"color: #333333\">&lt;=<\/span>limit)\n\t{\n\t\texec(i);\n\t\ti<span style=\"color: #333333\">++<\/span>;\n\t\trun(i);\n\t}\n}\n\n<span style=\"color: #333399; font-weight: bold\">int<\/span> main(<span style=\"color: #333399; font-weight: bold\">int<\/span> argc, <span style=\"color: #333399; font-weight: bold\">char<\/span> <span style=\"color: #333333\">*<\/span>argv[])\n{\n\thello world;\n\t<span style=\"color: #008800; font-weight: bold\">if<\/span>(argc<span style=\"color: #333333\">&gt;<\/span><span style=\"color: #0000DD; font-weight: bold\">1<\/span>)\n\t{\n\t\tstringstream ss(argv[<span style=\"color: #0000DD; font-weight: bold\">1<\/span>]);\n\t\t<span style=\"color: #333399; font-weight: bold\">int<\/span> i;\n\t\tss <span style=\"color: #333333\">&gt;&gt;<\/span> i;\n\t\tworld <span style=\"color: #333333\">=<\/span> i;\n\t}\n\tworld.run();\n\t<span style=\"color: #008800; font-weight: bold\">return<\/span> <span style=\"color: #0000DD; font-weight: bold\">0<\/span>;\n}\n<\/pre><\/td><\/tr><\/table><\/div>\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This Hello World program, illustrates a number of object oriented programming features of C++; including use of classes, method and operator overloading and recursive functions. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 &#8230; <a href=\"https:\/\/dragonlordwarlock.com\/blog\/?p=966\" class=\"more-link\">Read More<span class=\"screen-reader-text\"> &#8220;C++ Hello World using OOP&#8221;<\/span> &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[29,30,33,32],"tags":[],"class_list":["post-966","post","type-post","status-publish","format-standard","hentry","category-c","category-hello-world","category-object-oriented-programming","category-programming"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/dragonlordwarlock.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dragonlordwarlock.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dragonlordwarlock.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dragonlordwarlock.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dragonlordwarlock.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=966"}],"version-history":[{"count":8,"href":"https:\/\/dragonlordwarlock.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/966\/revisions"}],"predecessor-version":[{"id":974,"href":"https:\/\/dragonlordwarlock.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/966\/revisions\/974"}],"wp:attachment":[{"href":"https:\/\/dragonlordwarlock.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dragonlordwarlock.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dragonlordwarlock.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}