0% found this document useful (0 votes)
8K views19 pages

MCQs

The programmer is conceptualizing an object-oriented program to create a database of animals in a zoo. Each animal (dog, lion, zebra) is an object of class "Animal" with attributes like isHerbivorous, color, and isNocturnal. The best way to structure the program is to have one Animal class with dog, lion, and zebra as objects that contain the data members.

Uploaded by

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

MCQs

The programmer is conceptualizing an object-oriented program to create a database of animals in a zoo. Each animal (dog, lion, zebra) is an object of class "Animal" with attributes like isHerbivorous, color, and isNocturnal. The best way to structure the program is to have one Animal class with dog, lion, and zebra as objects that contain the data members.

Uploaded by

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

1. A programmer is making a database of animals in a zoo and their properties.

The
possible animals are dog, lion and zebra. Each one has as attributes isHerbivorous,
colour and isNocturnal. She uses the object oriented programming paradigm for this.
How will she conceptualize the system?

(a) class: Animal; objects: dog, lion and zebra; data members: is Herbivorous,
colour and is
Nocturnal
(b)class: Animal; objects: is Herbivorous, colour and is Nocturnal; data
members: dog, lion and zebra
(c)classes: dog, lion and zebra; objects: Animal; data members: is Herbivorous,
colour and is
Nocturnal
d)None of these

Ans a)class: Animal; objects: dog, lion and zebra; data members: is Herbivorous,
colour and is
Nocturnal
class is a template(logical entity) , objects are instances of class(real entity).

2. A programmar mistakenly uses the ‘for’ keyword for loops. Due to distraction
Ravi writes ‘gor’ instead of ‘for’. What will this result to?

A. The code will not compile


B. The code will give an error while in execution
C. The code may work for some inputs and not for others
D. It will create no problems.

Ans.A The code will not compile

3. A librarian has to rearrange the library books on a shelf in a proper order at


the end of each day. Which of thefollowing sorting techniques should be the
librarian's ideal choice?

A. Bubble Sort
B. Insertion Sort
C. Selection sort
D. Heap Sort

Ans: B. Insertion Sort

4. A programmar has a 10,000 line code. She is trying to debug it. She knows there
is a logical error in the first 25 lines of the code. Which of the following
options will be an efficient way of debugging?
A. Compile the whole code and step into it line by line
B. Use an interpreter on the first 25 lines
C. Compile the whole code and run it
D. None of these

Ans:: B ( Use an interpreter on the first 25 lines )

5. A function that takes as input n and calculates the sum of first


n natural numbers.

function sum( n )
{
if(??)
return 1
else
return (n + sum(n-1))
end
}
Fill in ?? in the code.
Option 1 : n equals 1
Option 2 : n equals 2
Option 3 : n >= 1
Option 4 : n > 1

Ans:: Option 1

6. A function that takes as input n, an even integer and calculates


the sum of first n even natural numbers.

function sum( n )
{
if(n equals 2)
return 2
else
return (n + sum(n-2))
end
}
It calls the function by the statement, sum(30). How many times will the function
sum be called to compute this sum.

Option 1 : 1
Option 2 : 30
Option 3 : 15
Option 4 : 16

Ans:: Option 3::

7. Consider the following pseudo-cod


Class brush
{
Private:
Integer size,colorcode;
Function getdata(){…..}//statment1
Public:
Integer name //statement-2
Function putdata(){….}
}
Function main
{
Brush b1,b2
Print b1.name//statement 3
B2.getdata()//statement 4
}

Choose the correct answer. A pseudo-code which is similar to that of C++ and self-
explanatory. An accessible member function or data member for an object are
accessed by the statement
Objectname.functionname or objectname.datamembername respectively.
a) Statment1
b) Statment2
c) Statment3
d) Statment4

Ans:: d
Explaination : Since, get data is private

8. A data type is stored as an 6 bit signed integer. Which of the following cannot
be
represented by this data type?

Option 1 : -12 Option 2 : 0 Option 3 : 32 Option 4 : 18

Ans:: option 3:: 32

9. An integer X is saved as an unsigned 8-bit number, 00001011.What is X

