Cs2311-Object Oriented Programming
Cs2311-Object Oriented Programming
UNIT – I
1. Define object oriented programming?
OOP is an approach that provides a way of modularizing programs by creating
partitioned memory areas for both data and functions that can be used as an templates for
creating copies of such modules on demand.
2. List some features of OOP?
i. Emphasis is on data rather than procedures.
ii. Programs that are divided into what are known as objects.
iii. Follows bottom – up approach in program design.
iv. Functions that operate on the data of an object are tried together in the
data structure.
3. Define Class?
A Class is a collection of objects of similar type.
The classes are user-defined data types and behave like built-in types of a
programming language.
A class is a way to bind the data and its associated functions together.
A class is a user-defined data type with a template that serves to define its
properties.
A class is a blueprint that defines the variables & the methods common to
all objects of a certain kind.
4. What do you mean by object?
Objects are basic run-time entities in an object-oriented system. They may represent a
person, a place, a bank account, a table of data or any item that the program has to handle. Each
object has the data and code to manipulate the data and theses objects interact with each other.
5. What is meant by Encapsulation?
The wrapping up of data and function into a single unit(class) is known as
Encapsulation.
6. What do you mean by Data abstraction?
Abstraction refers to the act of representation of essential features without
including the background details or explanations. Classes use the concept of abstraction
& are defined as a list of abstraction attributes such as size, weight & cost & functions to
operate on these attributes.
7. What do you mean by inheritance?
Inheritance is the process by which objects of one class acquire the
properties of objects of another class.
8. What do you mean by reusability?
The process of adding additional features to an existing class without modifying
it is known as „Reusability‟. The reusability is achieved through inheritance. This is
possible by deriving a new class from an existing class. The new class will have the
combined features of both the classes.
9. Define polymorphism?
Polymorphism means the ability to take more than one form. For example, an
operation may exhibit different behavior in different instances. The behavior depends
upon the types of data used in the operation.
1
16 Mark Questions
Private:
Variable declaration;
Function declaration;
Public:
Variable declarations;
Function declarations;
};
31. What are the situations that inline functions may not work?
1. For function returning values, if a loop, a switch, or a goto exists.
2. For function not returning values, if a return statement exists.
3. If function contains static variables.
4. If inline functions are recursive.
32. What are constant arguments?
The qualifier const tells the compiler that the function should not modify the
argument. The compiler will generate an error when this condition is violated.
16 Mark Questions
1. Explain the declaration of a class in c++. How will you define the member
function of a class? Explain.
2. What is the need for parameterized constructor? Explain the function of
constructors with their declaration inside a class
3. Explain all types of inheritance.
4. What is virtual function? Give an example to highlight its need?
5. What is a Friend function? Describe their benefits and limitations? Give
Suitable example.
6. What is meant by function overloading? Write the rules associated with
Function overloading. Give suitable example to support your answer?
7. Explain virtual base classes and virtual function, pure virtual function.
UNIT – III
1. What do you mean by constructor?
10
...
delete[]p; //release memory
Any time we allocate an array of objects via new , we must use [] in the delete
statement. This syntax is necessary because there is no syntactic difference between a
pointer to a thing and a pointer to an array of things.
15. Can you overload the destructor for class?
No. You can have only one destructor for a class. It's always called Fred::~Fred( ). It
never takes any parameters, and it never returns anything. You can't pass parameters
to the destructor anyway, since you never explicitly call a destructor.
16. What is the advantage of using dynamic initialization?
The advantage of using dynamic initialization is that various initialization formats
can be provided using overloaded constructor.
17. Define operator overloading?
A language feature that allows a function or operator to be given more than one
definition. For instance C++ permits to add two variables of user defined types with the
11
16 Mark Questions
UNIT – IV
13
14
15
16 Mark Questions
17
1. Define streams
A stream is a logical device that produces or consumes information. A stream is
linked to a physical device by the I/O system.
A stream is a sequence of bytes. It acts either as a source from which the input
data can be obtained or as a destination to which the O/P data can be sent.
A stream acts as an interface between the program and the I/O devices.
2. What are the two types of I/O operation?
Formatted I/O operation - width( ), precision( ), fill( ), setf( ).
Unformatted I/O operation - cin>>,cout <<,getline( ), write( ).
3. What are the ios format function?
Function Task
width( ) To specify the required field size for displaying an o/p value.
precision( ) To specify the number of digits to be displayed after the decimal
point of float variable.
fill( ) To specify a character that is used to fill the unused portion of a
field.
setf( ) To specify format flags that can control the form of o/p display (ex:
left justification and right justification)
unsetf( ) To clear the flags specified
12. What is the use of passing second parameter to open( ) function? What are
they?
The second argument mode (file mode parameter) specifies the purpose for which
the file is opened. The file mode parameter can take one of constants defined in the class
ios.
Parameter Meaning
ios::app Append the end of file
ios::ate Go to end of file for opening
Ios::binary Binary file
Ios::in Open file for reading only
Ios::nocreate Open fails if the file does not exist
Ios::noreplace Open files if the file already exists
Ios::out Open file foe writing only
19
14. What are the errors we may expect while dealing with the files?
1. A file which we attempting to open for reading does not exist
2. The file name used for a new file may already exist
3. We may attempt an invalid operation such as reading past the end-of-file.
4. There may not be any space in the disk for storing more data
5. We may use an invalid filename
6. We may attempt to perform an operation when the file is not opened for that
purpose
15. What are the error handling functions for files available in C ++?eof( )
1. fail( ) 3. good( )
2. bad( )
16. What are the default actions on file pointers while opening a file?
When a file is opened in read only mode, the input pointer is automatically set at
the beginning so that the file can be read from the start.
Similarly when a file is opened in write only mode the existing contents are
deleted and the output pointer is set at the beginning. This enables to write to the file
from the beginning. If the file is opened in append mode the output pointer is set at the
end of the file.
17.What are the functions in C ++ to manipulate file pointers ?
seekg( ) - moves get pointer (i/p) to a specified location.
seekp( ) - moves put pointer(o/p) to a specified location.
tellg( ) - gives the current position of the get pointer.
tellp( ) - gives the current position of the put pointer.
18. What are the file stream classes in C++?
1. filebuf 2.fstreambase 3. ofstream
2. ifstream 4. fstream
19. What are the file manipulation function in C++?
i. seekg() iii. tellg()
ii. seekp() iv. tellp()
20. What are the file open modes?
Ios::app, ios::binary, ios::out, ios::in, ios::ate, ios::nocreate, ios::noreplace,
ios::trunk.
21. What are the error handling function in C++?
1. eof()
2. fail()
3. bad()
4. good()
20
21
22