Important Questions

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

CBSE CLASS XII

DELHI 2003

Q.1. Assume a array E containing elements of structure Employee is required to be arranged in descending order of Salary. Write a C++ function to arrange same with the help of bubble sort, the array and its size is required to be passed as parameters to the function. Definition of structrure Employee is as follows:
Struct Employee
{
int Eno;
char name[25];
float Salary;
};

Solution:
void bubble(Employee E[ ],int n)
{ int i,j;
Employee Etemp;
for(i=0;i<n;++i)
for(j=0;j<(n-1)-i ;j++)
if(E[j].salary<E[j+1].salary)
{ Etemp=E[j];
E[j]=E[j+1];
E[j+1]=temp;
}
cout<<"The details of the employee in ascending order of salary ";
for(i=0;i<n;i++)
cout<<E[i].Eno<<'\t'<<E[i].name<<’\t<<E[i].Salary<<endl;
}

Q.2. An array X[30][10] is stored in the memory with each element requiring 4 bytes storage. Find out the Base address of X is 4500, find out memory locations of X[12][8] and X[2][14], if the content is stored along the row.

Solution: Children, Try this answer as an assignment.

Q.3. Write a user-defined function in C++ to display those elements of 2D array T[4][4] which are divisible by 100. Assume the content of the array is already present and the function prototype is as follows: void showhundred( int T[4][4]);
void showhundred(int T[4][4])
{ int i,j;
cout<<”\nThe elements in the array which are divisible by 100 …..”;
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(T[i][j]%100= =0)
cout<<T[i][j]<<’\t’;
}

DELHI 2002

Q.1. Define array and pointer.

Solution: An array refer to a named list of a finite number n of similar data elements. Each of the data elements can be referenced respectively by a set of consecutive numbers.
Arrays can be one dimensional, two dimensional or multi dimensional.
An array can be declared as : Syntax: data_type Array_name[size];
Eg: int A[10]; //Then location of the array are A[0], A[1],…….A[9].
int B[5][4]; //This array can holds 5 X 4 = 20 elements.

Q.2.The array A[20][10] is stored in the memory with each element requiring one byte of storage if the base address of a is 0, determine the location of A[10][5] when the array A is stored by column major.

Solution: Children, Try this answer as an assignment.

Q.3. Considering the following key set: 42,29,74,11,65,58, use insertion sort to sort the data in ascending order and indicate the sequences of steps required.

Solution:
In this, Suppose an array A with n elements A[1],A[2],…A[N] is in memory. The insertion sort algorithm scans A from A[1] to A[N], insertion each element A[K] into its proper position in the previously sorted subarray A[1],A[2],…,A[K-1]. This sorting algorithm is frequently used when n is small.
The array contains 6 elements as follows: 42,29,74,11,65,58
Pass A[0] A[1] A[2] A[3] A[4] A[5] A[6]
K=1 -32768 42 29 74 11 65 58
K=2 -32768 42 29 74 11 65 58
K=3 -32768 29 42 74 11 65 58
K=4 -32768 29 42 74 11 65 58
K=5 -32768 11 29 42 74 65 58
K=6 -32768 11 29 42 65 74 58
Sorted -32768 11 29 42 58 65 74

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