A. 22
B. 11
C. 10
D. None of these

Ans::: B

10.A stack is implemented as a linear array A[0…N-1]. Noor writes the following
functions for popping an element from the stack.
function POP( top, N )
{
if(X)
{
top = top – 1
}
else
{
print “Underflow”
}
return top
}Fill in the condition X
Option 1 : top< N-1 Option 2 : top Option 3 : top>1 Option 4 : top >= 0

Ans:: option 4

11. What is the value 0f 10101 in decimal number system..

A. 42
B. 18
C. 20
D. 21

Ans:: B. 18

12. What is the output of the following pseudo code ?


int a = 456, b, c, d = 10;
b = a / d;
c = a - b;
print c

A. 411.4

B. 411

C. 410.4

D. 410

Ans:: B

13. Stack is useful for implementing

Option 1 : radix search


Option 2 : breadth first search
Option 3 : recursion
Option 4 : none of these

Ans:: Option 3

14. A programmer wants to find the largest number in a given list of 20 numbers.
Which of the
following is an efficient approach to do this?

Option 1 : Use bubble sort to sort the list in descending order and then print the
first number of the series.
Option 2 : Use selection sort to sort the list in descending order and then print
the first number of the series.
Option 3 : Implement one iteration of selection sort for descending order and print
the first number in the series.
Option 4 : None of these

Ans:: Option 3

15. A full binary tree with n leaves contains

Option 1 : 2n + 1 nodes
Option 2 : log2 n nodes
Option 3 : 2n – 1 nodes
Option 4 : 2n nodes

Ans:: Option 3

16. wants to print the following pattern on the screen:


1
1 2
1 2 3

He writes the following program:

integer i = 1 // statement 1
while ( i <= 3 )
{
int j // Statement 2
while ( j <= i ) // Statement 3
{
print j
print blank space
j = j + 1 // Statement 4
}
print end-of-line \takes the cursor to the next line
i = i + 1
}
Will this program function correctly? If not which one statement will you modify to
make the program function correctly?
Option 1 : Statement 1
Option 2 : Statement 2
Option 3 : Statement 3
Option 4 : Statement 4
Option 5 : Program does not have error.

Ans:: Option 2

17. A programmer writes an efficient program to sum two square diagonal matrices
(matrices with
elements only on diagonal). The size of each matrix is nXn. What is the time
complexity
of Vrinda's algorithm?

Option 1 : θ(n^2) Option 2 : θ(n) Option 3 : θ(n*log(n))


Option 4 : None of these

Ans:: Option 2

18. Which of the following cannot be inherited ?

A. Public
B. Private
C. Protected and Private
D. Protected

Ans:: B

19. : What is the default scope of fields in a class of a C++ program?

1. Protected
2. Public
3. Private
4. None of these

Ans:: 3

20. Consider an array on which bubble sort is used. The bubble sort would compare
the
element A[x] to which of the following elements in a single iteration.

Option 1 : A [x+1]
Option 2 : A [x+2]
Option 3 : A [x+2x]
Option 4 : All of these.
Ans:: Option 1

21. A sorting algorithm iteratively traverses through a list to exchange the first
element
with any element less than it. It then repeats with a new first element. What is
this
sorting algorithm called?

Option 1 : insertion sort


Option 2 : selection sort
Option 3 : heap sort
Option 4 : quick sort

Ans:: Option 2

22. A programmer writes a program to find an element in the array A[5] with the
following
elements in order: 8 30 40 45 70. She runs the program to find a number X. X is
found
in the first iteration of binary search. What is the value of X?

Option 1 : 40
Option 2 : 8
Option 3 : 70
Option 4 : 30

Ans:: Option 1

23. wants to make a program to print the sum of all perfect cubes, where the value
of the cubes go from 0 to 100. She writes the following program:
integer i = 0, a // statement 1
integer sum = 0;
a = ( i * i * i )
while ( i < 100 ) // statement 2
{
sum = sum + a // statement 3
i = i + 1
a = ( i * i * i ) // statement 4
}
print sum
Does this program have an error? If yes, which one statement will you modify to
correct
the program?

Option 1 : Statement 1
Option 2 : Statement 2
Option 3 : Statement 3
Option 4 : Statement 4

