SEPTEMBER MONTHLY TEST, YEAR:2016, CLASS: 12-D
SUBJECT: COMPUTER SCIENCE,
ANSWER KEY
MAX. MARKS:
35 DURATION:
1 ½ Hours
1) Write a function EXCHANGE (int A [ ],
int S) in C++ to modify the content of the array in such a way that the
elements, which are multiples of 15 exchange with the value present in the very
next position in the array. -2
For example:
If the content of array A is: 105, 56,
43, 60, 34, 54
The content of array A should become:
56, 105, 43, 34, 60, 54
2) Write user defined function
DispTen(int A[][4], int N, int M) in C++ to find and display all the members,
which are divisible by 10. For example
if the content of array is: -3
12
|
20
|
13
|
2
|
10
|
30
|
5
|
50
|
7
|
The output should be: 20, 10, 30, 50
3a) An array A[20][30] is stored along
the row in the memory with each element requiring 4 bytes of storage. If the base address of array A is 32000, find
out the location of A[15][10]. Also,
find the total number of elements present in this array. -3
Ans: 33840
3b) A 2-D array defined as A[5…20,2..15]
requires 2 words of storage space for each element. If the array is stored in Row-major form,
calculate the address of A[6,2] given the base address is 100. -3
Ans: 128
4a) An array T[20][10] is stored in the
memory along the column with each of the elements occupying 2 bytes. Find out the memory location of
T[10][15]. If the element T[2][9] is
stored at the location 7600. -3
Ans: Base Address= 7236 and T[10][15]= 7856
Ans: Base Address= 7236 and T[10][15]= 7856
4b) Each element of an array A[10…30,
10…35] requires one byte of storage. If the array is stored in column major
order beginning location 500, determine the location of A[12][15]. -3
Ans: 607
5) Write a function in C++ to Insert a node containing Book’s information, from a
dynamically allocated Stack of Books implemented with the help of the following structure -4
struct Book
{
int BNo;
char BName[20];
Book *Next;
}
Ans:void insert(book*ptr) //assuming top is used for top of stack
{
if(top==NULL) top=ptr;
else{
ptr->next=top;
top=ptr;}
}
Ans:void insert(book*ptr) //assuming top is used for top of stack
{
if(top==NULL) top=ptr;
else{
ptr->next=top;
top=ptr;}
}
6) Write a function in C++ to delete a
node containing Book’s information, from a dynamically allocated Stack of Books
implemented with the help of the following structure. -4
struct Book
{
int BNo;
char BName[20];
Book *Next;
}
ANS: void delete() //assuming *tmp is a global object of book
{
tmp=top;
top=top->next;
delete tmp;
}
ANS: void delete() //assuming *tmp is a global object of book
{
tmp=top;
top=top->next;
delete tmp;
}
7) Write a function QInsertion( ) in C++
to perform Insertion operation on a Linked Queue, which contains Passenger no
and Passenger name. Consider the
following definition of node in the code. -4
struct node
{
long int pno;
Char pname[20];
node *link;
}
ANS: void qinsertion(node*ptr) //front and rear are member of node
{
if (front==NULL) front=rear=ptr;
else{
rear->link=ptr;
rear=ptr;}
}
8) Write a function QDelete( ) in C++ to perform delete operation on a Linked Queue, which contains Passenger no and Passenger name. Consider the following definition of node in the code. -4
ANS: void qinsertion(node*ptr) //front and rear are member of node
{
if (front==NULL) front=rear=ptr;
else{
rear->link=ptr;
rear=ptr;}
}
8) Write a function QDelete( ) in C++ to perform delete operation on a Linked Queue, which contains Passenger no and Passenger name. Consider the following definition of node in the code. -4
struct node
{
long int pno;
Char pname[20];
node *link;
}
ANS: void q
ANS: void q
9) Evaluate the following postfix
expression. Show the status of stack
after execution of each operation. 5, 6, * , 50, 5, /, 5, -, + -2
Ans: 35
***GOOD
LUCK***
No comments:
Post a Comment