Capgemini Reginal Challenge Solutions

Page Contents

Capgemini Reginal Challenge 2021 Solutions

Data Structures and Algorithms

Stark is a linear data structure.

  • A Maybe
  • B None
  • C FALSE
  • D TRUE

Merging 4 sorted files containing 50, 10, 25 and 15 records will take____time

  • A O (100)
  • B O (200)
  • C O (175)
  • D O (125)

What will happen when defining the enumerated type?

  • A it will not allocate memory
  • B it will allocate memory
  • C it will not allocate memory to its variables
  • D none of the above.

……… form of access is used to add and remove nodes from a queue.

  • A LIFO, Last In First Out
  • B FIFO, First In First Out
  • C Both a and b
  • D None of these

If the list contains data as 10,20,30 and 40 initially, then after call to testfun(),
which of the following is the possible value of the 3rd node from the beginning ?

node * testfun(node * h)
{
node curr,new,*p;
curr=h;
new=h->next;
p=NULL;
while(new!=NULL)
{
curr->next=p;
p=curr;
curr=new;
new=curr->next;
}
curr->next=p;
h=curr;
return h;
}
  • A 10
  • B 20
  • C 30
  • D 40

Generic

Which operator has been used by Java run time implementations to free the memory of an object when it
has been no longer needed?

  • A delete
  • B free
  • C new
  • D None of these

Which of these is used to perform all input and output operations in Java?

  • A streams
  • B Variables
  • C classes
  • D Methods

Which is an expression in which each operator must follow its operands, and there is no need of
considering the precedence of operators?

  • A Prefix expression
  • B Memory allocation
  • C Postfix expression
  • D None the above

Which of these class can be used to implement input stream that uses a character array as the source?

  • A BufferedReader
  • B FileReader
  • C CharArrayReader
  • D FileArrayReader

Which constant member functions does not modify the string?

  • A bool empty()
  • B assign
  • C append
  • D None of the mentioned

INPUT OUTPUT

What is the output of the program?

int main () 
{ 
unsigned char c=255; 
char d=-1; 
if(c<0) 
cout<<"c is less than 0 "; 
else 
cout<<"c is not less than 0 "; 
if (d<0) 
cout<<"d is less than 0 "; 
else 
cout<<"d is not less than 0 "; 
} 
  • A c is less than 0 d is less than 0
  • B c is not less than 0 d is less than 0
  • C c is not less than 0 d is not less than 0
  • D c is less than 0 d is not less than 0

Point out the error in the program

#include int main()
 { struct a 
{ float category:5;
 char scheme:4; }; 
printf("size=%d",
 sizeof(struct a)); 
return 0; }
  • A Error: invalid structure member in printf
  • B Error in this float category:5; statement
  • C No error
  • D None of the above

What would be the output of the provided code snippet?

class Program
{
static void main( string[ ] args)
{
String s = "Hello World";
int i = s.IndexOf('o');
int j = s.LastIndexOf('l');
Console.WriteLine(i + "" + j);
Console.ReadLine();
}
}
  • A 9 5
  • B 4 9
  • C 9 0
  • D 9 4

Given the code, which all of the given Java Coding Guidelines are not followed here

public double calculateArea(String type, double arr[])
{ if(type.equals("Circle"))
{ 
double area = 3.14 * (arr[0]*arr[0]);
return area;
}
else if(type.equals("Rectangle"))
{ 
double area = arr[0] * arr[1];
return area;
}
else
return 0.0;
}
  • A Do not use the magic number in the code, define it as a Constant.
  • B Multiple return statements should be avoided in a method. All methods have only one exit path.
  • C The comparisons should be done always by placing the constants on the left-hand side of the Expression.

What is the output of this C code?

 #include int main()
 { char *str = "hello, world\n";
 printf("%d", strlen(str));
 }
  • A Compilation error
  • B Undefined behaviour
  • C 13
  • D 11

OOP

