Académique Documents
Professionnel Documents
Culture Documents
QUESTION BANK
SEMESTER : III
YEAR : II
REGULATION : 2008
Prepared By
S.Venkatesan M.E
Asst.Prof/CSE. A.C.T.C.E.T
UNIT I
2. What is an object?
An Object is the basic run time entities in an object oriented system. They may represent a
person, a place or any data item. Objects contain data and code to manipulate data.
3. What is a class?
The entire set of data and code of an object that can be made a user defined data type with the
help of a class. A class is a collection of objects of type class.
Binding refers to the linking of a procedure call to the code to be executed in response to the call.
Dynamic binding also known as late binding means that the code associated with a given
procedure call is not known until the time of call at run time.
5. Define encapsulation.
Encapsulation is the process of combining data and functions into a single unit called class.
Using the method of encapsulation, the programmer cannot directly access the data. Data is only
accessible through the functions present inside the class. Data encapsulation led to the important
concept of data hiding.
6. Define data-hiding.
Data members (attributes) in a class are declared as private and private members can be accessed
only by functions within the same class. This hides the data from being accessed by other
functions outside the class.
7. Define abstraction.
Abstraction is the process of hiding the inner working details. Classes provide the abstraction by
hiding the complex workings from the user and providing only the essential details.
8. What is inheritance?
Inheritance is the process by which new classes called derived classes are created from existing
classes called base classes. The derived classes have all the features of the base class and the
programmer can choose to add new features specific to the newly created derived class.
9. What is polymorphism?
Polymorphism is the ability to use an operator or function in different ways. Polymorphism gives
different meanings or functions to the operators or functions. Poly, referring too many, signifies
the many uses of these operators and functions. A single function usage or an operator
functioning in many ways can be called polymorphism. Polymorphism refers to codes,
operations or objects that behave differently in different contexts.
A function with the same name performing different operations is called function overloading.
To achieve function overloading, functions should be declared with the same name but different
number and type of arguments. This comes under compile time polymorphism.
The same operator performing different operations is called operator overloading. E.g. two
matrices cannot be directly overloaded. But the + operator can be overloaded to perform addition
of two matrices or other user defined data types.
Classes are data types based on which objects are created. Objects with similar properties and
methods are grouped together to form a Class. Thus a Class represents a set of individual objects.
Characteristics of an object are represented in a class as Properties. The actions that can be
performed by objects become functions of the class are referred to as Methods.
String length
String copy
String concatenation
String comparison
String
Uses:
21. What are the differences between structural and object oriented programming?
String length
String copy
String concatenation
String comparison
String conversions
Several different classes can use the same function name. The membership label
will resolve their scope.
Member functions can access the private data of the class. A non member
function cannot do so.
A member function can call another member function directly, without using the
dot operator.
2 Large programs are divided into smaller Programs are divided into objects.
programs called functions.
3 Functions share global data Functions that operate on the data of an object are
tied together.
4 Data move openly around the system Data is hidden and cannot be accessed by external
from function to function. functions.
UNIT II
Default constructor
Parameterized constructor
Copy constructor
A destructor as the name implies is used to destroy the objects that have been created by a
constructor. Like a constructor the destructor is a member function whose name is the same as
the class name but is preceded by a tilde symbol.
{
………
};
student s1(a);
}
48. Define copy constructor.
A copy constructor is used to declare and initialize an object from another object. It takes a
reference to an object of the same class as an argument.
E.g.: integer i2 (i1);
Would define the object i2 at the same time initialize it to the values of i1. Another form of this
statement is
E.g.: integer i2=i1;
The process of initializing through a copy constructor is known as copy initialization.
The overloaded operator must have at least one operand that is of user defined data type.
The basic meaning of the operator should not be changed.
Overloaded operators follow the syntax rules of the original operators. They cannot be
overridden.
53. How will you overload Unary & Binary operator using member functions?
When unary operators are overloaded using member functions it takes no explicit arguments and
return no explicit values. When binary operators are overloaded using member functions, it takes
one explicit argument. Also the left hand side operand must be an object of the relevant class.
55. How will you overload Unary & Binary operator using member functions?
When unary operators are overloaded using member functions it takes no explicit arguments and
return no explicit values. When binary operators are overloaded using member functions, it takes
one explicit argument. Also the left hand side operand must be an object of the relevant class.
Delete operator is used to return the memory allocated by the new operator back to the memory
pool. Memory thus released will be reused by other parts of the program.
UNIT III
Synchronous exception:
Asynchronous exception:
The exception which occur during program execution , due to some fault in the input data or
technique that is not suitable to handle the current class of data, within the program are known as
synchronous exception. For instance errors such as out-of-range, overflow, underflow and so on.
The technique that is not suitable to handle the current class of data, within the program is known
as synchronous exception
The exceptions caused by events or faults unrelated to the program and beyond the
control of the program are called asynchronous exception. For instance, errors such as keyboard
interrupts, hardware malfunctions, disk failure, and so on.
The exceptions caused by events or faults unrelated to the program and beyond the control of
program are called asynchronous exceptions
The templates declared for functions are called function templates. They perform appropriate
operations depending on the data type of the parameters passed to them.
The templates declared for classes are called function templates. They perform appropriate
operations depending on the data type of the parameters passed to them.
Runtime exceptions are automatically defined for the programs that we write and include
things such as division by zero and invalid array indexing.
The process of calling destructor for automatic objects constructed on the path from a try-
block to a thrown expression is called stack unwinding
1. Logical errors-errors occur due to poor understanding of the problem and solution procedure
2. Syntax errors-errors that arise due to poor understanding of the language itself.
Run time Polymorphism - The compiler selects the appropriate function for a
particular call at the run time only. It can be achieved using virtual functions.
Unit IV
Inheritance is the process of creating new classes from the existing classes. The new classes are
called derived classes. The existing classes are called base classes. The derived classes inherit all
the properties of the base class plus its own properties. The property of inheritance does not
affect the base classes.
Single inheritance
Multiple inheritance
Hierarchical inheritance
Multilevel inheritance.
Hybrid inheritance
Multipath inheritance
New classes can be derived by the user from the existing classes without any modification.
A member function whose definition can be changed during run time is called virtual function.
The class which contains virtual function is called polymorphic class and it should be a base
class. Different versions for the virtual function should be present in different derived classes
with same name as virtual function name.
A function qualified by the ‘virtual’ keyword is called virtual function. When a virtual function
is called through a pointer, class of the object pointed to determine which function definition will
be used.
Pure virtual function is a virtual function with no body. The general form is:
Polymorphism is the ability to take more than one form. An operation may exhibit different
behaviors in different. The behavior depends upon the type of data used.
Run-time type information (RTTI) is a mechanism that allows the type of an object to be
determined during program execution
The typeid operator provides a program with the ability to retrieve the actual derived type of the
object referred to by a pointer or a reference. This operator is used along with the dynamic cast
operator
Dynamic cast allows us to downcast a data type from one to a more specific one in the same
hierarchy
Downcasting is used to cast a pointer or reference to a base class to a derived class. Downcasting
is the opposite of the basic object-oriented rule, which states objects of a derived class, can
always be assigned to variables of a base class. Since base class variables can only sometimes be
assigned to variables of a derived class downcasting doesn’t always work
identical.
• If a virtual function is defined in the base class, it need not be redefined in the derived class.
The compiler while compiling the program resolves the function call or the operator call. This is
known as compile time polymorphism:
During multiple inheritances if the appropriate member function could be selected while the
program is running is known as Runtime polymorphism
It is a very powerful tool in c++ for finding out the type of an object at runtime. Because
of runtime functioning, RTTI also impacts the performance of the system to a notable extent.
Stream is a series of bytes, which act either as a source from which input data can be extracted or
as a destination to which the output can be sent. The source stream provides data to the program
called the input stream and the destination stream that receives data from the program is called
the output stream.
A class that serves only as a base class from which derived classes is derived. No objects of an
abstract base class are created. A base class that contains pure virtual function is an abstract base
class.
Manipulators are special functions that are specifically designed to modify the working of a
stream. They can be embedded in the I/O statements to modify the form parameters of a
stream.
A sequential file has to be accessed sequentially; to access the particular data in the file all the
preceding data items have to be read and discarded. For example a file on a tape must be
accessed sequentially.
A random file allows access to the specific data without the need for accessing its preceding data
items. However, it can be accessed sequentially. For example, a file on a hard disk or floppy disk
can be accessed either sequentially or randomly.
UNIT V
A Stream is a sequence of bytes. It can either as a source from which the input data can
be obtained or as a destination to which the output data can be sent
The stream source that provides data to the program is called the input stream and the
destination stream that receives output from the program is called output stream
a)ios
b)istrean
c)ostream
d)iostream
e)streambuf
C++ supports a number of features that could be used for formatting the output. These features
include
b) Standard manipulators
ANSI C++ Standard has added a new keyword namespace to define a scope that could
hold global identifiers. The best example of namespace scope is the C++ Standard Library. All
classes, functions and templates are declared within the namespace named std.
The using namespace statement specifies that the members defined in std namespace will be
used frequently throughout the program
An unnamed namespace is one that does not have a name. Unnamed namespace members
occupy global scope and are accessible in all scopes following the declaration in the file
A container is an object that actually stores data. It is a way data is organized in memory.
The STL containers are implemented by template classes and therefore can be easily customized
to hold different types of data
1) Sequence containers
2) Associative containers
3) Derived containers
Sequence containers store elements in a linear sequence, like a line. Each element is related to
other elements by its position along the line. They all expand themselves to allow insertion of
elements and all of them support a number of operations on them
The derived containers do not support iterators and therefore we cannot use them for data
manipulation. They support two member functions pop () and push () for implementing deleting
and inserting operations.
The vector stores elements in contiguous memory locations and enables direct access to any
element using the subscript operator [].A vector can change its size dynamically and therefore
allocates memory as needed at run time