All mock tests are FREE till 31 December — register to save your progress
Paper 2 CS · UNIT 03 · MOCK TEST

Programming Languages and Computer Graphics — Mock Test 9

25 questions · about 30 minutes. Press End Mock any time to see your score and the correct answers.

0 / 25 answered 00:00
Q1.

Which of the following statements are true regarding C ++ ?

(a) Overloading gives the capability to an existing operator to operate on other data types.

(b) Inheritance in object oriented programming provides support to reusability.

(c) When object of a derived class is defined, first the constructor of derived class is executed then constructor of a base class is executed.

(d) Overloading is a type of polymorphism.

Q2.

Which of the following are legal C statements? (a) int *P = &44; (b) int *P = &r; (c) int P = &a; (d) int P = a;

Q3.

On a 32-bit x86 machine: typedef struct { union { unsigned char a; unsigned short b; } U; unsigned char c; } S; S B[10]; S *p = &B[4]; S *q = &B[5]; p->U.b = 0x1234; (S takes 32 bits). If M is q − p and N is (int)&(p->c) − (int)p, then (M, N) is

Q4.

Class Good has a field m and a method public boolean equals(Good n) { return n.m == m; }. In main: Good m1 = new Good(22), m2 = new Good(22); Object s1 = new Good(22), s2 = new Good(22); then it prints m1.equals(m2), s1.equals(s2), m1.equals(s2), s1.equals(m2). What is printed?

Q5.

Consider the following function ) : f n unsigned int (unsigned int )( b = 0

unsigned int ;
while (n) {
b+ = n&1
;
n ≫>= 1
;
}
return b;}
```
f (

The function ) returns the int that represents _P_ the in the binary representation of positive n P

integer , where is
Q6.

Consider a raster system with resolution 640 by 480 . What size is frame buffer (in bytes) for this system to store 12 bits per pixel?

Q7.

Consider the following statements regarding 2D transforms in computer graphics: 1 0 [ ] 2 × 2

S1 : is a matrix that reflects 0 −1 2D X (mirrors) only point about the -axis. 2 × 2 2D

S2 : A matrix which mirrors any point X about the -axis, is a rotation matrix. What can you say about the statements S1 and S2?

Q8.

In the context of 3D computer graphics, which of the following statements is/are true? P : Orthographic transformations keep parallel lines parallel. Q : Orthographic transformations are affine transformations. Select the correct answer from the options given below :

Q9.

Using the phong reflectance model, the strength of the specular highlight is determined by the angle between

Q10.

If the frame buffer has 10-bits per pixel and 8- bits are allocated for each of the R, G, and B components, then what would be the size of the color lookup table (LUT) ?

Q11.

Which homogeneous 2D matrix transforms the figure (a) on the left side to the figure (b) on the right ?

Figure
Q12.

Consider the midpoint (Bresenham) algorithm for rasterizing lines: (1) Input (x₁, y₁) and (x₂, y₂) (2) y = y₁ (3) d = f(x₁ + 1, y₁ + 1/2) // f is the implicit form of the line (4) for x = x₁ to x₂ (5) do (6) plot(x, y) (7) if (d < 0) (8) then (9) y = y + 1 (10) d = d + (y₁ − y₂) + (x₂ − x₁) (11) else (12) d = d + (y₁ − y₂) (13) end (14) end Which statements are true? P: For a line with slope m > 1, the outer loop in line (4) should be over y. Q: Lines (10) and (12) update the decision variable d through an incremental evaluation of the line equation f. R: The algorithm fails if d is ever 0.

Q13.

In 3D Graphics, which of the following statements about perspective and parallel projection is/are true? P : In a perspective projection, the farthest an object is from the centre of projection, the smaller it appears. Q : Parallel projection is equivalent to a perspective projection where the viewer is standing infinitely far away. R : Perspective projections do not preserve straight lines.

Choose the correct answer from the code given below :

Q14.

In 3D Graphics, which of the following statements is/are true? P : Back-face culling is an example of an image- precision visible-surface determination procedure. Q : Z-buffer is a 16-bit, 32-bit, or 64-bit field associated with each pixel in a frame buffer that can be used to determine the visible surfaces at each pixel.

Q15.

Consider the two C++ programs P1 and P2 shown below and two statements about them:

S1: P1 prints out 3

S2: P2 prints out 4:2 What can you say about S1 and S2?

Q16.

Consider the following recursive Java function f that takes two long arguments and returns a

float value :
public static float f(long m, long n)
{
float result =(float )m/(float )n;
if (m<0||n<0)
return 0.0f ;
else
result +=f(m∗2,n∗3);
return result;
}

Which of the following integers best approximates the value of f(2,3)?

Q17.

What does the following Java function perform? (Assume int occupies four bytes of storage) public static int f(

int a)
{ // Pre-conditions : a>0 and no
overflow/underflow occurs int b=0 ;
for (int i=0; i<32; i++)
{
b=b<<1 ;
b=b | (a & 1);
a=a≫>1;// This is a logical shift
}
return b;
}
Q18.

Which of the following HTML5 codes will affect the horizontal as well as vertical alignment of the table content?

Q19.

Consider the C/C++ function f() given below:

void f(char w[])
{
    int x = strlen(w); // length of the string
    char c;
    for (int i = 0; i < x; i++)
    {
        c = w[i];
        w[i] = w[x − i − 1];
        w[x − i − 1] = c;
    }
}

Which of the following is the purpose of f()?

Q20.

The definitions in an XML document are said to be __________ when the tagging system and definitions in the DTD are all in compliance.

Q21.

Consider the JavaScript code:

var y = "12";
function f() {
    var y = "6";
    alert(this.y);
    function g() { alert(y); }
    g();
}
f();

If M is the number of alert dialog boxes generated by this code and D1, D2, …, DM are the contents displayed in each, then:

Q22.

What is the output of the following Java program?

class simple {
    public static void main(String[] args) {
        simple obj = new simple();
        obj.start();
    }
    void start() {
        long[] P = {3, 4, 5};
        long[] Q = method(P);
        System.out.print(P[0] + P[1] + P[2] + ":");
        System.out.print(Q[0] + Q[1] + Q[2]);
    }
    long[] method(long[] R) {
        R[1] = 7;
        return R;
    }
} // end of class
Q23.

What is the output of the following C program? (Assume little-endian representation, with the least significant byte at the lowest address, and a two-byte short int.)

#include <stdio.h>
int main()
{
    union saving {
        short int one;
        char two[2];
    };
    union saving m;
    m.two[0] = 5;
    m.two[1] = 2;
    printf("%d, %d, %d\n", m.two[0], m.two[1], m.one);
}
Q24.

Given below are three implementations of swap() in C++:

(a) void swap(int a, int b) { int temp; temp = a; a = b; b = temp; }  called as swap(p, q);
(b) void swap(int &a, int &b) { int temp; temp = a; a = b; b = temp; }  called as swap(p, q);
(c) void swap(int *a, int *b) { int *temp; temp = a; a = b; b = temp; }  called as swap(&p, &q);

with int p = 0, q = 1 in main(). Which of these would actually swap the contents of p and q?

Q25.

In Java, which of the following statements is/are True ?

S1 : The ‘final’ keyword applied to a class definition prevents the class from being extended through derivation.

S2 : A class can only inherit one class but can implement multiple interfaces.

S3 : Java permits a class to replace the implementation of a method that it has inherited. It is called method overloading.