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

Document 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)
10 views3 pages

Document 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 Consider a function where mergesort is being applied not on a single array,


but on two distinct arrays. The output of the mergesort is a single merged
sorted array. The two arrays would give a single array as output. How
would you create and use a template-based mergesort in this case?
A2 Assume that we are using the STL’s algorithm library to perform a linear
search. Assume that we have a total of 1000 objects of the same class.
One developer utilizes a vector to store them, whereas another developer
utilizes a heap. Which of them would be faster and why?
A3 Compare both the execution speed AND compilation speed of the follow-
ing two programs:
Program p1 . cpp

i n t main ( v o i d ) {
v e c t o r <i n t > v ( 1 0 0 , 5 ) ;
f o r ( i n t i = 0 ; i < 1 0 0 ; i ++) {
v[ i ] = i ;
}
return 0;
}

1
Roll Number:

Program p2 . cpp

i n t main ( v o i d ) {
v e c t o r <i n t > v ( ) ;
f o r ( i n t i = 0 ; i < 1 0 0 ; i ++) {
v . push back ( i ) ;
}
return 0;
}

A4 Consider the following C++ program and a bash script used together:
Program p1 . cpp

i n t main ( v o i d ) {
v e c t o r <i n t > v ( 1 0 0 , 5 ) ;
f o r ( i n t i = 0 ; i < 1 0 0 ; i ++) {
v[ i ] = i ;
c o u t << rand ( ) << e n d l ;
}
return 0;
}
Program s c r i p t . sh
. / a . out > out . t x t
g r e p ”1” out . t x t

Is there a way to speed up the execution of the above programs?


A5 Consider a command you are designing which needs to accept a (> 30)
large number of behaviors depending on the argument. How would you
go about designing it? Name the function that you would use, along with
the reason behind it.
A6 Consider a case where you need to mass rename files, for example, all files
named as “abc1.txt”, “abc2.txt”, ..., would be renamed as “def1.txt”,
“def2.txt”,... Which command(s) in bash would you use to do it?
A7 Consider a filesystem that has empty space, but is still not letting you
add content to a specific file, even though you have sufficient permissions.
What is the problem here, and can you suggest a possible solution?
A8 Suppose user U1 has created a file, but wants to allow user U2 and U3 to
modify it, but not other people. What can user U1 do to facilitate this?
A9 Consider a situation where you want to enter into a directory, but by
mistake open it using a text editor. Will this file open? If so, what will
you see in this file?
A10 Assume that there are a sequence of rectangles that need to be sorted.
You utilize a class of rectangles to model them. The sorting has to be
done based on their bottom-left coordinates, followed by bottom-right
coordinates in case of a tie. Is it possible to use an STL sort algorithm to
do this, and if so, how?

2
Roll Number:

A11 Suppose you want to use a reverse iterator instead of a standard iterator
on a vector. Is it possible to use it by defining the iterator’s type as auto?

A12 Suppose you need to speed up the execution of a specific process, when it
is slowed down by the functioning of other processes. How can you do it,
and is there anything specific you need to ensure in order to do it?
A13 Consider two functions A() and B() that works on a global variable x with
different threads. What is the output of the following program?
int x = 0;
A( ) {
x++;
}
B( ) {
x−−;
};
i n t main ( v o i d ) {
Thread t = new Thread (A ( ) ) ;
Thread s = new Thread (B ( ) ) ;
c o u t << x ;
}

You might also like