270 likes | 348 Views
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 3
E N D
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 3 If the array is 1, 2, 3, 4, 5, 6 The resultant 2 D array is given 1 2 3 4 5 6 1 2 3 4 5 0 1 2 3 4 0 0 1 2 3 0 0 0 1 2 0 0 0 0 1 0 0 0 0 0 If the array is 1, 2, 3 The resultant 2 D array is given below 1 2 3 1 2 0 1 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]; else A2D[I][J] = 0; } OR
OR const 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
OR • Any other equivalent code • (1 mark for function header) • (1 mark for correct use of nested loops) • ( ½ mark for correctly assigning the values from 1D array to 2D array) • ( ½ mark for assigning 0 to the rest of the elements) • Note: Ignore declaration of the 2D array.
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 3 If the array is 1, 2, 3, 4, 5, 6 The resultant 2 D array is given below 1 0 0 0 0 0 1 2 0 0 0 0 1 2 3 0 0 0 1 2 3 4 0 0 1 2 3 4 5 0 1 2 3 4 5 6 If the array is 1, 2, 3 The resultant 2 D array is given below 1 0 0 1 2 0 1 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; else NUM[i]=2*NUM[i]; } } OR
OR void 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; else Arr[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 4 Example: 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; } } OR Any 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 swapping Deduct ½ 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, 10 then 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 3 Note: Assume the following definition of structure Game struct Game { long PNo; //Player Number char PName [20] ; long Points; } ;
Sample content of the array (before sorting) PNo PName Points 103 Ritika Kapur 3001 104 John Philip 2819 101 Razia Abbas 3451 105 Tarun Kumar 2971 Sample content of the array (after sorting) PNo PName Points 101 Razia Abbas 3451 103 Ri tika Kapur 3001 105 Tarun Kumar 2971 104 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; }
OR Any 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 order Deduct ½ Mark if only Points is swapped instead of the whole Structure Deduct ½ 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. 3 Note: Assume the following definition of structure Examinee struct Examinee { long RollNo; char Name [20] ; float Score; } ;