Tuesday, October 29, 2013

Programming (C, C++ ...) 02

11. Assume that we have constructor functions for both base class and derived class. Now consider the declaration in main( ). Base * P = new Derived; in what sequence will the constructor be called? [Paper III June 2012]
(A) Derived class constructor followed by Base class constructor.
(B) Base class constructor followed by derived class constructor.
(C) Base class constructor will not be called.
(D) Derived class constructor will not be called.

12. printf(“%c”, 100); [Paper II June 2012]
(A) prints 100
(B) prints ASCII equivalent of 100
(C) prints garbage
(D) none of the above

13. Which API is used to draw a circle ? [Paper II December 2012]
(A) Circle( )                 (B) Ellipse( )
(C) RoundRect( )         (D) Pie( )

14. Which of the following are two special functions that are meant for handling exception, that occur during exception handling itself? [Paper II December 2012]
(A) void terminate ( ) and void unexpected ( )
(B) Non void terminate ( ) and void unexpected ( )
(C) void terminate ( ) and non void unexpected ( )
(D) Non void terminate ( ) and non void unexpected ( )

15. Match the following with respect to C++ data types: [Paper II December 2012]
a. User defined type 1. Qualifier
b. Built in type 2. Union
c. Derived type 3. Void
d. Long double 4. Pointer
Code :
       a b c d
(A) 2 3 4 1
(B) 3 1 4 2
(C) 4 1 2 3
(D) 3 4 1 2

16. Enumeration is a process of [Paper II December 2012]
(A) Declaring a set of numbers
(B) Sorting a list of strings
(C) Assigning a legal values possible for a variable
(D) Sequencing a list of operators

17. Which of the following mode declaration is used in C++ to open a file for input?
[Paper II December 2012]
(A) ios : : app
(B) in : : ios
(C) ios : : file
(D) ios : : in

18. What is the result of the following expression? [Paper II December 2012]
(1 & 2) + (3 & 4)
(A) 1
(B) 3
(C) 2
(D) 0


SOLUTIONS

11. B
Here A derived class object is created first and then assigned to a base class pointer. Whenever a derived class object is created, the base class constructor gets called first and then the derived class constructor.

12. B

13. B

14. A
The visual C++ Standard requires that unexpected() is called when a function throws an exception that is not on its throw list.
The terminate( ) function is used with visual C++ exception handling and is called in the following cases:

  • A matching catch handler cannot be found for a thrown C++ exception.
  • An exception is thrown by a destructor function during stack unwind.
  • The stack is corrupted after throwing an exception.

Both the functions does not return anything.

15. A

16. C
An enum is a user-defined type consisting of a set of named constants called enumerators. The colors of the rainbow would be mapped like this.:
              enum rainbowcolors { red,  orange, yellow, green,  blue, indigo, violet)  }
Now internally, the compiler will use an int to hold these and if no values are supplied, red will be 0, orange is 1 etc.

17. D
In order to open a file with a stream object we use its member function open():
          open (filename, mode);
Where filename is a null-terminated character sequence of type const char * (the same type that string literals have) representing the name of the file to be opened, and mode is an optional parameter with a combination of the following flags:

  • ios::in    Open for input operations.
  • ios::out    Open for output operations.
  • ios::binary  Open in binary mode.
  • ios::ate    Set the initial position at the end of the file. If this flag is not set to any value, the initial position is the beginning of the file.
  • ios::app    All output operations are performed at the end of the file, appending the content to the current content of the file. This flag can only be used in streams open for output-only operations.
  • ios::trunc    If the file opened for output operations already existed before, its previous content is deleted and replaced by the new one.

18. D
& represents bitwise AND. Converting the given values in the expression to 4 bit binary we have:
(1 & 2) + (3 & 4) = (0001 & 0010) + (0011 & 0100)
                            = (0000) + (0000)
                            = 0 + 0
                            = 0

Sunday, August 18, 2013

Operating Systems 03

21. Resources are allocated to the process on non-shareable basis is
[Paper II June 2012]
(A) mutual exclusion
(B) hold and wait
(C) no pre-emption
(D) circular wait

