Q. Explain the terms:
(i)
Dynamic
Biding
(ii)
Message
Passing
Ans. Dynamic Binding: - Dynamic Binding is also known as late binding
means that the code associated with a procedure call is not known until the
time of the call at run time. Binding refers to the linking of code with
procedure call at the time of execution in the response of call. Dynamic
binding is associated with ‘polymorphism’ and ‘inheritance’, for ex. in a
polymorphism program a function/procedure call associated with a polymorphic
reference depends on the dynamic type of that reference.
Message Passing: - In Object Oriented Programming we create class
that define objects and their behaviors, create objects of classes, and
establishing the communication between among objects. In OOP we can make the
number of objects and these objects can communicate with each other. These
objects communicate with each other by sending and receiving information to
each other in the same as peoples communicate with each other. A message is a
request for an object to execute of a procedure, or calling a function. A
message passing involves specifying the name of the object, the name of the
function (that is also known as message) and the information to be sent ex.student.marks
(course) student is an object here, marks
is a message and course is an information.
Q (a) Differentiate between the following: July 05
(a) Object & Classes?
(b) Data Abstraction & Data Hiding?
(c) Data Abstraction & Data encapsulation?
(d) Inheritance and polymorphism?
Ans. (a) Object & Class
Object is a run-time entity,
which may represent a person, a place, a table of data, or anything. Object
contains data and code to manipulate the data. The problem of Object-Oriented
Programming is solved in term of objects and communication between them. The
names of objects are choose in such way that they looks very closely to real
world objects. When an object is created it take place in memory and has a
unique address like a structure in C. when a program is execute, objects
interact with each other in the form of messages. Objects can interact without
having the knowledge of data and code of each other.
Class is a user-defined data
type, or a class is a logical entity which contains the set of attributes and
behavior, or a class is a collection of objects of similar type. Object is
variable of type class. After creating a class we can make any number of
objects belonging to that class. Each object is associated with the data of
type class with which they are crated.
(b) Data Abstraction & Data Hiding
Abstraction refers to
representing of essential features without including the background detail or
explanation. Class uses the concept of abstraction and defines the attributes
(variables) and functions (procedures), function make the operation on these
attributes. Classes use the concept of data abstraction and also known as
‘Abstract Data Types’ (ADT)
The functions provides the interface between
the object’s data and the program, we can access data from class only through
objects. This insulation of the data from direct access by the program is
called data hiding.
(c) Data Abstraction & Data encapsulation
The wrapping of data and
functions into a single unit is called encapsulation, or the wrapping of data
and functions into a class is called encapsulation. Data encapsulation is a
most important feature of class. It means the data encapsulate in the class is
not accessible by outside world and only those function which are wrapped in
the class can access it. Class encapsulates the properties of objects that are
to be created.
Abstraction refers to
representing of essential features without including the background detail or
explanation. Class uses the concept of abstraction and defines the attributes
(variables) and functions (procedures), function make the operation on these
attributes. Classes use the concept of data abstraction and also known as
‘Abstract Data Types’ (ADT)
(d) Inheritance and polymorphism
The concept of inheritance
provides the facility of code reusability. Inheritance means the object of one
class inherit the properties of another class object. It allows the programmer
to use the code again which already has been tested and debugged without retyping
same again. It means we can add additional features to an existing class
without modifying it. This is achieved by to deriving a new class from existing
one. This new class has the combined features of both classes.
Polymorphism means ability to
take more than one form it means one name having multiple forms. Polymorphism
is one of the most important characteristic of OOP. Concept of ‘polymorphism’
is used in function overloading and in operator overloading for ex. if a class
has more than one function with same name and different parameters is called
function overloading, which refers to polymorphism. There are two types of
Polymorphism ‘Compile Time Polymorphism’ and ‘Run Time Polymorphism’.
Q. Write a program in C++ to find the greatest and the second
greatest from a list of numbers.
Ans. #include<iostream.h>
#include<conio.h>
class abc
{
public:
int arr[100],no,i,max,smax,temp;
void find();
};
void abc::find()
{
i=-1,max=smax=0;
cout<<"\n Enter Number or -0 to exit ::
";
cin>>no;
while(no!=-0)
{
i++;
if(i==100)
{
cout<<"\n Over Flow Enter -0 to Exit ";
}
else
{
arr[i]=no;
if(arr[i]>=max)
{
temp=max;
max=arr[i];
smax=temp;
}
else if(arr[i]<max&&arr[i]>=smax)
smax=arr[i];
cout<<"\n Enter Number or -0 to exit ::
";
cin>>no;
}
}
cout<<"\n Greatest Number = "<<max;
cout<<"\n Second Greatest Number =
"<<smax;
}
void main()
{
clrscr();
abc obj;
obj.find();
getch();
}
No comments:
Post a Comment