0% found this document useful (0 votes)
5 views2 pages

Quiz 2

This document is a quiz for the Object Oriented Programming course at the Indian Institute of Technology (ISM), Dhanbad, covering various topics such as exception handling, virtual functions, file operations, and serialization. It includes multiple-choice questions and code snippets requiring analysis to determine outputs and correct syntax. The quiz is designed for B.Tech, Int. M.Tech, and M&C students and is timed for 20 minutes.

Uploaded by

prabidushk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Quiz 2

This document is a quiz for the Object Oriented Programming course at the Indian Institute of Technology (ISM), Dhanbad, covering various topics such as exception handling, virtual functions, file operations, and serialization. It includes multiple-choice questions and code snippets requiring analysis to determine outputs and correct syntax. The quiz is designed for B.Tech, Int. M.Tech, and M&C students and is timed for 20 minutes.

Uploaded by

prabidushk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

INDIAN INSTITUTE OF TECHNOLOGY (ISM), DHANBAD


WINTER SESSION: 2022-23 [QUIZ-2]
Name of the Student: Admission No:

Subject: Object Oriented Programing [CSE202] Time: 20 Minutes


Examination: All (B.Tech, Int. M.Tech, M&C) Total Marks: 20

Note: Answer ALL questions

1. What would be the output of the following code snippets? [5 M]


i) #include <iostream> ii) int main()
#include <exception> { double Op1 = 10, Op2 = 5, Res;
using namespace std; char Op;
struct MyException : public exception try {
{ const char * what () const throw () if (Op != '+' && Op != '-' && Op != '*' &&
{ return "C++ Exception"; } }; Op != '/')
int main() { throw Op;
try switch(Op) {
{ throw MyException(); } case '+': Res = Op1 + Op2;
catch(MyException& e) break;
{ cout << "Exception caught" << case '-': Res = Op1 - Op2;
std::endl; break;
cout << e.what() << std::endl; } case '*': Res = Op1 * Op2;
catch(std::exception& e) break;
{ } case '/': Res = Op1 / Op2;
} break; }
cout << "\n" << Op1 << " " << Op << " "<<
a) C++ Exception b) Exception caught Op2 << " = " << Res; }
c) Exception caught C++ Exception catch (const char n)
d) C++ Exception Exception caught { cout << “\n” << " is not a valid operator";
e) error }return 0; }
a)15 b)5 c)2 d) is not a valid operator e) error

iii) #include<iostream> iv) How to handle error in the destructor?


using namespace std; a) throwing
class Base { b) terminate
public: c) both throwing & terminate
virtual void show() { cout<<" In Base "; } }; d) none of the mentioned
class Derived: public Base {
public: v) #include<iostream> #include "math.h"
void show() { cout<<"In Derived "; } }; using namespace std;
int main(void) double MySqrt(double d)
{ Base *bp, b; Derived d; bp = &d; { if (d < 0.0)
bp ->show(); bp = &b; throw "Cannot take sqrt of negative number";
bp->show(); return sqrt(d); }
return 0; } int main()
a) In Base In Base { double d = 5;
b) In Base In Derived cout << MySqrt(d) << endl; return 0; }
c) In Derived In Derived
a) 5 b) 2.236 c) Error
d) In Derived In Base
d) Cannot take sqrt of negative number
2. Choose the appropriate option(s). [5 M]
(i) What does a virtual function ensure for an object, among the following?
a) Correct method is called, regardless of the class defining it
b) Correct method is called, regardless of the object being called
c) Correct method is called, regardless of the type of reference used for function call
d) Correct method is called, regardless of the type of function being called by objects
(ii) Where the virtual function should be defined?
a) Twice in base class b) Derived class c) Base class and derived class d) Base class
(iii) Which is correct syntax ?
a) myfile:open ("example.bin", ios::out); b) myfile.open ("example.bin", ios::out);
c) myfile::open ("example.bin", ios::out); d) myfile.open ("example.bin", ios:out);
(iv) It is not possible to combine two or more file opening mode in open () method. [ True / False ]
(v) Streams that will be performing both input and output operations must be declared as class
a. iostream b. fstream c. stdstream d. Stdiostream
3. (i) You have opened two files for writing using an instance of the fstream class. The first file, called
data.txt, is opened in the text mode, while second file, called data.dat, is opened in the binary mode. Assume
that a float value requires 8 bytes on the platform. You have written the data 5.263 in both files. How many
bytes will the two files occupy on the disk? Ignore any control characters (such as the newline character)
that may have been added by default to the file. [1 + 1 = 2 M]
Size of data.txt: 5 bytes Size of data.dat: 8 bytes
(ii) Which of the following has been deprecated in ISO C++11? [1 M]
a. The use of multiple catch blocks paired with a single try block
b. The use of multiple throw statements in a single try block
c. The use of throw clause in function headers to restrict thrown exception types
d. The use of the “catch-all-exceptions” catch block (i.e., the catch (…) { } block)
(iii) You have defined three catch blocks paired with the same try block. The exception types associated
with the three catch blocks are X, Y and Z respectively. Assuming that X is a derived class of Y, and Y is
a derived class of Z, which order of the catch blocks can ensure the possibility of each one of them being
invoked under certain circumstances? [1 M]
a. The catch block with type X must be defined first, the other two blocks can be in any order
b. The catch block with type Z must be defined first, the other two blocks can be in any order
c. The catch block with type X, followed by that with type Y, followed by that with type Z
d. The catch block with type Z, followed by that with type Y, followed by that with type X
(iv) Serialization involves [1 M]
a. Printing the values of an object’s public fields
b. Saving the values of an object’s public and protected fields in a text file

c. Saving the full state of an object (including private and protected members) in a binary file
d. Accessing the private fields of an object which is declared as a field inside another class
4. Choose the appropriate option(s). [5 M]
Which statements are true about an abstract class?
a) Abstract class has at least one pure virtual function. b) Pointer for an abstract class can be created
c) Object of an abstract class cannot be created. d) All are correct
In a class, pure virtual function is used
a) To create an interface b) To make a class abstract
c) To force derived class to implement the pure virtual function d) All the above
Which is/are the correct declaration(s) of pure virtual function in C++?
virtual void func= 0; b) virtual void func()= 0; c) virtual void func(){0}; d) void fun()=0;
If inner catch block is unable to handle the exception thrown then
Program stops abnormally
The compiler will check for appropriate catch handler of the outer try block
The compiler will not check for appropriate catch handler of the outer try block
The unexpected() function is called
Which of the following is not used as a file opening mode?
ios::trunk b) ios::binary c) ios::in d) ios::ate e) All of these

***************** THE END ********************

You might also like