{"id":601,"date":"2012-03-02T18:45:24","date_gmt":"2012-03-02T18:45:24","guid":{"rendered":"http:\/\/www.websitedesignwebsitedevelopment.com\/?p=601"},"modified":"2014-03-19T09:14:02","modified_gmt":"2014-03-19T09:14:02","slug":"the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program","status":"publish","type":"post","link":"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/","title":{"rendered":"The concept of composition in OOP, Inheritance, Public &#038; private inheritance, basic constructs of OOP in a program"},"content":{"rendered":"<h2>The concept of composition in OOP, Inheritance, Public &#038; private inheritance, basic constructs of OOP in a program<\/h2>\n<h4>A C++ Program in which you will learn to write a class \u2018Pakistani Citizens\u2019 which has five data members \u201cname, age, CNIC No, province, and domicile\u201d and two data functions getter and setter for each data member e.g setAge() getAge() etc.<\/h4>\n<p>A second class \u2018VotersList\u2019 which inherited the \u2018PakistaniCitizens\u2019 class and has \u201cimplemented in term of\u201d relationship to pakistaniCitizens.<\/p>\n<p>The \u2018VotersList\u2019 class restrict the functionality of setAge() function by override the setAge() function of \u2018PakistaniCitizens\u2019 class and check the condition :<\/p>\n<p>If age is greater than 18 then print \u201cEligible for vote cast\u201d.<\/p>\n<p>If object of VotersList class is initialized with the age less than 18, then it prints a message<\/p>\n<p>\u201cAge is less than 18\u201d and sets the value of age to default.<\/p>\n<p>#include<br \/>\n#include<\/p>\n<p>\/\/Pakistani Citizens class<br \/>\nclass Pakistani_Citizens{<\/p>\n<p>\/\/Attributes of pakistani citizens class<\/p>\n<p>protected:<br \/>\nint age;<br \/>\nprivate:<br \/>\nchar * name;<br \/>\nint CnicNo;<br \/>\nchar * provience;<br \/>\nchar * domicile;<br \/>\n\/\/public interface of pakistani citizens class<\/p>\n<p>public:<br \/>\n\/\/Default constructor<br \/>\nPakistani_Citizens();<\/p>\n<p>\/\/ Parameterized constructor<br \/>\nPakistani_Citizens(int, char *, int, char *,char *);<\/p>\n<p>\/\/Setter functions of paksitani citizens class<br \/>\nvoid setAge(int _age);<br \/>\nvoid setName(char * aname);<br \/>\nvoid setProvience(char * pro);<br \/>\nvoid setDomicile(char * dom);<\/p>\n<p>\/\/Getter functions of pakistani citizens class<br \/>\nint getAge();<br \/>\nchar * getName();<br \/>\nchar *getProvience();<br \/>\nchar * getDomicile();<\/p>\n<p>\/\/Destructor of pakistani citizens class<br \/>\n~Pakistani_Citizens();<br \/>\n}; \/\/End of pakistani citizens class<\/p>\n<p>\/\/Definition of Default constructor<br \/>\nPakistani_Citizens::Pakistani_Citizens(){<\/p>\n<p>age=0;<br \/>\nname=&#8221;ABC&#8221;;<br \/>\nCnicNo=1234;<br \/>\nprovience=&#8221;abc&#8221;;<br \/>\ndomicile=&#8221;xyz&#8221;;<\/p>\n<p>}<\/p>\n<p>\/\/Definition of parameterized constructor<br \/>\nPakistani_Citizens::Pakistani_Citizens(int _age, char* aname, int cno, char*prov, char*dom)<br \/>\n{<br \/>\nage=_age;<br \/>\nname=aname;<br \/>\nCnicNo=cno;<br \/>\nprovience=prov;<br \/>\ndomicile=dom;<br \/>\n}<\/p>\n<p>\/\/Definition of setAge method<br \/>\nvoid Pakistani_Citizens::setAge(int _age){<br \/>\nif(_age&gt;0)<br \/>\n{<br \/>\nage=_age;<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/Definition of setName method<br \/>\nvoid Pakistani_Citizens::setName(char * aname){<br \/>\nname=aname;<br \/>\n}<\/p>\n<p>\/\/Definition of setProvience method<br \/>\nvoid Pakistani_Citizens:: setProvience(char * pro){<br \/>\nprovience=pro;<br \/>\n}<\/p>\n<p>\/\/Definition of setDomicile method<br \/>\nvoid Pakistani_Citizens::setDomicile(char * dom){<br \/>\ndomicile=dom;<br \/>\n}<\/p>\n<p>\/\/Definition of getAge method<br \/>\nint Pakistani_Citizens:: getAge(){<br \/>\nreturn age;<br \/>\n}<\/p>\n<p>\/\/Definition of getName method<br \/>\nchar * Pakistani_Citizens:: getName(){<br \/>\nreturn name;<br \/>\n}<\/p>\n<p>\/\/Definition of getProvience method<br \/>\nchar * Pakistani_Citizens::getProvience(){<br \/>\nreturn provience;<br \/>\n}<\/p>\n<p>\/\/ Definition of getDomicile method<br \/>\nchar * Pakistani_Citizens::getDomicile(){<br \/>\nreturn domicile;<br \/>\n}<\/p>\n<p>\/\/ Destructor of pakitani citizens class<br \/>\nPakistani_Citizens::~Pakistani_Citizens(){<br \/>\n}<\/p>\n<p>\/\/VotorList class inherited from Pakistani_Citizens class<br \/>\nclass VotorList:public Pakistani_Citizens{<\/p>\n<p>\/\/pbulic interface of class VotorList<br \/>\npublic:<\/p>\n<p>\/\/Default constructor<br \/>\nVotorList();<\/p>\n<p>\/\/ Declaration of setAge method<br \/>\nvoid setAge(int _age);<\/p>\n<p>\/\/Destructor of VotorList class<br \/>\n~VotorList();<br \/>\n}; \/\/End of class VotorList<\/p>\n<p>VotorList::VotorList(){<\/p>\n<p>}<br \/>\nvoid VotorList:: setAge(int _age){<br \/>\nif (_age &gt;=18 ) {<br \/>\ncout&lt; _age=Pakistani_Citizens::age;<br \/>\n}<br \/>\n}<br \/>\nVotorList::~VotorList(){<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p class=\"MsoNormal\">a C++ Program in which you will have to write a class \u2018<strong>Pakistani Citizens\u2019<\/strong> which has five data members \u201cname, age, CNIC No, province, and domicile\u201d and two data functions getter and setter for each data member e.g <strong>setAge() getAge<\/strong>() etc.<\/p>\n<p>Write a second class \u2018<strong>VotersList\u2019<\/strong> which inherited the <strong>\u2018PakistaniCitizens\u2019<\/strong> class and has \u201cimplemented in term of\u201d relationship to <strong>pakistaniCitizens.<\/strong><\/p>\n<p>The \u2018VotersList\u2019 class restrict the functionality of <strong>setAge()<\/strong> function by override the <strong>setAge()<\/strong> function of <strong>\u2018PakistaniCitizens\u2019<\/strong> class and check the condition :<\/p>\n<p class=\"MsoNormal\">If age is greater than 18 then print \u201c<strong>Eligible for vote cast\u201d<\/strong>.<\/p>\n<p class=\"MsoNormal\"><span>\u00a0<\/span>If object of <strong>VotersList<\/strong> class is initialized with the age less than 18, then it prints a message<\/p>\n<p><span style=\"font-size: 12pt; font-family: 'Times New Roman';\">\u201c<strong>Age is less than 18<\/strong>\u201d and sets the value of age to default.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The concept of composition in OOP, Inheritance, Public &#038; private inheritance, basic constructs of OOP in a program A C++ Program in which you will learn to write a class \u2018Pakistani Citizens\u2019 which has five data members \u201cname, age, CNIC No, province, and domicile\u201d and two data functions getter and setter for each data member [&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,50],"tags":[],"class_list":["post-601","post","type-post","status-publish","format-standard","hentry","category-c","category-oop"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>The concept of composition in OOP, Inheritance, Public &amp; private inheritance, basic constructs of OOP in a program<\/title>\n<meta name=\"description\" content=\"The concept of composition in OOP, Inheritance, Public &amp; private inheritance, basic constructs of OOP in a program\" \/>\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\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The concept of composition in OOP, Inheritance, Public &amp; private inheritance, basic constructs of OOP in a program\" \/>\n<meta property=\"og:description\" content=\"The concept of composition in OOP, Inheritance, Public &amp; private inheritance, basic constructs of OOP in a program\" \/>\n<meta property=\"og:url\" content=\"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/\" \/>\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-03-02T18:45:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-03-19T09:14:02+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=\"3 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\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/\"},\"author\":{\"name\":\"Fahad\",\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\"},\"headline\":\"The concept of composition in OOP, Inheritance, Public &#038; private inheritance, basic constructs of OOP in a program\",\"datePublished\":\"2012-03-02T18:45:24+00:00\",\"dateModified\":\"2014-03-19T09:14:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/\"},\"wordCount\":571,\"articleSection\":[\"C++\",\"OOP\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/\",\"url\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/\",\"name\":\"The concept of composition in OOP, Inheritance, Public & private inheritance, basic constructs of OOP in a program\",\"isPartOf\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/#website\"},\"datePublished\":\"2012-03-02T18:45:24+00:00\",\"dateModified\":\"2014-03-19T09:14:02+00:00\",\"author\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7\"},\"description\":\"The concept of composition in OOP, Inheritance, Public & private inheritance, basic constructs of OOP in a program\",\"breadcrumb\":{\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/#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\":\"The concept of composition in OOP, Inheritance, Public &#038; private inheritance, basic constructs of OOP in a program\"}]},{\"@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":"The concept of composition in OOP, Inheritance, Public & private inheritance, basic constructs of OOP in a program","description":"The concept of composition in OOP, Inheritance, Public & private inheritance, basic constructs of OOP in a program","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\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/","og_locale":"en_US","og_type":"article","og_title":"The concept of composition in OOP, Inheritance, Public & private inheritance, basic constructs of OOP in a program","og_description":"The concept of composition in OOP, Inheritance, Public & private inheritance, basic constructs of OOP in a program","og_url":"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/","og_site_name":"AndroidBubble Blog","article_publisher":"https:\/\/www.facebook.com\/pages\/Website-Design-Website-Development\/172363336135453","article_published_time":"2012-03-02T18:45:24+00:00","article_modified_time":"2014-03-19T09:14:02+00:00","author":"Fahad","twitter_misc":{"Written by":"Fahad","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/#article","isPartOf":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/"},"author":{"name":"Fahad","@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7"},"headline":"The concept of composition in OOP, Inheritance, Public &#038; private inheritance, basic constructs of OOP in a program","datePublished":"2012-03-02T18:45:24+00:00","dateModified":"2014-03-19T09:14:02+00:00","mainEntityOfPage":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/"},"wordCount":571,"articleSection":["C++","OOP"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/","url":"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/","name":"The concept of composition in OOP, Inheritance, Public & private inheritance, basic constructs of OOP in a program","isPartOf":{"@id":"https:\/\/androidbubble.com\/blog\/#website"},"datePublished":"2012-03-02T18:45:24+00:00","dateModified":"2014-03-19T09:14:02+00:00","author":{"@id":"https:\/\/androidbubble.com\/blog\/#\/schema\/person\/0a833b633f744c3a5e0de7c9a94e71f7"},"description":"The concept of composition in OOP, Inheritance, Public & private inheritance, basic constructs of OOP in a program","breadcrumb":{"@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/androidbubble.com\/blog\/website-development\/c\/the-concept-of-composition-in-oop-inheritance-public-private-inheritance-basic-constructs-of-oop-in-a-program\/#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":"The concept of composition in OOP, Inheritance, Public &#038; private inheritance, basic constructs of OOP in a program"}]},{"@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":632,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/601","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=601"}],"version-history":[{"count":3,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/601\/revisions"}],"predecessor-version":[{"id":603,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/posts\/601\/revisions\/603"}],"wp:attachment":[{"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/media?parent=601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/categories?post=601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/androidbubble.com\/blog\/wp-json\/wp\/v2\/tags?post=601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}