0% found this document useful (0 votes)
6 views3 pages

Practice Questions For OOPD 23F 2

Uploaded by

shubhankartiwary
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)
6 views3 pages

Practice Questions For OOPD 23F 2

Uploaded by

shubhankartiwary
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/ 3

Object Oriented Programming & Design -

Monsoon 2023
Final Practice Questions

Student’s Details
Name of the Student:

Roll Number:

Stream:

1 Short Conceptual Questions (3x15=45 points)


There are 20 questions in this section each worth 3 points. You may write the
answers to these questions succinctly.
A1 What will the data type of type T2 be in the following program? Justify.
template <c l a s s T1 , c l a s s T2>
v o i d checkGreaterThan (T1 a , T2 b ) ;

i n t main ( v o i d ) {
c o u t << checkGreaterThan ( 5 , 6 ) ;
c o u t << checkGreaterThan ( 5 , 3 . 2 ) ;
return 0;
}

A2 Is the following program designed correctly? If so, what is the output? If


not so, explain why it is incorrect.
i n t main ( v o i d ) {
v e c t o r <i n t > l i s t { 1 , 2 , 4 , 5 , 6 } ;
f o r ( i n t c t r = 0 ; c t r < l i s t . s i z e ( ) ; c t r ++)
{
i f ( l i s t [ c t r ] % 2 == 0 )
l i s t . push back ( 1 0 ) ;
}
c o u t << l i s t ;
return 0;
}

1
Roll Number:

A3 Is it possible to get the following cast working?


c l a s s MyBase
{
public :
v o i d t e s t ( ) {}
};
c l a s s MyChild : p u b l i c MyBase { } ;
i n t main ( v o i d ) {
MyChild ∗ c h i l d = new MyChild ( ) ;
MyBase ∗ b a s e = d y n a m i c c a s t <MyBase∗>( c h i l d ) ;
/∗ Use b a s e t o h a n d l e f u r t h e r ∗/
return 0;
}

A4 Consider a case of two distinct (unrelated) programs communicating via


pipes. Does the stream of data go via the Virtual File System? If so, what
will the inode point to?
A5 Consider the conda environment that is very frequently used to set up
python and its related libraries. Suppose you activate it and its python.
You now enter the python shell and run a command. Where is this com-
mand interpreted, and how is the system ensuring that the right python
version is being used?
A6 Consider a program that requires some dependency software that is dif-
ficult to install. Is there any way you can transfer it easily to another
machine?
A7 Suppose you are checking at a number of places if a linked list has non-
integer value, and if so, you are doing a different operation. Is it a good
idea to use lambda functions to do this check?
A8 Which of the following functions is going to be faster and why?
c l a s s Stack {
/∗ s t a n d a r d s t a c k o p e r a t i o n s ∗/
int push with exception ( int val ) {
i f ( s i z e > 100) {
throw OverFlowException ;
}
a r r [ s i z e ++] = v a l ;
}
int push without exception ( int val ) {
i f ( s i z e > 100) {
r e t u r n −1;
}
a r r [ s i z e ++] = v a l ;
return 0;
}
};

2
Roll Number:

A9 What will be the output, and which of the following accesses is going to
be faster and why?
i n t main ( v o i d ) {
v e c t o r <i n t > x ;
c o u t << x . a t ( 1 ) ;
}

i n t main ( v o i d ) {
v e c t o r <i n t > x ;
c o u t << x [ 1 ] ;
}

A10 Consider an STL iterator that requires you to get the elements in reverse
order. Is this possible, and how would you access the next element?

A11 Consider an STL container that has been created. How would you deal-
locate its memory, and handle its memory leaks?
A12 Compare the speed of the following codes:
c l a s s abcd {
public :
int x ;

i n t add ( v a l ) {
return x + val ;
}

i n t o p e r a t o r +( v a l ) {
return x + val ;
}
};
i n t main ( v o i d ) {
abcd a ;
a . x = 5;
c o u t << a . add ( 1 0 ) ;
c o u t << a + 1 0 ;
return 0;
}

You might also like