Quantcast
Channel: Learn CBSE
Viewing all articles
Browse latest Browse all 9061

Important Questions for Class 12 Computer Science (C++) – Object Oriented Programming

$
0
0

Important Questions for Class 12 Computer Science (C++) – Object Oriented Programming

Previous Years Examination & Important Questions
2 Marks Questions

Question 1:
Write any four important characteristics of object oriented programming. Give example of any one of the characteristics using C++.  All India 2016
Answer:
Four important characteristics of object oriented programming are as follows:

(i) Data encapsulation
(ii) Inheritance
(iii) Polymorphism
(iv) Data abstraction

Example of Inheritance

Class Rectangle
{
::::
};
class Area : public Rectangle
{
::::
};

Question 2:
Explain data hiding with an example. All India 2014C
Answer:
Data hiding is a property, where internal data structure of an object is hidden from the outside world. Data hiding helps to secure the data. It is implemented with private and protected keywords. ,
e.g.

class Item
{
private:
int item_no; 
float item_cost; 
public:
void getdata(); 
void putdata();
};

Here, in this example variables item_no and item_cost are hidden, i.e. cannot be directly accessed from outside the class Item.

Question 3:
What is function overloading? Give an example in C++ to illustrate function overloading.
All India 2014,2009

or

What do you understand by function overloading? Give an example illustrating its use in a C++ program. All India 2009
Answer:
When several functions have same name but performing different tasks, then it is known as function overloading. The definitions of these functions are differentiable by the number or types of their arguments.
e.g.

float compute(float radius)
{
return(3.14*radius*radius);
}
float compute(float l, float b)
{
return(l*b)
}
float compute (int b, float h) 
{
 return(0.5*b*h);
}

Question 4:
Write the output of the following C++ code. Also, write the name of feature of Object Oriented Programming used in the following program jointly illustrated by the functions [I] to [IV]. Delhi 2011

#include<iostream.h>
void Print() //Function[I]
{
for(int K=1; K<=60; K++) 
cout<<"-"; 
cout<<endl;
}
void Print(int N) //Function[II]
{
for(int K=1; K<=N; K++) 
cout<<"*"; 
cout<<endl;
}
void Print(int A, int B)//Function[III]
}
for(int K=1; K<=B; K++)
cout<<A*K; 
cout<<endl;
}
void Print(char T, int N)//Function[IV]
{
for(int K=l; K<=N; K++) 
cout<<T; 
cout<<endl;
}
void main!)
{
int U=9, V=4, W=3; 
char C= '@';
Print(C, V);
Print(U, W);
}

Answer:
Feature of C++→ Function overloading The output will be:
@@@@
91827

Question 5:
Write the output of the following C++ code. Also, write the name of feature of Object Oriented Programming used in the following program jointly illustrated by the functions [I] to [IV]: All India 2011

#include<iostream.h>
 void Lined //Function[I]
 {
 for(int L=1;L<=80;L++)
 cout<<"-";
 cout<<endl;
 }
 void Line(int N) //Function[II]
 {
 for(int L=1;L<=N;L++)
 cout«"*";
 cout<<endl:
 }
 void Line(char C,int N) //Function[III]
 {
 for(int L=1:L<=N:L++)
 cout<<C;
 cout<<endl:
 }
 void Line(int M, int N)//Function[IV]
 {
 for(int L=1:L<N;L++)
 cout<<M*L;
 cout<<endl;
 }
 void main()
 {
 int A=9, B=4, C=3;
 char K=’#':
 Line (K,B);
 Line (A,C);

Answer:
Feature of C ++ Function overloading Output will be :
####
91827

Question 6:
What do you understand by Data Encapsulation and Data Hiding? Also, give an example in C++ to illustrate
both. All India 2010
Answer:
Data Encapsulation
The wrapping up of data (member variables) and functions into a single unit is known as data encapsulation. Encapsulation is implemented in C ++ with the help of classes.
Data Hiding
When member data and member function are binded into a single unit then the data is not accessible to the outside world and only those functions, which are wrapped in that class can access it. Data hiding is implemented in C+ + with the help of private and protected keywords.
e.g.
Important Questions for Class 12 Computer Science (C++) - Object Oriented Programming

Question 7:
What do you understand by polymorphism? Give an example illustrating its use in a C++ program. Delhi 2010
Answer:
Polymorphism means processing of data or messages in more than one form. C ++ implements polymoiphism through overloaded functions and overloaded operators,
e.g.

float compute(float a)
{
return a*a;
}
float computer float a,float b)
{
return(a*b); 
}

Question 8:
How are abstraction and encapsulation interrelated? Delhi 2009
Answer:
Abstraction refers to the representation of only the essential features of the real-world object in the program. This process does not include the background details and explanations. This concept of abstraction is used in classes whereas, data encapsulation is the most significant characteristic of the class. By this term, we mean the wrapping up of data and functions which operate on the data, into a single unit called the class. This encapsulation prevents free access to the data within an object.

Question 9:
What is event driven programming?
Answer:
In event driven programming, the user indicates the order of program execution not the programmer. Instead of, the program ‘driving’ the user ‘drives’ the program. Programming, in which the code that responds to the event is called event driven programming.

Question 10:
What is the significance of classes in OOPs?
Answer:
The classes are the manufacturing units of the objects of their type, i.e. it is the class that can be used to create an object. Classes are user defined data types and behave like the built-in types of a programming language. Classes are the basic building blocks of object oriented programming.

Question 11:
What are the advantages of object oriented programming over procedural oriented programming?
Answer:
Advantages of Object Oriented Programming (OOP) over Procedural Oriented Programming (POP)

Object Oriented Programming Procedural Oriented Programming
In OOP, program is divided into parts called objects. In POP, program is divided into small parts called functions.
OOP follows bottom up approach. POP follows top down approach.
OOP provides data hiding that provides more security. POP does not have any proper way for data hiding so it is less secure.
C++, Java, VB.NET, C, .NET, etc. are the examples of OOP language. C, VB, FORTRAN, Pascal etc are the examples of POP language.

Question 12:
Encapsulation is one of the major properties of OOP. How is it implemented in C++? HOTS

or

Define the term data encapsulation in terms of object oriented programming. Give a suitable example using a C++ code to illustrate the same.
Answer:
The wrapping up of data and functions into a single unit is called data encapsulation. That single unit is known as class.
e.g.

class person 
{
char name[30]; 
int age; 
public:
void getdata(void); 
void display(void);
};

The above program implements data hiding as data can’t be accessed directly from outside.

Question 13:
What is operator overloading? Explain with example.
Answer:
The process of making an operator to exhibit or show different behaviour in different situations is called as operator overloading.
e.g. consider the operation of (+) operator. Operation is sum, if operands are integer type and the operation is concatenation, if operands are strings.

The post Important Questions for Class 12 Computer Science (C++) – Object Oriented Programming appeared first on Learn CBSE.


Viewing all articles
Browse latest Browse all 9061

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>