27
XII CBSE Previous Year Question Paper QUESTION NO 3 (a) 3 Marks

XII CBSE Previous Year Question Paper QUESTION NO 3 (a) 3 Marks

Embed Size (px)

Citation preview

XII CBSE Previous Year Question

Paper

QUESTION NO 3 (a)

3 Marks

(a) Write a function in C++ which accepts an integer array and its size as arguments / parameters and assign the elements into a two dimensional array of integers in the following format D 2006 3If the array is 1, 2, 3, 4, 5, 6The resultant 2 D array is given1 2 3 4 5 6 1 2 3 4 5 0 1 2 3 4 0 0 1 2 3 0 0 01 2 0 0 0 01 0 0 0 0 0

If the array is 1, 2, 3 The resultant 2 D array is given below1 2 31 2 01 0 0

(a) const int R = 100, C = 100;void Arrayconvert(int A1D[], int N){int A2D[R][C]={0};for(int I = 0; I<N; I++)for (int J = 0; J <N-I; J++)A2D[I][J] = A1D[J];}

OR

(a)const int R = 100, C = 100;void Arrayconvert(int A1D[], int N){int A2D[R][C];for(int I = 0; I<N; I++)for (int J = 0; J <N; J++)if (J<N-I)A2D[I][J] = A1D[J];elseA2D[I][J] = 0;}

OR

ORconst int R = 100, C = 100;void Arrayconvert(int A1D[], int N){int A2D[R][C], I, J;for(I = 0; I<N; I++)for (J = 0; J <N; J++)A2D[I][J] = 0;for(I = 0; I<N; I++)for (J = 0; J <N-I; J++)A2D[I][J] = A1D[J];}

OR

3. (a) Write a function in C++ which accepts an integer array and its size as arguments/ parameters and assign the elements into a two dimensional array of integers in the following format : OD 2006 3If the array is 1, 2, 3, 4, 5, 6The resultant 2 D array is given below1 0 0 0 0 01 2 0 0 0 01 2 3 0 0 0 1 2 3 4 0 01 2 3 4 5 01 2 3 4 5 6

If the array is 1, 2, 3The resultant 2 D array is given below1 0 01 2 01 2 3

(a) const int R = 100, C = 100;void Arrayconvert(int A1D[ ], int N){int A2D[R][C]={0};for(int I = 0; I<N; I++)for (int J = 0; J <=I; J++)A2D[I][J] = A1D[J];}( 1 mark for proper function header )( 1 mark for proper use of loops)( 1 mark for proper assignment of values)

3. (a) Write a function in C++ which accepts an integer array and its size as arguments and replaces elements having even values with its half and elements having odd values with twice its value. Outside Delhi 2007 4

Example : if an array of five elements initially contains the elements as,

3, 4, 5, 16, 9

then the function should rearrange the content of the array as,

6, 2, 10, 8, 18

(a) void Display(int NUM[],int N){for(int i=0;i<N;i=i+1){if(NUM[i]%2==0)NUM[i]=NUM[i]/2;elseNUM[i]=2*NUM[i];}}

OR

ORvoid Display(int NUM[],int N){for(int i=0;i<N;i=i+1)NUM[i]=(NUM[i]%2!=0)?2*NUM[i]:NUM[i]/2;}

(1 Mark for correct Function Header with proper Arguments)(1 Mark for correct loop)(1 Mark for checking Even / Odd values)(1 Mark for replacing array elements with proper values)

3. (a) Write a function in C++ which accepts an integer array and its size as arguments and replaces elements having odd values with thrice its value and elements having even values with twice its value. D 2007 4

Example : if an array of five elements initially contains the elements as

3, 4, 5, 16, 9

then the function should rearrange the content of the array as

9, 8, 15, 32, 27

3. (a) void Replace( int Arr[], int Size){for(int i =0; i<Size; i++)if(Arr[i]%2 != 0 )Arr[i] *= 3;elseArr[i] *= 2;}

OR

void Replace( int Arr[], int Size){for(int i =0; i<Size; i++)Arr[i]%2 ? Arr[i] *= 2 : Arr[i] *= 3;}

(1 Mark for correct Function Header with proper Arguments)

(1 Mark for correct loop)

(1 Mark for checking Even / Odd values)

(1 Mark for replacing with proper values)

3. (a) Write a function in C++, which accepts an integer array and its size as parameters and rearranges the array in reverse.

Delhi 2008 4Example: if an array of nine elements initially contains the elements as

4, 2, 5, 1, 6, 7, 8, 12, 10

then the function should rearrange the array as

10, 12, 8, 7, 6, 1, 5, 2, 4

Ans:void Rearrange( int Arr [], int Size){for (int i = 0; i<Size/2; i++){int T = Arr[i];Arr[i] = Arr[Size-1-i];Arr[Size-1-i]=T;}}ORAny other correct equivalent function definition

(1 Mark for correct Function Header with proper Arguments)(1 Mark for correct loop)(2 Marks for swapping the values correctly)

Note:

Deduct ½ Mark if loop runs till Size instead of Size/2 for swappingDeduct ½ Mark if reversed values are stored in another array

3. (a) Write a function in C++, which accepts an integer array and its size as arguments and swaps the elements of every even location with its following odd location.

OUTSIDE DELHI 2008 4

Example: if an array of nine elements initially contains the elements as

2, 4, 1, 6, 5, 7, 9, 23, 10then the function should rearrange the array as

4, 2, 6, 1, 7, 5, 23, 9, 10

Ans:void Display (int NUM[ ], int N){int T;for (int I=0; I<N–l; I+=2){T=N[I] ;N[I]=N[I+1] ;N[I+1] = T ;}}(1 Mark tor correct Function Header with proper Arguments)(1 Mark for correct loop)(2 Marks for swapping values correctly with / without a temporary variable)

3. (a) Write a function SORTPOINTS( ) in C++ to sort an array of structure Game in escending order of Points using Bubble Sort.

Delhi 2009 3Note: Assume the following definition of structure Gamestruct Game{long PNo; //Player Numberchar PName [20] ;long Points;} ;

Sample content of the array (before sorting)

PNo PName Points103 Ritika Kapur 3001104 John Philip 2819101 Razia Abbas 3451105 Tarun Kumar 2971

Sample content of the array (after sorting)

PNo PName Points101 Razia Abbas 3451103 Ri tika Kapur 3001105 Tarun Kumar 2971104 John Philip 2819

Ans void SORTPOINTS(Game G[], int N){Game Temp;for (int I = 0; I<N-l; I++)for (int J = 0; J<N-I-l; J++)if(G[J].Points < G[J+l].Points){Temp = G[J];G[J] = G[J+l];G[J+l] = Temp;}

ORAny other correct equivalent function definition( ½ Mark for correct Function Header)( ½ Mark for each correct loop)( 1 Mark for correct comparison of adjacent elements)( ½ Mark for swapping the values correctly)Note:Deduct ½ Mark if sorted in ascending order instead of descending orderDeduct ½ Mark if only Points is swapped instead of the whole StructureDeduct ½ Mark if Temp is not declared with correct data type

3. (a) Write a function SORTSCORE( ) in C++ to sort an array of structure Examinee in descending order of Score using Bubble Sort. 3Note: Assume the following definition of structure Examinee

struct Examinee{long RollNo;char Name [20] ;float Score;} ;

THANK YOU