Cs 2 PDF
Cs 2 PDF
http://cbsecsnip.in
Ans. Inheritance ensures the closeness with the real-world models.
Allows the code to be reused as many times as needed. The base class once defined and once it is compiled,
it need not be reworked.
We can extend the already made classes by adding some new features.
Inheritance is capable of simulating the transitive nature of real-worlds inheritace, which in turn saves on
modification time and efforts, if required.
8. Do you think OOP is more closer to real world problems? Why? How?
Ans. Yes, OOP is more closer to real world problems because object oriented programming implement inheritance by
allowing one class to inherit from another. Thus a model developed by languages is much closer to the real world. By
implementing inheritance, real-world relations among objects can be represented programmatically.
9. How are classes and objects implemented in C++?
Ans. A class is a blueprint for object. A class is implementing with the help of an object. Suppose a class has a member
function named display(). Now, to implement that member function display we have to use object of that class.
The objects is implemented in software terms as follows:
(i) characteristics / attributes are implemented through member variables or data items of the object.
(ii) behavior is implemented through member functions called methods.
(iii) It is given a unique name to give it identify.
10. What is the significance of private, protected and public specifiers in a class?
Ans. A class groups its members into three sections: private, protected, and public. The private and protected members
remain hidden from outside world. Thus through private and protected members, a class enforces data-hiding. The
public members are accessible everywhere in a program.
http://cbsecsnip.in
class GraduateStudent:protected Student
{
protected:
char subjects[50];
public:
void readAradStud();
void showGradStud();
};
14. Encapsulation is one of the major properties of OOP. How is it implemented in C++?
Ans. A class binds together data and its associated functions under one unit thereby enforcing encapsulation as
encapsulation means wrapping up data and associated functions together into a single unit. While implementing
encapsulation, following things are taken care of:
(i) Anything that an object does not know or cannot do is excluded from the objects.
(ii) Encapsulation is used to hide unimportant implementation details from other objects.
(iii) The data and associated functions are wrapped up in one unit called class.
Through encapsulation, an interface is made available to world through which users can use the class.
15. Reusability of classes is one of the major properties of OOP. How is it implemented in C++?
Ans. Reusability of classes is implemented through inheritance in C++. Inheritance is implemented by specifying the name
of the (base) class from which the class being defined (the derived class) has to inherit from.
It is done with the following syntax:
class<derived class name> : <base class name>
{
<- derived class own features.
}
16. How is polymorphism implemented in C++?
Ans. C++ implements polymorphism through virtual functions, overloaded functions and overloaded operators.
The term overloaded function refers to a function having one name and more than one distinct meaning.
For example,
float area(float a)
{
return a*a;
}
float area(float a,float b)
{
return a*b;
}
TYPE C : LONG ANSWER QUESTIONS
1. Write briefly about different programming paradigms.
Ans. Programming Paradigm: A Programming Paradigm defines the methodology of designing and implementing
programs using the key features and building blocks of a programming language. Following are the different
programming paradigms:
(i) Procedural Programming: Procedural programming paradigm lays more emphasis on procedure or the algorithm.
Data is considered secondary. Data is loosely available to many functions. This paradigm is: Decide which procedure
we want; use the best algorithm we can find.
(ii) Object Based Programming: In object based programming, data and its associated meaningful functions are
enclosed in one single entity a class. Classes enforce information hiding and abstraction thereby separating the
implementation details and the user interface. It also supports user-defined types.
(iii) Object Oriented Programming: Object oriented programming offers all the features of object based programming
and overcomes its limitation by implementing inheritance. The object oriented approach views a problem in terms of
objects involved rather than procedure for doing it. We can define the object oriented programming (OOP) paradigm
as following: Decide which classes and objects are needed; provide a full set of operations for each class.
2. Discuss OOP concepts. How are these implemented in software terms in C++?
3
http://cbsecsnip.in
Ans. Following are the general OOP concepts:
1. Data Abstraction: Abstraction refers to the act of representing essential features without including the
background details or explanations. Abstraction is implemented through public members of a class, as the outside
world is given only the essential and necessary information through public members, rest of the things remain
hidden.
2. Data Encapsulation: The wrapping up of data and operations/functions (that operate o the data) into a single unit
(called class) is known as Encapsulation. Encapsulation is implemented with the help of a class as a class binds
together data and its associated function under one unit.
3. Modularity: The act of partitioning a program into individual components is called modularity. C++ implements
modularity through separately compiled files. The traditional practice in the C++ community is to place module
interface in files named with a .h suffix; these are called header files which can be used through #include directive.
4. Inheritance: Inheritance is the capability of one class of things to inherit capabilities or properties from another
class. Inheritance is implemented in C++ by specifying the name of the (base) class from which the class being
defined (the derived class) has to inherit from.
5. Polymorphism: Polymorphism is the ability for a message or data to be processed in more than one form. C++
implements polymorphism through virtual functions, overloaded functions and overloaded operators.
http://cbsecsnip.in