Ans:: Option 2

24. A programmer wants to make a program to print the sum of square of the first 5
whole numbers
(0...4). She writes the following program:
integer i = 0 // statement 1
integer sum = 0 // statement 2
while ( i < 5 ) // statement 3
{
sum = i*i // statement 4
i = i + 1 // statement 5
}
print sum // statement 6
Is her program correct? If not, which statement will you modify to correct it?

Option 1 : No error, the program is correct.


Option 2 : Statement 1
Option 3 : Statement 4
Option 4 : statement 6

Ans:: Option 3

25. Assume the following precedence (high to low). Operators in the same row have
the same
precedence:
(.)
* /
+ -
AND
OR
For operators with equal precedence, the precedence is from left-to-right in
expression.
integer a = 40, b = 35, c = 20, d = 10
Comment about the output of the following two statements:
print a * b / c – d

print a * b / (c - d)

Option 1 : Differ by 80
Option 2 : Same
Option 3 : Differ by 50
Option 4 : Differ by 160

Ans:: Option 1

26. A programmer is making a questionnaire of True-false questions. She wants to


define a data-type
which stores the response of the candidate for the question. What is the most-
suited
data type for this purpose?
Option 1 : integer Option 2 : boolean Option 3 : float Option
4 :character

Ans:: Option 2

27. Two programmers asked to write the code to evaluate the following
expression:
a - b + c/(a-b) + (a-b)2
Pankaj writes the following code statements (Code A):
print (a-b) + c/(a-b) + (a-b)*(a-b)
Mythili writes the following code statements (Code B):
d = (a-b)
print d + c/d + d*d
If the time taken to load a value in a variable, for addition, multiplication or
division
between two operands is same, which of the following is true?
Option 1 : Code A uses lesser memory and is slower than Code B
Option 2 : Code A uses lesser memory and is faster than Code B
Option 3 : Code An uses more memory and is faster than Code B
Option 4 : Code A uses more memory and is slower than Code B

Ans:: Option 1

28.
While calculating time complexity of an algorithm, the designer concerns
himself/herself primarily with the run time and not the compile time. Why?

Option 1 : Run time is always more than compile time.


Option 2 : Compile time is always more than run time.
Option 3 : Compile time is a function of run time.
Option 4 : A program needs to be compiled once but can be run several times.

Ans:: Option 4

29. Which of the following sorting algorithms yield approximately the same worst-
case and
average-case running time behaviour in O (n log n)?

Option 1 : Bubble sort and Selection sort


Option 2 : Heap sort and Merge sort
Option 3 : Quick sort and Radix sort
Option 4 : Tree sort and Median of- 3 Quick sort

Ans:: Option 2

30. Which of the given option is not a Datatype??

A. Integer
B. Character
C. Boolean
D. Array

Ans:: D.

31. Two programmes are asked to write a program to sum the rows of a 2X2 matrices
stored
in the array A.
Ravi writes the following code (Code A):
for n = 0 to 1
sumRow1[n] = A[n][1] + A[n][2]
end
Rupali writes the following code (Code B):
sumRow1[0] = A[0][1] + A[0][2]
sumRow1[1] = A[1][1] + A[1][2]
Comment upon these codes (Assume no loop-unrolling done by compiler):
Option 1 : Code A will execute faster than Code B.
Option 2 : Code B will execute faster than Code A
Option 3 : Code A is logically incorrect.
Option 4 : Code B is logically incorrect.
Ans:: Option 2

32. Which of the following method is sorting not possible ??

A. Insertion
B. Selection
C. Exchange
D. Deletion

Ans:: D

33. The algorithm design technique used in the quick sort algorithm is
Option 1 : Dynamic programming
Option 2 : Back tracking
Option 3 : Divide and conquer
Option 4 : Greedy Search

Ans:: Option 3

34. The maximum number of nodes on level I of a binary tree is which of the
following?
(Root is Level 1)

Option 1 : 2^(l-1)
Option 2 : 3^l-1
Option 3 : 2^l
Option 4 : 2^l – 1

Ans:: Option 1

35. What can be inherited by a derived class from a base class?

