Practice Questions For OOPD 24-1
Practice Questions For OOPD 24-1
Roll Number:
Stream:
Suppose we want to use a more general technique of doing the above loop, where “general” implies
that it works with other containers. How would you implement this technique? Your code must avoid
as much verbose syntax as possible.
A2 Consider a case where the output of a function is itself a function of two distinct template types. Is
there a way to do this?
A3 Suppose a company enforces a code standard where usage of templates is not allowed. Can you
implement the same functionality that templates allow in functions? If so, how?
A4 Consider a file system that allows inodes with only one level of indirection. What will be the disad-
vantage of this filesystem?
A5 Suppose a kernel designer decides that only one filesystem is sufficient, and discards use of virtual
filesystem. Can this be a functional kernel? Is there any other functionality that would be affected?
A6 Assume that we first create a vector and then a set. In each of them, you need to insert an element,
with both the positions/numbers being uniformly distributed. We decide to use first the individual
container’s insert, and then the insert algorithm. Which of them is faster and why?
A7 Consider a situation where we have installed a program called “abc”. Trying to execute it gives the
error “Permission denied”. How would you resolve the above problem? You need to explain the reason
and then give the exact command.
A8 Assume that we want to create an object of HashMap (present in STL) where the key can be either
an object of Class1 or Class2. Is this possible, and if so, what can you do to enable it?
1
A9 Consider a situation where you create a linked list using pointers. Due to a variety of performance
reasons, the programming team decides to avoid using a higher-level object such as STL containers.
Is there still a way to ensure deallocation of memory is done properly by the programmers? You must
mention the concepts and initialize one such data structure.
A10 Consider a situation where you want to write programs in the form of layers. Is inheritance the right
way to implement it? If so, give an example, If not so, explain the alternative strategy.
B4 Consider two programs P1 and P2 both of which implement sorting of arrays of ints and floats. P1
uses templates to do the sorting, whereas P2 uses function overloading to write the two functions.
Which among P1 and P2 have higher compilation time, and specify that who among P1’s int sort,
P1’s float sort, P2’s int sort and P2’s float sort are the fastest and slowest respectively? You need to
justify the reason.
B5 The Indian immigration system classifies countries into trusted and distrusted categories. Citizens of
trusted countries get a visa on arrival, whereas citizens of distrusted countries do not get. There are
also different categories of visa, such as tourist, work, education. Note that every visa must belong to
some category. Furthermore, anybody making a false claim is noted down, and further visa requests
are denied to them. Design a class structure to model the visas issued by the immigration system.
B6 In the above question, the application is considered critical, as a decision has major impact on the
security. This requires unit testing of various classes that deal with issuing of visas. How would you
go about testing each of such classes? You need to show the structure of any extra code that might be
needed.