<?xml-stylesheet type="text/xsl" href="http://edutogether.com/cprojects/weblog/rss/rssstyles.xsl"?>
<rss version='2.0'   xmlns:dc='http://purl.org/dc/elements/1.1/'>
    <channel xml:base='http://edutogether.com/cprojects/weblog/'>
        <title><![CDATA[C/C++ Projects : Weblog]]></title>
        <description><![CDATA[The weblog for C/C++ Projects, hosted on Edutogether : Education Network for Teachers, Students and Online Learners.]]></description>
        <generator>Elgg</generator>
        <link>http://edutogether.com/cprojects/weblog/</link>        
        <item>
            <title><![CDATA[Pointers and References]]></title>
            <link>http://edutogether.com/cprojects/weblog/238.html</link>
            <guid isPermaLink="true">http://edutogether.com/cprojects/weblog/238.html</guid>
            <pubDate>Thu, 10 Jul 2008 13:49:37 GMT</pubDate>
		<dc:subject><![CDATA[Pointers]]></dc:subject>
		<dc:subject><![CDATA[references]]></dc:subject>
            <description><![CDATA[<h2><a name="Pointers and references"  title="Pointers and references"></a>Pointers and references</h2> <p> C++ can have three kinds of variable, leading to three kinds of assignment, passing of arguments to functions, and returning values from functions. From C it inherits <em>value </em>and <em>pointer </em>variables. </p><h3>Value variables</h3> Value variables are declared with a plain syntax, preceding the name of the variable with the type (or class) name. For example: <pre>int i1;<br />float sum_of_money;<br />Graphic g1, g2;<br />Telescope t1;<br /></pre> where int and float are examples of base types, and Graphic and Telescope are names of classes already declared. <h3>Pointer variables</h3> Similarly: <pre>int* p1;<br />float* pointer_to_sum_of_money;<br />Graphic* pG1, pG2;<br />Telescope* pt1;<br /></pre> declare pointer variables of the same types. <p> In order to be useful, a pointer variable must be made to point to an existing object. This can be done by initialization: </p><pre>int* p1 = &amp;i1;<br />Graphic* pG1 = &amp;g1;<br /></pre> or by assignment: <pre>pG2 = &amp;g2;<br />pt1 = &amp;t1;<br /></pre> The ampersand (&amp;) is the &quot;address-of&quot; operator that comes from C. <p> Pointers may also be initialized or assigned through the new operator. They can  be used in parameter lists as well as as return types. </p><p>&nbsp;</p><h3>Reference variables</h3> C++ has a third kind of variable which operates like a pointer but with a value-like syntax. To declare a reference variable, we use &amp;, not *: <pre>int&amp; ri1;<br />Graphic&amp; rG1;<br />Telescope&amp; rt1;<br /></pre> The best way to think of reference variables is as <em>aliases</em>, i.e. a reference variable adds a name to an <em>existing</em> object. For this reason, &quot;free&quot; reference variables, such as the ones above are not allowed unless initialized: <pre>int&amp; ri1 = i1;<br />Graphic&amp; rG1 = g1;<br />Telescope&amp; rt1 = t1;<br /></pre> Now ri1 is another name for the object i1, rG1 for object g1 and rt1 for object t1. References are however allowed as class members (as long as they are initialized by some constructor), as parameters, and as return types. <p> One advantage of references over pointers is a simpler syntax. Compare the two &quot;swap&quot; functions below: </p><pre>void pswap(int* pi1, int* pi2) {<br />  int* ptemp = pi1;<br />  *ptemp = *pi1;<br />  *pi1 = *pi2;<br />  *pi2 = *ptemp;<br />}</pre> called with: <pre>int i1 = 12, i2 = 20;<br />pswap(&amp;i1, &amp;i2);<br /><br />void rswap(int&amp; ri1, int&amp; ri2) {<br />  int temp;<br />  temp = ri1;<br />  ri1 = ri2;<br />  ri2 = temp;<br />}<br /></pre> called with: <pre>int i1 = 12, i2 = 20;<br />rswap(i1, i2);<br /></pre> Both pswap and rswap produce the same result - the swapping of values in i1 and i2. <p> In theory the reference variable can replace most uses of pointers, but in practice, pointers are still used, especially with dynamic allocation.  </p>]]></description>
        </item>
                
        <item>
            <title><![CDATA[Important Concepts in C++ - Part 2]]></title>
            <link>http://edutogether.com/cprojects/weblog/188.html</link>
            <guid isPermaLink="true">http://edutogether.com/cprojects/weblog/188.html</guid>
            <pubDate>Mon, 02 Jun 2008 07:00:32 GMT</pubDate>
		<dc:subject><![CDATA[class]]></dc:subject>
		<dc:subject><![CDATA[constructor]]></dc:subject>
		<dc:subject><![CDATA[copy constructor]]></dc:subject>
		<dc:subject><![CDATA[dynamic]]></dc:subject>
		<dc:subject><![CDATA[friend function]]></dc:subject>
            <description><![CDATA[<p><em><strong><u>Friend Function</u> </strong>: </em>As we know, private class members can not be accessed from outside the class. By using private class members, we can reduce the possibility of a program misusing a member's value, since the program must access the class members using an interface function. Sometime, we would like two classes to share a particular function. In such situation, C++ allows the common function to be made <em>friendly</em> with both classes, thereby allowing the function to have access to the private data of these classes. Such a function need not be a member of any of these classes.</p><p>To make an outside function '<em>friendly</em>' to a class, we have to simply declare this function as a friend of the class. The function declaration should be preceded by the keyword <em>friend</em>. While the function definition does not use either the keyword <em>friend </em>or scope resolution operator (::). The function that are declared with the keyword <em>friend</em> are known as <strong>friend functions</strong>. A function can be declared friend in any number of classes.</p><p>A friend function possesses certain characteristics :</p><ul><li>It can be declared either in the public or private part of a class without affecting its meaning.</li><li>Usually, it has objects as arguments.</li><li>Its scope is not limited to the class in which it has been declared as <em>friend</em>. It can not be called using the object of that class. It can be invoked like a normal function without the help of any object.</li><li>Unlike the normal member functions, it can not access the member names directly. It has to use an object name and dot membership operator with each member name.</li></ul><p>Example,</p><p>#include &lt;iostream.h&gt;</p><p>class sample</p><p>{</p><p>&nbsp;&nbsp; int a;</p><p>&nbsp;&nbsp;  int b;</p><p>&nbsp;&nbsp; public :</p><p>&nbsp;&nbsp; &nbsp;&nbsp; void setvalue( int al, int bl)</p><p>&nbsp;&nbsp;&nbsp;&nbsp; {</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; a = a1;</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp; b = b1;</p><p>&nbsp;&nbsp;&nbsp;&nbsp; }</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; friend float mean (sample s);&nbsp; <em>//friend declared</em></p><p>};</p><p>float mean(sample s) &nbsp; &nbsp; <em>//function definition</em></p><p>{</p><p>&nbsp;&nbsp; return float(s.a + s.b) / 2; &nbsp; <em>//accessing private members</em></p><p><br />}&nbsp;</p><p>void main ()</p><p>{</p><p>&nbsp;&nbsp; sample x;&nbsp; <em>//create an object x</em></p><p><em>&nbsp;</em>&nbsp; x.setvalue(25,40);</p><p>&nbsp;&nbsp; cout&nbsp; &lt;&lt; &quot;Mean Value : &quot; &lt;&lt; mean(x) &lt;&lt; endl;</p><p>}</p><p>&nbsp;</p><p>All the member functions of one class can be declared as friend functions of another class. In such a case,the class is called a friend class. This can be specified as follows:</p><p>class X;</p><p>class Z</p><p>{</p><p>&nbsp;&nbsp; ......</p><p>&nbsp;&nbsp; friend class X;&nbsp; <em>//all member functions of X are friends to Z</em></p><p>};</p><p>&nbsp;</p><p><u><strong><em>Constructors</em></strong></u> : These are special member functions that are used to initialize the objects, as soon as they are created. Thst is, you can create an object and simultaneously pass the value to the parameters of the object. The constructors should have exactly the same name as that of class of which they are members. The constructor function does not have a return value. They should be declared in public section. To understand how constructors are used, let's try the example of displaying the area of square by using constructors :</p><p>Example,&nbsp;</p><p>class Square</p><p>{</p><p>&nbsp;&nbsp; public :</p><p>&nbsp;&nbsp; int dim;</p><p>&nbsp;&nbsp;  Square(int d);&nbsp;&nbsp;<em> //Declaring a Constructor Function</em></p><p>&nbsp;&nbsp;  {</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dim = d;</p><p>&nbsp;&nbsp;  }</p><p>&nbsp;&nbsp;  void DisplayArea()</p><p>&nbsp;&nbsp; {</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; &quot;The area of the square : &quot;&lt;&lt;dim*dim;</p><p>&nbsp;&nbsp; }</p><p>&nbsp;&nbsp; void main ()</p><p>&nbsp;&nbsp; {</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Square S1(10), S2(15);&nbsp;&nbsp;&nbsp; <em>//the constructor function will be called automatically</em></p><p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </em>cout &lt;&lt; &quot;The dimension of the square is : &quot; &lt;&lt; s1.dim;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S1.DisplayArea();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; &quot;The dimension of the square is :&quot; &lt;&lt; s1.dim;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; S2.DisplayArea();</p><p>&nbsp;&nbsp; }</p><p>&nbsp;</p><p>The output of the program will be :</p><p>The dimension of the square is 10</p><p>The area of the square : 100</p><p>The dimension of the square is 15</p><p>The area of the square : 225&nbsp;</p><p>&nbsp;</p><p><u><em><strong>Copy Constructor</strong></em></u> : It is used to declare an object and the values of these objects are initialized from other object. Note that a copy constructor takes a reference to an object of the same class. We can not pass the argument by value to a copy constructor.</p><p>Example,</p><p>#include &lt;iostream.h&gt;&nbsp;</p><p>class Square</p><p>{</p><p>&nbsp;&nbsp; int dim;</p><p>&nbsp;&nbsp; public :</p><p>&nbsp;&nbsp;  Square();&nbsp; </p><p>&nbsp;&nbsp;  {&nbsp;  }</p><p>&nbsp;&nbsp; Square (int I)</p><p>&nbsp;&nbsp; {</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; dim = I;</p><p>&nbsp;&nbsp;&nbsp; }</p><p>&nbsp;&nbsp; Square (Square &amp; j)&nbsp;&nbsp;&nbsp; <em>//passing the argument through reference not by value</em> </p><p>&nbsp;&nbsp; {&nbsp; dim = x.dim; }&nbsp; </p><p>&nbsp;&nbsp;  void Display()</p><p>&nbsp;&nbsp; {</p><p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; cout &lt;&lt; dim;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cout &lt;&lt; &quot;n The area is : &quot;&lt;&lt;dim*dim;</p><p>&nbsp;&nbsp; }</p><p>};&nbsp;</p><p>main ()</p><p>{</p><p>&nbsp; &nbsp; &nbsp; Square&nbsp;&nbsp; Square1(10);</p><p>&nbsp;&nbsp;&nbsp; &nbsp; Square&nbsp;&nbsp; Square1(Square2);&nbsp; <em>//declaring a copy constructor</em></p><p>&nbsp;&nbsp;&nbsp; &nbsp; Square Square3 = Square1;&nbsp; <em>//declaring a copy constructor</em> </p><p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </em>cout &lt;&lt; &quot;n length of square1 &quot; ;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Square1.Display();</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cout &lt;&lt; &quot;n length of square2 &quot; ; </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Square2.Display();</p><p>&nbsp;&nbsp;&nbsp; &nbsp; cout &lt;&lt; &quot;n length of square3 &quot; ; </p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Square3.Display();</p> <p>&nbsp;</p> <p>}</p><p>&nbsp;</p><p>The output is :</p><p>Length of square1 : 10</p><p>The area is : 100</p><p>length of square2 : 10</p><p>The area is : 100</p><p>Length of Square3 : 10</p><p>The area is : 100</p><p>&nbsp;</p><p><u><strong><em>Dynamic Constructors</em></strong></u> : They are used to allocate memory to objects at the time of their creation. Normally we can allocate fixed amount of memoryby using array but in many situations, we are not sure how much memory we need until runtime.&nbsp; For example, space required to store the length of string entered by user.</p><p>In such case, we use 'new' operator. This operator obtains memory space from operating system and returns a pointer to its starting point. We can use 'new' operators in constructors to dynamically assign storage space when objects are created.&nbsp;</p><p>&nbsp;</p>]]></description>
        </item>
                
        <item>
            <title><![CDATA[Important Concepts in C++ - Part 1]]></title>
            <link>http://edutogether.com/cprojects/weblog/178.html</link>
            <guid isPermaLink="true">http://edutogether.com/cprojects/weblog/178.html</guid>
            <pubDate>Sun, 25 May 2008 18:47:18 GMT</pubDate>
		<dc:subject><![CDATA[call by reference]]></dc:subject>
		<dc:subject><![CDATA[call by value]]></dc:subject>
		<dc:subject><![CDATA[Function]]></dc:subject>
            <description><![CDATA[<p><u><em><strong>Function Calls</strong></em></u></p><p>The program executes the function statements by calling the function.We can pass the information to the called function in two ways :</p><ul><li><em><strong>Call by Value </strong>:</em> The following program demonstrates how the information is passed to the called function by passing the value of parameters. This program uses the function <strong><em>display_values </em></strong>to display the value of variables before and after the function call.</li></ul><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ex.</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #include &lt;iostream.h&gt;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void display_values( int a, int b)</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p><p>&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  a = 100;</p><p>&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  b = 200;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; cout &lt;&lt; &quot;The values within the function are : &quot;&lt;&lt; a &lt;&lt; &quot;and&quot; &lt;&lt; b &lt;&lt; endl &lt;&lt; endl;</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  }</p><p>&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  void main()</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  {</p><p>&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  int x = 1001;</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  int y = 2001;</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  cout &lt;&lt; &quot; Before Function Call &quot; &lt;&lt; endl;</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp; cout &lt;&lt; &quot;The value of x and y is &quot; &lt;&lt; x &lt;&lt; &quot;and&quot; &lt;&lt; y &lt;&lt; endl &lt;&lt; endl;</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  display_values(x,y);</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  cout &lt;&lt; &quot; After function call &quot; &lt;&lt; endl;</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp; cout &lt;&lt; &quot; The value of x and y is &quot;&lt;&lt; x &lt;&lt; &quot;and&quot; &lt;&lt; y &lt;&lt; endl;<br />&nbsp;</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p><p>&nbsp;</p><p><br />The <strong>output </strong>is :</p><p>Before Function call</p><p>The value of x and y is 1001 and 2001</p><p>The values within the function are: 100 and 200</p><p>After function call</p><p>The value of x and y is 1001 and 2001</p><p>&nbsp;</p><p>As you can see, the  parameter values have been changed to 100 and 200 within the display-values functions. However, when the function ends, the values of the variables x and y within main() have not changed. Because when program pass a parameter to a function, C++ makes a copy of the parameter's valus and places the copy into a temporary memory location called stack. The function then uses the copy of the value. When the function ends, C++ discards the stack contents and any changes the function has made to the copy.</p><p>&nbsp;</p><ul><li><em><strong>Call by Reference </strong></em>: In Call-By-Value, the called function does not have access to the actual variables in the calling program and only works on the copies of the values. This mechanism is fine if the function does not need to alter the values of the original variables in the calling function. Sometimes, we need to change the value of variables in the calling function. For example, in the bubble sort program, we compare two adjacent elements in the list and interchange their values if the first element is greater than the second. If a function is used for bubble sort, then it should be able to alter the values of variables in the calling program, which is not possible if the call-by-value method is used.</li></ul><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;  &nbsp;&nbsp;  Ex :</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; #include&lt;iostream.h&gt;</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; void display_values( int *a, int *b )&nbsp; //creating pointers to type int</p><p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  *a = 100;</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp; *b = 200;</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  cout &lt;&lt; &quot;The values within the function are : &quot;&lt;&lt; *a &lt;&lt; &quot;and&quot; &lt;&lt;*b &lt;&lt; endl &lt;&lt; endl;</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  }</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  main (void)</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; {</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  int x = 1001;</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp; int y = 2001;</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  cout &lt;&lt; &quot;Before function call &quot; &lt;&lt; endl;</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp; cout &lt;&lt; &quot; The value of x and y is &quot; &lt;&lt; x &lt;&lt; and &lt;&lt; y &lt;&lt; endl &lt;&lt; endl;</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  display_values ( &amp;x, &amp;y );</p><p>&nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;  cout &lt;&lt; &quot; After function call &quot; &lt;&lt; endl;</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  cout &lt;&lt; &quot; The value of x and y is &quot; &lt;&lt; x &lt;&lt; &quot;and&quot; &lt;&lt; y &lt;&lt; endl;</p><p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;  }</p><p>&nbsp;</p><p>The <strong>output </strong>is :<br />&nbsp;</p><p>Before function call</p><p>The value of x and y is 1001 and 2001</p><p>The values within the function are: 100 and 200</p><p>After function call</p><p>The value of x and y is 100 and 200</p><p>&nbsp;</p><p>This is all about calling the functions in different ways. In next post, we will discuss about the various types of functions and their usage. </p>]]></description>
        </item>
                
        <item>
            <title><![CDATA[Features of Object Oriented Programming (OOP)]]></title>
            <link>http://edutogether.com/cprojects/weblog/175.html</link>
            <guid isPermaLink="true">http://edutogether.com/cprojects/weblog/175.html</guid>
            <pubDate>Fri, 23 May 2008 23:11:37 GMT</pubDate>
		<dc:subject><![CDATA[class]]></dc:subject>
		<dc:subject><![CDATA[programming]]></dc:subject>
		<dc:subject><![CDATA[polymorphism]]></dc:subject>
		<dc:subject><![CDATA[inheritance]]></dc:subject>
		<dc:subject><![CDATA[object oriented]]></dc:subject>
		<dc:subject><![CDATA[data encapsulation]]></dc:subject>
		<dc:subject><![CDATA[data abstraction]]></dc:subject>
            <description><![CDATA[<p><em><strong>Object oriented programming</strong></em> is defined as a method of implementation in which programs are organized as cooperative collection of objects, each of which is an instance of some class.&nbsp; Object based programming languages support the following features :</p><ul><li><strong>Data Abstraction</strong></li><li><strong>Data Encapsulation</strong></li><li><strong>Inheritance</strong></li><li><strong>Polymorphism</strong></li></ul><p>Now we will explain each one of them with examples :</p><p><em><u><strong>Data Abstraction</strong></u></em> : <em>&quot;Abstraction refers to the act of representing the essential features without including the background details or explanations.&quot; It </em>is the enforcement of a clear separation between the <em>abstract</em> properties of a data type and the <em>concrete</em> details of its implementation. The abstract properties are those that are visible to client code that makes use of the data type--the <em>interface</em> to the data type--while the concrete implementation is kept entirely private, and indeed can change, for example to incorporate efficiency improvements over time. The idea is that such changes are not supposed to have any impact on client code, since they involve no difference in the abstract behaviour. </p><p>For example, one could define an abstract data type called <em>lookup table</em>, where <em>keys</em> are uniquely associated with <em>values</em>, and values may be retrieved by specifying their corresponding keys. Such a lookup table may be implemented in various ways: as a hash table, a binary search tree, or even a simple linear list. As far as client code is concerned, the abstract properties of the type are the same in each case.</p><p><strong><u><em>Data Encapsulation</em></u></strong> :<em> &quot;Data encapsulation, sometimes referred to as data hiding, is the mechanism  whereby the implementation details of a class are kept hidden from the user.</em>&quot; The user can only perform a restricted set of operations on the hidden members of the class by executing special functions commonly called <em>methods</em>. The actions performed by the methods are  determined by the designer of the class, who must be careful not to make  the methods either overly flexible or too restrictive. This idea of hiding  the details away from the user and providing a  restricted, clearly defined interface is the underlying theme behind  the concept of an <em>abstract data type</em>.</p><p>For example, to create a stack class which can contain integers, the designer may choose to implement it with an array, which is hidden from the user  of the class. The designer then writes the push() and pop()  methods which puts integers into the array and removes them from the  array respectively. These methods are made accessible to the user. Should an attempt be made by the user to access the array directly,  a compile time error will result. Now, should the designer decide to  change the stack's implementation to a linked list, the array can simply  be replaced with a linked list and the push() and pop()  methods rewritten so that they manipulate the linked list instead of  the array. The code which the user has written to manipulate the  stack is still valid because it was not given direct access to the array to  begin with.</p><p> The concept of data encapsulation is supported in C++ through the use of the public, protected and private keywords which are placed in the declaration of the class. Anything in the class placed after the public keyword is accessible to all the users of the class; elements placed after the protected keyword are accessible only to the methods of the class or classes derived from that class; elements placed after the  private keyword are accessible only to the methods of the class.</p><p><u><em><strong>Inheritance</strong></em></u> : &quot;<em>It refers to a way to form new classes (instances of which are called objects) using classes that have already been defined.</em>&quot; The new classes, known as <strong>derived classes</strong>, take over (or <strong>inherit</strong>) attributes and behavior of the pre-existing classes, which are referred to as <strong>base classes</strong> (or ancestor classes). It is intended to help reuse existing code with little or no modification.</p><p>For example, <strong>manager</strong> is a part of class employee. Here class manager acquires the characteristics of class employee. There are many types of inheritance, some of which are listed below.</p><ul><li><em>Single Inheritance : </em>When a class is derived from only one base class, it is called single inheritance.</li></ul><img src="http://edutogether.com/cprojects/files/392/400/single.png"  border="0"  hspace="250"  width="100"  height="109"  align="middle" /><ul><li><em>Multiple Inheritance : </em>Inheritance in which a derived class has several base classes.</li></ul><img src="http://edutogether.com/cprojects/files/392/401/multiple.png"  border="0"  hspace="200"  width="200"  height="150"  align="middle" /><ul><li><em>Multilevel Inheritance : </em>The method of deriving a class from another derived class is called multilevel inheritance.</li></ul><img src="http://edutogether.com/cprojects/files/392/395/multi+level.gif"  border="0"  hspace="220"  width="138"  height="95"  align="middle" /><ul><li><em>Hierarchical Inheritance : </em>When the traits of one class are inherited by more than one class.</li></ul><img src="http://edutogether.com/cprojects/files/392/392/heirarchical.gif"  border="0"  hspace="220"  width="145"  height="57"  align="middle" /><ul><li><em>Hybrid Inheritance : </em>A method of inheritence where a class is derived from several derived classes.</li></ul><p><img src="http://edutogether.com/cprojects/files/-1/396/hybrid.png"  border="0"  hspace="250"  width="90"  height="135"  align="middle" /><br /><u><em></em></u></p><p><u><em><strong>Polymorphism</strong></em></u> : &quot;<em>Polymorphism is the process of using an operator or function in different ways for different set of inputs given.&quot; </em>More precisely, polymorphism (object-oriented programming theory) is the ability of objects belonging to different types to respond to method calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, so this behavior can be implemented at run time (this is called <em>late binding</em> or <em>dynamic binding</em>).</p><u><em></em></u><p>It means that if class B inherits from class A, it doesn&rsquo;t have to inherit everything about class A; it can do some of the things that class A does differently.means that if class B inherits from class A, it doesn&rsquo;t have to inherit everything about class A; it can do some of the things that class A does differently. </p><p>&nbsp;</p>]]></description>
        </item>
        
    </channel>
</rss>