1. Data members
2. Member functions
3. Constructor and destructor
4. Data members and member functions

Ans:: 4

36. How many nodes does a binary tree with n non leaf nodes contain?
1. Log n
2. N+1
3. 2n+1
4. 2n

Ans:: 3

37. To solve a problem, it is broken in to a sequence of smaller sub-problems, till


a stage
that the sub-problem can be easily solved. What is this design approach called?
Option 1 : Top-down Approach
Option 2 : Bottom- Up Approach
Option 3 : Procedural Programming
Option 4 : None of these

Ans:: Option 1
38. A language has 28 different letters in total. Each word in the language is
composed of maximum 7 letters. You want to create a data-type to store a word of
this language. You decide to store the word as an array of letters. How many bits
will you assign to the data-type to be able to store all kinds of words of the
language.
Op 1: 7
Op 2: 35
Op 3: 28
Op 4: 196
Op 5:

Ans :: Op : 2

39. A programmer X writes a piece of code, where a set of eight lines occur around
10 times in different parts of the program (Code

A). X passes on the code to Programmer Y. Y puts the set of eight lines in a
function definition and calls them at the 10

points in the program (Code B). Which code will run faster using an interpreter?

Option 1 : Code A
Option 2 : Code B
Option 3 : Code A and Code B will run with the same speed
Option 4 : None of these

Ans:: Option 1

40. Consider the following code:

for i= m to n increment 2
{ print "Hello!" }

Assuming m < n and exactly one of (m,n) is even, how many times will Hello be
printed?
Option 1 : (n - m + 1)/2
Option 2 : 1 + (n - m)/2
Option 3 : 1 + (n - m)/2 if m is even, (n - m + 1)/2 if m is odd
Option 4 : (n - m + 1)/2 if m is even, 1 + (n - m)/2 if m is odd

Ans:: Option 1

41. What is the function used to describe the situation, when a function in base
class is redefined in inherited class?
a.Inheritance
b.Overriding
c.Overloading
d.Encapsulation

Answer:: Option b

42. Which of the given statements refers to data encapsulation in


OOPs??

A. The data and operation for an object are defined and fixed.
B. The data of an object is encapsualted in its class.
C. The data is hidden for an object..
D. A class have multiple objects.

Ans:: Option B. The data of an object is encapsualted in its class.

43. A Programmer writes an efficient program to add two upper triangular 10X10
matrices (elements on diagonal retained). How

many total additions will his program make?

Option 1 : 100
Option 2 : 55
Option 3 : 25
Option 4 : 10

Ans-option 2

44. Which of the following sorting methods is stable??

A. Straight insertion sort


B. Binary insertion sort
C. Shell sort
D. Heap sort

Ans:: Option B

45. What is the output of the following code statements? The compiler saves the
first integer
at the memory location 4165 and the rest at consecutive memory spaces in order of
declaration. Integer is one byte long.

integer a, b

pointer c, d
a = 30
c = &a
b = *c
a = a + 10
print b

Option 1 : 30 Option 2 : 4165 Option 3 : 40 Option 4 : 4166

46. Which of the given statements is TRUE about a "bipartite graph" with "n" nodes?
A. It contains n edges.
B. It contains a cycle of odd length.
C. It contains no cycle of odd length.
D. It contains n2 edges.

Ans:: Option C

47. A programmer is given two codes, A and B, to solve a problem, which have
complexity θ(n3)
and ω(n3) respectively. Her client wants to solve a problem of size k, which is
sufficiently large. Which code should she deliver to the client in the present
scenario?
Option 1 : Code A
Option 2 : Code B
Option 3 : Both codes have the same execution time, so deliver any.
Option 4 : None of these

Ans:: Option 1

48. Which of the given statement is true about Breadth First Search??

A. Beginning from a node all tha adjascent nodes are traversed first.
B. Beginning from a node, each adjacent node is fully explored before traversing
the next adjacent node
C. Beginning from a node, the nodes are traversed in cyclic order
D. None of the above

Ans:: Option A

49. How does inheritance relate to abstraction?

A. a base class is an abstraction of all its derived classes


