Subject Name: OBJECT ORIENTED PROGRAMMING DESIGN
Subject Code: CS T33:
2 MARKS AND 11 MARKS
UNIT IV
Files: File Stream classes – Checking for errors – file opening modes – file pointers and
manipulators – manipulators with arguments – read and write operations – Binary and ASCII
files – Random access operation – Error handling functions – command line arguments –
stdstreams.
Generic Programming with Templates: Generic Functions- Need of Template – Normal
function template – class template with more parameters – Function template with more
parameters, overloading of function templates, class template with overloaded operators – class
templates and inheritance.
Exception Handling: Fundamentals of Exception Handling – Catching Class Types – Using
Multiple catch statements – Catching All Exception – Rethrowing Exception – Specifying
Exception – Exceptions in constructors and destructors – controlling uncaught Exceptions –
Exception and operator overloading – Exception and inheritance – Class Template and Exception
handling.
PART A – 2 MARK QUESTIONS
1. What are the various traditional error handling methods?
The various traditional error handling methods are,
i. Returning error number.
ii. Global flag manipulation.
iii. Abnormal termination.
,CS T33 OBJECT ORIENTED PROGRAMMING AND DESIGN Y2/S3
2. What is the importance of exceptional handling?
The importance of exceptional handling is,
i. Divide the error handling.
Ii.To provide unconditional termination and programmer preferred termination
iii. For separating error reporting and error handling.
iv. To solve the object destroy problem.
3. What are the three keywords used for exception handling mechanism?
The three keywords used for exception handling mechanism are,
i. try : for indicating program area where the exception can be thrown.
ii. throw: for throwing an exception.
iii. catch: for taking an action for specific exception.
4. What is the use of unexpected function?
The unexpected function is called when a function throws an exception not listed in its
exception specification. Internally, it calls the terminate function to terminate the
program execution. The function set unexpected () is used to call our own unexpected
function in place of the built-in unexpected function.
5. What are the challenges in the exception handling mechanism?
The challenges in the exception handling mechanism are,
i. Finding proper catch block.
ii. Finding proper catch block for polymorphic object.
iii. Backtracking till the beginning of the try block.
6. Why Templates are used in C++?
The Templates are used to develop reusable software component such as functions,
classes, etc. Templates allow the construction of a family of templates functions and
classes to perform the same operations on different data types.
7. What are rules for invalid function template declaration?
The rules for invalid function template declaration are,
i. No-argument template function.
ii. Template–type argument unused.
iii. Usage of partial number of template arguments.
8. Write the syntax for function Template.
,CS T33 OBJECT ORIENTED PROGRAMMING AND DESIGN Y2/S3
The syntax for function Template is,
Template <class T, .......... >
Return Type Fun_Name (arguments)
{
………. // body of the template
}
9. What are the error handling function in C++?
The error handling function in C++ is,
i. eof()
ii. fail()
iii. bad()
iv. good()
10. What are the rules for virtual function?
The rules for virtual function are,
i. They cannot be static members.
ii. They are access by using object pointers.
iii. A virtual function can be a friend of another class.
11. What are Streams?
Stream is a mechanism, which supplies the input data to a program and presents the
processed data in the desired form.
12. What are the file stream classes in C++?
The file stream classes in C++ are,
i. filebuf
ii. fstreambase
iii. ifstream
iv. ofstream
v. fstream
13. List out the ways of Class Template inheritance.
The ways of Class Template inheritance are,
i. Derive a class template from a base class, which is a template class
ii. Derive a class template from the base class, which is a template class, add more
template members in the derived class
iii. Derive a class template from a base class which is not a template class, and
add template members to that class
iv. Derive a class template from a base class which is a template class and restrict
the template feature.
, CS T33 OBJECT ORIENTED PROGRAMMING AND DESIGN Y2/S3
14. What are the functions of ios classes?
The functions of ios classes are,
Function Task Performed
width() Specifies the required number of
fields to be used while displaying
the output value.
precision() Specifies the number of digits to
be displayed after the decimal
point
fill() Specifies a character to be used to
fill the unused area of a field.
setf() Sets format flag that control the
form of output display
unset() Clears the specified flag
15. What are the modes used file stream class?
The modes used file stream class is,
i. in – open for reading
ii. out – open for writing
iii. app – all write occur at end of file
iv. trunc – truncate the file if already exits
v. nocreate – open fails if file does not exits
vi. noreplace – open fails if file already exits
vii. binary – open as a binary file
16. What is get () and put () functions?
get() is a member function of a stream class fstream and is used to read a single
character from a file. put() is a member function of a stream class fstream and is used to write
a single character to the file.
17. What are two types of file pointers used in C++?
The two types of file pointers used in C++ are,
i. get pointer – specifies a location from where the current reading operation is initiated
ii. put pointer - specifies a location from where the current writing operation is initiated