Important Questions

CBSE Guess > Papers > Important Questions > Class XII > 2010 > Computer Science > Computer Science By Ravi Kiran

CBSE CLASS XII

DELHI 2001

Q.1. Given two arrays of integers X and Y of sizes m and n respectively. Write a function named MERGE() which will third array named Z, such that the following sequence is followed.
(i) All odd numbers of X from left to right are copied into Z from left to right.
(ii) All even numbers of X from left to right are copied into Z from right to left.
(iii) All odd numbers of Y from left to right are copied into Z from left to right.
(iv) All even numbers of Y from left to right are copied into Z from right to left.
X, Y and Z are passed as arguments to MERGE().

Eg. X is {3, 2, 1, 7, 6, 3} and {9, 3, 5, 6, 2, 8, 10}
the resultant array Z is {3, 1, 7, 3, 9, 3, 5, 10, 8, 2, 6, 6, 2}
void MERGE(int X[ ], int m,int Y[ ],int n,int Z[ ])
{ int mn,i,,left=0,right=mn-1;
mn=m+n;
for(i=0;i<m;i++)
if (X[i]%2= = 1)
Z[left++]=X[i]; //For copying odd numbers of X into Z from left to right
else
Z[right- -]=X[i]; //For copying even number of X into Z from right to left
for(i=0;i<n;i++)
if (X[i]%2= = 1)
Z[left++]=Y[i]; //For copying odd numbers of Y into Z from left to right
else
Z[right- -]=Y[i]; //For copying even number of X into Z from right to left
}

Q.2. An array X[10][20] is stored in the memory with each element requiring 4 bytes of storage. If the Base address of the array is 1000, calculate location of X[5][15] when the array X is stored using column major order.
NOTE: X[10][20] means valid row indices are 0 and 9 and valid column indices are 0 and 19

Solution: Children, Try this answer as an assignment.

Q.3. Write a user-defined function named Lower_half() which takes 2D array A, with size N rows and N columns as argument and prints the lower half of the array.
Eg. 2 3 1 5 0 2
7 1 5 3 1 7 1
Input 2 5 7 8 1 the output will be 2 5 7
0 1 5 0 1 0 1 5 0
3 4 9 1 5 3 4 9 1 5

Solution:
void Lower_half( int A[ ][ ],int N)
{ int i,j;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
{ if(i<j)
cout<<A[i][j]<<’\t’;
cout<<endl;
}
}

DELHI 2000

Q.1. Suppose A, B, C are arrays of integers of size M, N and M+N respectively. The numbers in array A appear in ascending order while numbers in array in descending order. Write user defined function in C++ to produce third array C by merging array A by B in ascending order. Use A, B and C as arguments in the function.
void Merge(int A[ ],int M,int B[ ],int N,int C[ ])
{ int a,b,c;
for(a=0,b=N-1,c=0;a<M&&b>=0;)
{ if(A[a]<=B[b])
C[c++]=A[a++];
else
C[c++]=B[b--];
}
if(a<M)
{ while(a<M)
C[c++]=A[a++];
}
else
{ while(b>=0)
C[c++]=B[b--];
}
}

Q.2. An array VAL[1…15][1…10] is stored in the memory with each element requiring 4 bytes of storage. If the base address of the array VAL is 1500, determine the location of VAL[12][9] when the array VAL is stored (i) Row wise (ii) Column wise.

Solution:
Given Data:
VAL[1…15][1…10]
Word Length (W) = 4 Bytes
Base Address of VAL(B) = 1500
VAL[12][9] = ?
C = Total No of Columns R = Total No of Rows
Lr = Least Row=1 Lc = Least Column=1

( i ) Row Major:
Address of an element (I,J) in row major = B + W ( C (I-Lr) + (J – Lc))
VAL [12][9] = 1500 + 4 (10 * (12-1) + (9-1))
= 1500 + 4 (10 * 11+8)
= 1500 + 4 (118)
= 1500 + 472
= 1972.

( i ) Column Major:
Address of an element (I,J) in column major = B + W ( (I-Lr) + R(J – Lc))
VAL [12][9] = 1500 + 4 ((12-1) +15 * (9-1))
= 1500 + 4 (11 + 15 * 8)
= 1500 + 4 ( 11+ 120)
= 1500 + 4 * 131
= 1500 + 524
= 2024.

Paper By Mr. Ravi Kiran
Email Id : [email protected]