B. a derived class is an abstraction of all its base classes
C. Base & derived classes are abstractions for each other
D. Inheritance prevents abstration

Ans:: Option B

50. What is space complexity of a program?


Option 1 : Amount of hard-disk space required to store the program
Option 2 : Amount of hard-disk space required to compile the program
Option 3 : Amount of memory required by the program to run
Option 4 : Amount of memory required for the program to compile

Ans:: Option 3

51. A 10-bit unsigned integer has the following range:

Option 1 : 0 to 1000
Option 2 : 0 to 1024
Option 3 : 1 to 1025
Option 4 : 0 to 1023

Ans:: Option 4

52. Identify the lower level format to which the computer converts a program in a
higher language before it executes

A. English code
B. Machinde Code
c. Assembly language
D. System language

Ans:: Option 2

53. A programmer writes a code snippet in which set of the three lines occurs 10
times in different pathway program what program concept should be used to shorten
the code length??

A. For loops
B. Functions
C. Arrays
D. Classes

Ans:: B. Functions

54. Consider a binary tree implementation. The root address is stored in variable
root. Given the address of a node is variable node, its value, right and root could
node address can be accessed using the following statements respectively node->
value ,node -> right, node-> left. Srikanth writes the following function to do a
preorder traversal of the tree.
function preordertraverse(n0de)
{
print node -> value
if(Conditon X)
{
preordertraverse(node ->left)
}
if(Condition Y)
{
preordertraverse(node ->right)
}
return
}
What is the Condition X and Condition Y ?
a. Condition X: node -> left is not equal null
b. Condition X: node -> right is not equal null,Condition Y:node -> right is not
equal null,Condition Y:node -> left is not equal null
c. Condition X: node -> left is equal null
d. Condition X: node -> right is equal null, Condition Y:node -> right is equal
null, Condition Y:node -> left is equal null.

Ans.A

55. What will happen if some indentations are made in some statements of a code
written in C++?

A. Faster execution of the code


B. Lower memory requirement for the code
C. Correction of errors in the code
D. Better readability of the code

Ans:: Option D

56. . In an implementation of a linked list, each node contains data and address.
Which of the following could the address field possibly contain?
Op 1: Address of next node in sequence
Op 2: It's own address

Op 3: Address of last node


Op 4: Address of first node Op 5:

Ans:: Op : 1

57. A sorting algorithm traverses through a list, comparing adjacent elements and
switching them under certain conditions. What is this sorting algorithm called?
Option 1 : insertion sort
Option 2 : heap sort
Option 3 : quick sort
Option 4 : bubble sort

Ans:: Option 4

58. A stack is implemented in a linear array A[0...n-1]. A programmer writes the


function given below to pop out an element from the stack.

