{"id":565,"date":"2012-02-29T13:57:01","date_gmt":"2012-02-29T13:57:01","guid":{"rendered":"http:\/\/www.websitedesignwebsitedevelopment.com\/?p=565"},"modified":"2014-03-19T09:14:04","modified_gmt":"2014-03-19T09:14:04","slug":"c-example-for-triangle-area-with-the-help-of-getter-setter-functions","status":"publish","type":"post","link":"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/","title":{"rendered":"C++ example for triangle area with the help of getter setter functions"},"content":{"rendered":"<p>#include &lt;cstdlib&gt;<br \/>\n#include &lt;iostream&gt;<\/p>\n<p>\/\/INCLUDING &lt;iomanip&gt; FOR setfill() function<br \/>\n#include &lt;iomanip&gt;<\/p>\n<p>using namespace std;<\/p>\n<p>\/\/We are required to write a class.<br \/>\n\/\/Which should have area, base and height private data members (real numbers).<br \/>\n\/\/We are declaring class Fortrianglearea<\/p>\n<p>class Fortrianglearea<br \/>\n{<\/p>\n<p>\/\/Private data members area, base and height of float type for fractions<br \/>\nprivate:<br \/>\nfloat area, base, height;<\/p>\n<p>\/\/Public section, default constructor methods declared<br \/>\npublic:<br \/>\nFortrianglearea();<\/p>\n<p>\/\/setter and getter functions to set base and height<br \/>\nvoid setBaseHeight(float,float);<br \/>\nvoid getBaseHeight();<\/p>\n<p>\/\/display method to display the results after calculation<br \/>\nvoid Display(int);<\/p>\n<p>void CalaulateArea();<\/p>\n<p>};<\/p>\n<p>\/\/User will input for 2nd object and input values would be set for the second object<br \/>\nvoid Fortrianglearea::setBaseHeight(float base, float height)<br \/>\n{<br \/>\nthis-&gt;base = base;<\/p>\n<p>this-&gt;height = height;<br \/>\n}<\/p>\n<p>void Fortrianglearea::getBaseHeight()<br \/>\n{<br \/>\ncout &lt;&lt; endl &lt;&lt; &#8220;User input requried for the second object&#8221; &lt;&lt; endl &lt;&lt; endl;<\/p>\n<p>cout &lt;&lt; &#8220;Value of Triangle Base: &#8220;;<br \/>\ncin &gt;&gt; base;<\/p>\n<p>cout &lt;&lt; &#8220;Value of Triangle Height: &#8220;;<br \/>\ncin &gt;&gt; height;<\/p>\n<p>cout\u00a0 &lt;&lt; endl &lt;&lt; endl;<br \/>\n}<\/p>\n<p>void Fortrianglearea::CalaulateArea()<br \/>\n{<br \/>\nthis-&gt;area = (this-&gt;base * this-&gt;height \/ 2);<br \/>\n}<\/p>\n<p>\/\/A default constructor which will initialize all data members<br \/>\n\/\/with values 2.5 and 2.5 for base and height<br \/>\nFortrianglearea::Fortrianglearea()<br \/>\n{<br \/>\nthis-&gt;base = 2.5;<\/p>\n<p>this-&gt;height = 2.5;<\/p>\n<p>}<\/p>\n<p>\/\/Display (public) method for displaying area after calculation<br \/>\nvoid Fortrianglearea::Display(int obj)<br \/>\n{<br \/>\ncout &lt;&lt; &#8220;Object&#8221;&lt;&lt; obj &lt;&lt;&#8220;&#8221; &lt;&lt; endl;<br \/>\ncout &lt;&lt; &#8220;Input :&#8221;;<br \/>\ncout &lt;&lt; setfill(&#8216;*&#8217;) &lt;&lt; setw(20);<br \/>\ncout &lt;&lt; &#8220;base &#8221; &lt;&lt; base &lt;&lt; &#8220;, Height &#8221; &lt;&lt; height &lt;&lt; endl;<br \/>\ncout &lt;&lt; &#8220;Area of Object &#8221; &lt;&lt; obj &lt;&lt; &#8220;: &#8220;;<\/p>\n<p>\/\/using setfill() setw() and setprecision() as instructed<br \/>\nif(obj==1)<br \/>\ncout &lt;&lt; setfill(&#8216;*&#8217;) &lt;&lt; setw(11) &lt;&lt; area &lt;&lt; endl;<br \/>\nelse<br \/>\ncout &lt;&lt; setfill(&#8216;*&#8217;) &lt;&lt; setw(11) &lt;&lt; setprecision(1) &lt;&lt; area &lt;&lt; endl;<\/p>\n<p>}<\/p>\n<p>int main(int argc, char *argv[])<br \/>\n{<br \/>\ncout &lt;&lt; &#8220;\\t Area of Triangle&#8221; &lt;&lt; endl;<br \/>\ncout &lt;&lt; &#8220;\\t &#8212;&#8212;&#8212;&#8212;&#8212;-&#8221; &lt;&lt; endl &lt;&lt; endl;<\/p>\n<p>\/\/Required objects of the same class<br \/>\nFortrianglearea obj1, obj2;<\/p>\n<p>\/\/Assigning values of base and height for the first object through setter function<br \/>\nobj1.setBaseHeight(2.5,2.5);<\/p>\n<p>\/\/Calculating area of triangle<br \/>\nobj1.CalaulateArea();<\/p>\n<p>\/\/telling the display function that this is object one, so text will be changed acoordingly<br \/>\nobj1.Display(1);<\/p>\n<p>\/\/object two is for user, so now calling getter function<br \/>\nobj2.getBaseHeight();<\/p>\n<p>\/\/Calculating area of triangle<br \/>\nobj2.CalaulateArea();<\/p>\n<p>\/\/telling the display function that this is object one, so text will be changed acoordingly<br \/>\n\/\/and setprecision will work here too<br \/>\nobj2.Display(2);<\/p>\n<p>system(&#8220;PAUSE&#8221;);<br \/>\nreturn EXIT_SUCCESS;<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include &lt;cstdlib&gt; #include &lt;iostream&gt; \/\/INCLUDING &lt;iomanip&gt; FOR setfill() function #include &lt;iomanip&gt; using namespace std; \/\/We are required to write a class. \/\/Which should have area, base and height private data members (real numbers). \/\/We are declaring class Fortrianglearea class Fortrianglearea { \/\/Private data members area, base and height of float type for fractions private: float [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[31],"tags":[],"class_list":["post-565","post","type-post","status-publish","format-standard","hentry","category-c"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>C++ example for triangle area with the help of getter setter functions<\/title>\n<meta name=\"description\" content=\"C++ example for triangle area with the help of getter setter functions\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++ example for triangle area with the help of getter setter functions\" \/>\n<meta property=\"og:description\" content=\"C++ example for triangle area with the help of getter setter functions\" \/>\n<meta property=\"og:url\" content=\"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"AndroidBubble Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pages\/Website-Design-Website-Development\/172363336135453\" \/>\n<meta property=\"article:published_time\" content=\"2012-02-29T13:57:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-03-19T09:14:04+00:00\" \/>\n<meta name=\"author\" content=\"Fahad\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Fahad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/\"},\"author\":{\"name\":\"Fahad\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\"},\"headline\":\"C++ example for triangle area with the help of getter setter functions\",\"datePublished\":\"2012-02-29T13:57:01+00:00\",\"dateModified\":\"2014-03-19T09:14:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/\"},\"wordCount\":453,\"articleSection\":[\"C++\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/\",\"url\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/\",\"name\":\"C++ example for triangle area with the help of getter setter functions\",\"isPartOf\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/#website\"},\"datePublished\":\"2012-02-29T13:57:01+00:00\",\"dateModified\":\"2014-03-19T09:14:04+00:00\",\"author\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\"},\"description\":\"C++ example for triangle area with the help of getter setter functions\",\"breadcrumb\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/androidbubble.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Website Development\",\"item\":\"https:\/\/androidbubble.com\/blog\/category\/website-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"C++\",\"item\":\"https:\/\/androidbubble.com\/blog\/category\/website-development\/c\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"C++ example for triangle area with the help of getter setter functions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#website\",\"url\":\"https:\/\/androidbubble.com\/blog\/\",\"name\":\"AndroidBubble Blog\",\"description\":\"Articles &amp; Posts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/androidbubble.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\",\"name\":\"Fahad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g\",\"caption\":\"Fahad\"},\"sameAs\":[\"http:\/\/www.androidbubbles.com\/\",\"https:\/\/x.com\/phpFlex\"],\"url\":\"https:\/\/androidbubble.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C++ example for triangle area with the help of getter setter functions","description":"C++ example for triangle area with the help of getter setter functions","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/","og_locale":"en_US","og_type":"article","og_title":"C++ example for triangle area with the help of getter setter functions","og_description":"C++ example for triangle area with the help of getter setter functions","og_url":"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/","og_site_name":"AndroidBubble Blog","article_publisher":"https:\/\/www.facebook.com\/pages\/Website-Design-Website-Development\/172363336135453","article_published_time":"2012-02-29T13:57:01+00:00","article_modified_time":"2014-03-19T09:14:04+00:00","author":"Fahad","twitter_misc":{"Written by":"Fahad","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/#article","isPartOf":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/"},"author":{"name":"Fahad","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7"},"headline":"C++ example for triangle area with the help of getter setter functions","datePublished":"2012-02-29T13:57:01+00:00","dateModified":"2014-03-19T09:14:04+00:00","mainEntityOfPage":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/"},"wordCount":453,"articleSection":["C++"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/","url":"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/","name":"C++ example for triangle area with the help of getter setter functions","isPartOf":{"@id":"https:\/\/androidbubble.com\/blog\/#website"},"datePublished":"2012-02-29T13:57:01+00:00","dateModified":"2014-03-19T09:14:04+00:00","author":{"@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7"},"description":"C++ example for triangle area with the help of getter setter functions","breadcrumb":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/c-example-for-triangle-area-with-the-help-of-getter-setter-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/androidbubble.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Website Development","item":"https:\/\/androidbubble.com\/blog\/category\/website-development\/"},{"@type":"ListItem","position":3,"name":"C++","item":"https:\/\/androidbubble.com\/blog\/category\/website-development\/c\/"},{"@type":"ListItem","position":4,"name":"C++ example for triangle area with the help of getter setter functions"}]},{"@type":"WebSite","@id":"https:\/\/androidbubble.com\/blog\/#website","url":"https:\/\/androidbubble.com\/blog\/","name":"AndroidBubble Blog","description":"Articles &amp; Posts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/androidbubble.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7","name":"Fahad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/afab5bcad71955d142a69df1758e6710aed4ab9cc2b5da28c54a7c3f39801b73?s=96&d=mm&r=g","caption":"Fahad"},"sameAs":["http:\/\/www.androidbubbles.com\/","https:\/\/x.com\/phpFlex"],"url":"https:\/\/androidbubble.com\/blog\/author\/admin\/"}]}},"views":1451,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/565","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/comments?post=565"}],"version-history":[{"count":2,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/565\/revisions"}],"predecessor-version":[{"id":1673,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/565\/revisions\/1673"}],"wp:attachment":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/media?parent=565"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/categories?post=565"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/tags?post=565"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}