22. Cached and interleaved memories are ways of speeding up memory access between CPU’s and slower RAM. Which memory models are best suited (i.e. improves the performance most) for which programs?     [Paper II June 2012]
(i) Cached memory is best suited for small loops.
(ii) Interleaved memory is best suited for small loops
(iii) Interleaved memory is best suited for large sequential code.
(iv) Cached memory is best suited for large sequential code.
(A) (i) and (ii) are true.
(B) (i) and (iii) are true.
(C) (iv) and (ii) are true.
(D) (iv) and (iii) are true.

23. Consider the following page trace: 4,3, 2, 1, 4, 3, 5, 4, 3, 2, 1, 5
Percentage of page fault that would occur if FIFO page replacement algorithm is used with number of frames for the JOB m = 4 will be                       [Paper II June 2012]
(A) 8                (B) 9
(C) 10             (D) 12


24. Given memory partitions of 100 K, 500 K, 200 K, 300 K and 600 K (in order) and processes of 212 K, 417 K, 112 K, and 426 K (in order), using the first-fit algorithm, in which partition would the process requiring 426 K be placed ?                  [Paper II December 2012]
(A) 500 K
(B) 200 K
(C) 300 K
(D) 600 K

25. The problem of indefinite blockage of low-priority jobs in general priority scheduling algorithm can be solved using:   [Paper II December 2012]
(A) Parity bit
(B) Aging
(C) Compaction
(D) Timer

26. Which of the following memory allocation scheme suffers from external fragmentation?
[Paper II December 2012]
(A) Segmentation
(B) Pure demand paging
(C) Swapping
(D) Paging

27. In UNIX, which of the following command is used to set the task priority?      
[Paper II December 2012]
(A) init
(B) nice
(C) kill
(D) PS




SOLUTIONS
21. A

22.

23. C
The first 4 page references will cause page faults and they are brought into the 4 page frames available. The sequence is shown below
4 - page fault, brought to frame. Page Frame : 4
3 - page fault, brought to frame. Page Frame : 4, 3
2 - page fault, brought to frame. Page Frame : 4, 3, 2
1 - page fault, brought to frame. Page Frame : 4, 3, 2, 1
4 - available in the frame, no page fault occurs. Page Frame : 4, 3, 2, 1
3 - available in the page frame, no page fault occurs. Page Frame : 4, 3, 2, 1
When the fame is full and a page fault occurs, then the page that was first brought in is removed and the referred page is brought in to the frame.
5 - not in the page frame, page fault. 4 is removed and 5 is brought is. Page Frame : 5, 3, 2, 1
4 - not in the page frame, page fault. 3 is removed and 4 is brought is. Page Frame : 5, 4, 2, 1
3 - not in the page frame, page fault. 2 is removed and 3 is brought is. Page Frame : 5, 4, 3, 1
2 - not in the page frame, page fault. 1 is removed and 2 is brought is. Page Frame : 5, 4, 3, 2
1 - not in the page frame, page fault. 5 is removed and 1 is brought is. Page Frame : 1, 4, 3, 2
5 - not in the page frame, page fault. 4 is removed and 5 is brought is. Page Frame : 1, 5, 3, 2

24. A
100 K, 500 K, 200 K, 300 K and 600 K (in order) and processes of 212 K, 417 K, 112 K, and 426 K
According the to the first fit algorithm, the memmory will be scanned to find out the memory portion that is enough for the arriving process, The first such portion found is allocated to the process. In the given example when process of size 212K arrives it is placed in memory portion with size 500K. This leaves an unused space of 288K. Now 417K arrioves it is placed inportion with size 600K, leaving 183K unused. Now 112K arrives and this can be placed in the un used sopace of 183K. Atlast the process of 426K arrives, we dont have memory block large enough to hold this, so we need to remove some already allocated process and allocate that block. 500k block is the one suitable if we do a linear search.
25. B

26. A

27. B
init - Init is the parent of all processes. Its primary role is to create processes from a script stored in the file
nice - run a program with modified scheduling priority
kill - terminate a process

ps - report process status