function POP(top,N)
{
if(X)
{
top=top-1;
}
else
{
print "Underflow"
}
return top;

What should be replaced in X ??

a. top<N-1
b. top<N
c. top>1
d. top>=0

Ans:: option d

59. What is implied by the argument of a function ??

Ans:: Value passed to a function when it is called

60. A sorting mechanism uses the binary tree concept such that any number in the
tree is
larger than all the numbers in the sub-tree below it. what is method called?
A. selection sort
B. insertion sort
C. heap sort
D. quick sort

Ans:: Option C

60. What will be the output of the following pseudo-code statements:


integer a = 984, b=10
//float is a data-type to store real numbers.
float c
c = a / b
print c
Option 1 : 984
Option 2 : 98.4
Option 3 : 98
Option 4 : Error
Ans:: Option 2

61. Which of the following data structure may give overflow error,even though the
current number of element in it is less than its size?
A. Simple queue
B. Circular queue
C. Priority Queues
D. None of these

Ans:: Option B

62. How are protected members of a base can be inherited in the derived class?

A. Privately
B. Publicly
C. Protectedly
D. Not inherited.

Ans:: A

63. A programmer writes a sorting algorithm. The algorithm takes different amount
of time to sort two different lists of equal size. What is the possible difference
between the two lists?
A. All numbers in one more list are more than 100, while in other are less
than 100.
B. The ordering of numbers with respect to magnitude in two lists has different
properties.
C. One list has all negative numbers, while the other has all positive numbers.
D. One list contains 0 as element, while the other does not.

Ans. B

64. A programmer wants to program to print the largest number out of three inputted
numbers.
She writes the following program:

int number1, number 2, number3, temp;


input number1, number2, number3;
if (number1>number2)
temp = number1
else
temp = number2
end if
if (??) // Statement 1
temp = number3
end if
print temp
Fill in the ?? in Statement 1
Option 1 : number3 > number2
Option 2 : number3 > temp
Option 3 : number3 < temp
Option 4 : number3 > number1

Ans:: Option 2

65.
function g(int n)
{
if (n > 0) return 1;
else return -1;
}
function f(int a, int b)
{
if (a > b) return g(a-b);
if (a < b) return g(-b+a);
return 0;
}

If f(a,b) is called, what is returned?

Option 1 : Always +1
Option 2 : 1 if a > b, -1 if a < b, 0 otherwise
Option 3 : -1 if a > b, 1 if a < b, 0 otherwise
Option 4 : 0 if a equals b, -1 otherwise

Ans:: Option 2

66. What does function overloading imply??

Ans:: Two or more functions with same but different parameter list different with
type of argument.

67. How can a call to overloadedd function be ambiguos??

Ans:: Two or more functions with equally appropriate signatures.

68. Consider the following:

Class rocket
{
Private:
integer height,weight
public: //statement 1
function input(int a,int b)
{
height=a;
weight=b;
}
}
function main()
{
rocket rocket 1,rocket2
}
What can we infer from this code?
Choose the correct answer. A pseudo-code which is similar to that of c++ and self-
explanatory. An accessible member function or data member for an object are
accessed by the statement object name, function name or object name data member
name respectively.

A. rocket is a class with rocket 1 and rocket2 as its objects.height and


weight are attributes of a rocket.
B. rocket is a class with rocket1 and rocket2 as its attributes.height and
weight are objects of the class rocket.
C. rocket is a class with rocket1,rocket2,height and weight as its attributes
D. rocket is a class with rocket1, rocket2, height, weight as its objects.

Ans- A
69. A complete binary tree has a property that the value at each node is at least
as large as the values at its children nodes. What is this binary tree known as??

A. Binary Search Tree


B. AVL tree
C. Completely Balance Tree.
D. Heap.

Ans:: Option D

70. Consider the following code:


function modify(b,a)
{
return a - b
}
function calculate( )
{
integer a = 5, b = 12, c
c = modify(a, b);
print c
}
Assume that a and b were passed by reference. What will be the output of the
program
on executing function calculate( ) ?
Option 1 : 7
Option 2 : -7
Option 3 : Error
Option 4 : 8

Ans:: Option 1

71. In an implementation of a linked list, each node contains data and address.
What can the address field possibly contain?

Option 1 : Address of next node in sequence


Option 2 : It’s own address
Option 3 : Address of last node
Option 4 : Address of first node

Ans::
Option 1 : Address of next node in sequence

72. The following operations are performed on an empty stack "A":

PUSH(1)
PUSH(2)
POP
PUSH(5)
PUSH(6)
POP

What will be the stack contain after these operations??


(Top of stack is underlined)
A: 5 6
-
B. 1 5
-
C. 5 6
-
D. 1 5
-

Ans:: Option B

73.
class entity
{
private: integer a, b public: integer c
function entity( ) { a = 0; b=0} function compare ( )
{ if (a>b) return 1; return 0
}
}
function main ( )
{
entity black
int value, value2 = 5
value = black.compare( ) // Statement 1 black.c = value2 //Statement 2
print black.a //Statement 3
}
Choose the correct answer. A pseudo-code which is similar to that of C++ and self-
explanatory. An accessible member function or data member for an object are
accessed by the statement objectname.functionname or objectname.datamembername
respectively.
(a)Statement 1 (b)Statement 2 (c)Statement 3 (d)None of these

Ans:: Option c

74. Which of the given options will create an object named pigeon of the class Bird
in c++?
A. pigeoon birs
B. bird pigeon
C. Object pigeon of bird
D. None of above

Ans:: Option D(Bird pigeon)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy