2. (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
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 <N-I; J++)
A2D[I][J] = A1D[J];
}
OR
4. (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
5. 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
6.
7. 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
8. (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)
9. 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
11. 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)
12. 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
13. 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
14. 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)
15. 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
16. 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
17. (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
18. 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
19. 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)
20. 3. (a) Write a function SORTPOINTS( ) in C++
to sort an array of structure Game in
escending order of Points using Bubble Sort.
Delhi
20093
Note: Assume the following definition of
structure Game
struct Game
{
long PNo; //Player Number
char PName [20] ;
long Points;
} ;
21. 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
22. 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;
}
23. 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
24. 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;
} ;