Which constructor creates an empty string buffer with the specified capacity as length?

  • A StringBuffer()
  • B StringBuffer(String str)
  • C StringBuffer(int capacity)
  • D None of the above

Consider a class A with a member variable m1.
Refer the code snippets given below.

Choose the incorrect option related to operator overloading of binary operator.

A A operator +(A obj2) {
A temp;
temp.m1 = m1 + obj2.m1;
return temp;
}
B A operator +(A obj1, A obj2) {
A temp;
temp.m1 = obj1.m1 + obj2.m1;
return temp;
}
C A operator+(A obj2) {
A temp;
temp.m1 = this->m1 + obj2.m1;
return temp;
}
D A operator+(A obj2) {
return (m1 + obj2.m1);
}

Which of the following statement is incorrect?

  • A Default constructor is called at the time of declaration of the object if a constructor has not been defined.
  • B Constructor can be parameterized.
  • C finalize() method is called when a object goes out of scope and is no longer needed.
  • D finalize() method must be declared protected

What are the possible access modifiers a protected method can have if it is overridden in the sub class?

  • A protected or public
  • B protected or private
  • C only public
  • D only protected

The input for object-oriented design is provided by the output of object-oriented analysis. State from the given as What is Basis of Encapsulation?

object

class

method

  • A 1,3
  • B Only 2
  • C 2,3
  • D 1,2,3

Pseudocode

Which of the given algorithm is depicted in the code given below:

FOR I = 0 to N-2
FOR J = 0 to N-2
IF A[J] > A[J+1]
TEMP = A[J]
A[J] = A[J+1]
A[J+1] = TEMP
END IF
END FOR
END FOR
  • A LINEAR SEARCH
  • B HASHING
  • C BUBBLE SORT
  • D RADIX SORT

What is the functionality of the pseudo code given below:

Declare an Integer array Arr of size N
Read N elements into the array Arr
Declare x as Integer
Set x = 99999
FOR EACH i in Arr upto N DO
IF Arr[i] is less than x THEN
x = Arr[i]
END IF
END FOR
Print x
  • A It counts the number of elements in Arr greater than x.
  • B It find the smallest element in the array.
  • C It find the elements less than 99999
  • D None of these

What is the output of the code given below:

DECLARE and DEFINE CLASS TEST:
PUBLIC:
DEFINE FUNCTION X with two INTEGER arguments and RETURN Type as INTEGER
INT X (INT A, INT B):
RETURN A + B
END FUNCTION X
DEFINE another FUNCTION X with three INTEGER arguments and RETURN type as INTEGER
INT X (INT A, INT B, INT C):
RETURN A - B * C
END FUNCTION X
END CLASS
IN MAIN FUNCTION:
CREATE a TEST object XYZ
PRINT XYZ.X(10, 20)
PRINT XYZ.X(10, 20, 30)
END MAIN
  • A 30
  • -300
  • B 30
  • -590
  • C 30
  • 500
  • D Compiler error because the functions have the same name

What is the output of the code given below if the input provided is, N = 79?

DECLARE N as INTEGER
READ N
DECLARE FLAG as Boolean
SET FLAG = TRUE
FOR EACH i from 2 to N/2
IF N is divisible by i THEN
Set FLAG = FALSE
BREAK
END IF
ELSE
CONTINUE
END LOOP
IF FLAG is TRUE THEN
PRINT YES
ELSE
PRINT NO
  • A NO
  • B YES
  • C -1
  • D Garbage value

Which sorting technique is depicted by the pseudo code given below:

FOR I = 0 to N-1 DO:
X = I
FOR J = I+1 to N-1 do:
IF ARR[J] is less than ARR[X]
X = J
END IF
END FOR
TEMP = A[I]
A[I] = A[X]
A[X] = TEMP
END FOR
  • A BUBBLE SORT
  • B SELECTION SORT
  • C MERGE SORT
  • D HEAP SORT

July Long Challenge 2021 Solutions

Weekly Contest 247

Biweekly Contest 55

Leave a Comment