CBSE eBooks

CBSE Guess > eBooks > Class XII > Computer Science By . Mr. MRK

Chapter – 3. OBJECT ORIENTED PROGRAMMING

Previous Index Next

Example program illustrating function overloading:

//Program to find out area of a circle or area of rectangle using
//function overloading.
#include<iostream.h>
#include<conio.h>
void area(float r)
{
cout<<”\nThe area of the circle = “<<3.1415*r*r;
}

void area(float l,float b)
{
cout<<”\nThe area of the rectangle = “<<l*b;
}
void main( )
{
float rad,len,bre; int n;
clrscr( );
cout<<”\n1. Area of a Circle…”;
cout<<”\n2. Area of a Rectangle…”;
cout<<”\n\nEnter your choice: “;
cin>>n; switch(n) { case 1:
cout<<”\nEnter the radius: “;
cin>>rad; area(rad); break; case 2:
cout<<”\nEnter the length and breadth: “;
cin>>len>>bre; area(len,bre); break; default:
cout<<”\nYou have to enter either 1 or 2”; } //end of switch
getch( );
}

2000:

1.a. Illustrate the concept of function overloading with the help of an example. 1

Ans: The above answer.

1998:

1.a. Define the following terms:

(i) Inheritance (ii)Encapsulation.

Ans:

i. Inheritance: The capability of one class to inherit properties from another class is called as inheritance. The class inheritance, lets you generate a model that is closer to the real world. The class inheritance lets you derive new classes (derived class) from old ones (base class), with the derived class inheriting the properties, including the methods of the old class.
Uses of Inheritance:

a. Capability to express the inheritance relationship which ensures the closeness with the real world models.
b. Reusability.
c. Transitive nature of inheritance.

ii. Encapsulation: The wrapping up of data and functions into a single unit (class) is called as encapsulation

Previous Index Next