CBSE Question (Data Structure)
CBSE 2018
(a)Write the definition of a function SumEO(int VALUES[], int N) in C++,which should display the sum of even values and sum of odd values of the array separately.
Example: If the array VALUES contains
25 / 20 / 22 / 21 / 53Then the functions should display the output as:
Sum of even values = 42 (i.e., 20+22)
Sum of odd values = 99 (i.e., 25+21+53)
(b)Write a definition for a function UpperHalf(int Mat[4][4]) in C++, which displays the elements in the same way as per the example shown below.
For example, if the content of the array Mat is as follows:
25 / 24 / 23 / 2220 / 19 / 18 / 17
15 / 14 / 13 / 12
10 / 9 / 8 / 7
The function should display the content in the following format:
25 24 23 22
201918
1514
10
(c)Let us assume Data[20][15] is a two-dimensional array, which is stored in the memory along the row with each elements occupying 2 bytes. Find the address of the element Data[10][5], if the element Data[15][10] is stored at the memory location 15000.
(d)Write the definition of a member function AddPAcket() for a class QUEUE in C++, to remove/delete a Packet from a dynamically allocated QUEUE of Packets considering the following code is already written as a part of the program.
struct Packet
{
char PID;
char Address[20];
Packet *LINK;
};
class QUEUE
{
Packet *Front, *Rear;
public:
QUEUE() Front = NULL; Rear = NULL; }
void AddPacket();
void DeletePacket();
~QUEUE();
};
(e)Convert the following Infix expression to its equivalent Postfix expression, showing the stack content for each step of conversion:
U * V + (W - Z) / X
CBSE 2017
1) (a) Write the definition of a function Reverse(int Arr[], int N) in C++, which should reverse the entire content of the array Arr having N elements, without using any other array.
Example: if the array Arr contains[3]
13 / 10 / 15 / 20 / 5Then the array should become
5 / 20 / 15 / 10 / 13Note:
- The function should only rearrange the content of the array.
- The function should not copy the reversed content in another array.
- The function should not display the content of the array.
(b) Write definition for a function ADDMIDROW(int MAT[][10], int R, int C) in C++, which finds sum of the middle row elements of the matrix MAT (Assuming C represents number of columns and R represents number of rows, which is an odd integer).
For example, if the content of array MAT having R as 3 and C as 5 is as follows:
1 / 2 / 3 / 4 / 52 / 1 / 3 / 4 / 5
3 / 4 / 1 / 2 / 5
The function should calculate the sum and display the following:
Sum of Middle Row : 15[2]
(c)T[25][30] is a two dimensional array, which is stored in the memory along the row with each of its element occupying 2 bytes, find the address of the element T[10][15], if the element T[5][10] is stored at the memory location 25000. [3]
(d) Write the definition of a member function ADDMEM() for a class QUEUE in C++, to add a MEMBER in a dynamically allocated Queue of Members considering the following code is already written as a part of the program. [4]
struct Member
{
int MNO;
char MNAME[20];
Member *Next;
};
class QUEUE
{
Member *Rear, *Front;
public:
QUEUE() { Rear = NULL;Front = NULL; }
void ADDMEM();
void REMOVEMEM();
~QUEUE();
};
(e) Convert the following Infix expression to its equivalent Postfix expression, showing the Stack contents for each step of conversion.
P + ( Q – R ) * S / T[2]
CBSE 2016
1 (a) Write the definition of a function FixPay(float Pay[], int N) in C++, which should modify each element of the array Pay having N elements, as per the following rules: [2]
Existing Value of Pay / PayIf less than 100000 / Add 25% in the existing value
If >= 100000 and < 200000 / Add 20% in the existing value
If >= 200000 / Add 15% in the existing value
(b) T[20][50] is a two dimensional array, which is stored in the memory along the row with each of its element occupying 4 bytes, find the address of the element T[15][5], if the element T[10][8] is stored at the memory location 52000. [3]
(c)Write the definition of a member function INSERT() for a class QUEUE in C++, to insert an ITEM in a dynamic allocated Queue of items considering the following code is already written as a part of the program. [4]
struct ITEM
{
int INO; char INAME[20];
ITEM *Link;
};
class QUEUE
{
ITEM *R, *F;
public:
QUEUE() { R=NULL; F=NULL; }
void INSERT();
void DELETE();
~QUEUE();
};
(d)Write definition for a function SHOWMID(int P[][5], int R, int C) in C++ to display the elements of middle row and middle column from a two dimensional array P having R number of rows and C number of columns. [3]
For example, if the content of array is as follows:
115 / 112 / 116 / 101 / 125103 / 101 / 121 / 102 / 101
185 / 109 / 109 / 160 / 172
The function should display the following as output:
103101121102101
116121109
(e) Convert the fpllowing Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion. [2]
A / ( B + C ) * D - E
CBSE 2015
1 (a) Write the definition of a function Alter(int A[], int N) in C++, which should change all the multiples of 5 in the array to 5 and rest of the elements as 0. For example, if an array of 10 integers is as follows:
A[0] / A[1] / A[2] / A[3] / A[4] / A[5] / A[6] / A[7] / A[8] / A[9]55 / 43 / 20 / 16 / 39 / 90 / 83 / 40 / 48 / 25
After executing the function, the array content should be changed as follows:
A[0] / A[1] / A[2] / A[3] / A[4] / A[5] / A[6] / A[7] / A[8] / A[9]5 / 0 / 5 / 0 / 0 / 5 / 0 / 5 / 0 / 5
(b) A two dimensional array P[20][50] is stored in the memory along the row with each of its element occupying 4 bytes, find the address of the element P[10][30], if the element P[5][5] is stored at the memory location 15000.
(c)Write the definition of a member function Pop() in C++, to delete a book from a dynamic stack of TEXTBOOKS considering the following code is already included in the program.
struct TEXTBOOKS
{
char ISBN[20];char TITLE[80];
TEXTBOOKS *Link;
};
class STACK
{
TEXTBOOKS *Top;
public:
STACK() { Top = NULL; }
void Push();
void Pop();
~STACK();
};
(d)Write a function REVCOL (int P[][5], int N, int M) in C++ to display the content of a two dimensional array, with each column content in reverse order.
Note: Array may contain any number of rows.
For example, if the content of array is as follows:
15 / 12 / 56 / 45 / 5113 / 91 / 92 / 87 / 63
11 / 23 / 61 / 46 / 81
The function should display output as:
1123614681
1391928763
1512564581
(e) Convert the following infix expression to its equivalent Postfix expression showing the stack contents for each step of conversion.
X / Y + U * ( V – W )
CBSE 2014
1)(a) Write code for a function OddEven( int S[ ], int N) in C++, to add 5 in all the odd values and 10 in all the even values of the array S.
Example: If the original content of the array S is
S[0] / S[1] / S[2] / S[3] / S[4]50 / 11 / 19 / 24 / 28
The modified content will be:
S[0] / S[1] / S[2] / S[3] / S[4]60 / 16 / 24 / 34 / 38
(b) An array T[25][20] is stored along the row in the memory with each element requiring 2 bytes of storage. If the base address of array T is 42000, find out the loaction of T[10][15]. Also, find the total number of elements present in this array.
(c) Write a user defined function SumLast3( int A[ ][4], int N, int M) in C++ to find and display the sum of all the values, which are ending with 3 (i.e., units place is 3). For example if the content of array is:
33 / 13 / 9299 / 3 / 12
The output should be
49
(d) Evaluate the following postfix expression. Show the status of stack after execution of each operation separately:
F, T, NOT, AND, F, OR, T, AND
(e) Write a function POPBOOK() in C++ to perform delete operation from a Dynamic Stack, which contains Bno and Title. Consider the following definition of NODE, while writing your C++ code.
struct NODE
{
int Bno;
char Title[20];
NODE *Link;
};
CBSE 2013
2)(a) Write code for a function void Convert(int T[ ], int Num) in C++, which re-positions all the elements of the array by shifting each of them one to one position before and by shifting the first element to the last position.
For example: If the content of the array is
0 / 1 / 2 / 3 / 422 / 25 / 70 / 32 / 12
The changed content will be:
0 / 1 / 2 / 3 / 425 / 70 / 32 / 12 / 22
(b) An array P[15][10] is stored along the column in the memory with each element requiring 4 bytes of storage. If the base address of array P is 14000, find out the location of P[8][5].
(c) Write a user-defined function DispNTen(int L[ ][4], int R, int C) in C++ to find and display all the numbers, which are not divisible by 10.
For example if the content of array is:
20 / 17 / 3012 / 19 / 10
The output should be
17 12 19
(d) Evaluate the following postfix expression. Show the status of stack after execution of each operation:
60, 6, /, 5, 2, *, 5, -, +
(e) Write a function QINSERT() in C++ to perform insert operation on a Linked Queue, which contains Client no and Client name. Consider the following definition of NODE in the code of QINSERT().
struct NODE
{
long int Cno;// Client No
char Cname[20];// Client Name
NODE *Next;
};
CBSE 2012
1. (a) Write a function SWAP2CHANGE( int p[ ], int N ) in C++ to modify the content of the array in such a way that elements, which are multiples of 10 swap with the value present in the very next position in the array.
For example:
If the content of array P is
91, 50, 54, 22, 30, 54
The content of array P should become
91, 54, 50, 22, 54, 30
(b) An array S[10][30] is stored in the memory along the column with each of the element occupying 2 bytes. Find out the memory location of S[5][10], if the element S[2][15] is stored at the location 8200.
(c) Write a function in C++ to perform Insert operation in Dynamic Queue containing DVD’s information (represented with the help of an array of structure DVD).
struct DVD
{
long No;
char Title[20];
DVD *Link;
};
(d) Write a function SKIPEACH( int H[][3], int C, int R) in C++ to display all alternate elements from two-dimensional array H (starting from H[0][0] ).
For example:
If the array is containing:
124567
339076
214359
The output will be
1267902159
(e) Evaluate the following POSTFIX notation. Show status of Stack after every step of evaluation (i.e. after each operator).
False, NOT, True, AND, True, False, OR, AND
CBSE 2011
2. (a) Write GetFrom2() function in C++ to transfer the content from two arrays FIRST[ ] and SECOND[ ] to array ALL[ ]. The even places (0, 2, 4, .....) of array ALL[ ] should get the content from the array FIRST[ ] and odd places (1, 3, 5, ....) of the array ALL[ ] should get the content from the array SECOND[ ].
Example:
If the FIRST[ ] array contains
30, 60, 90
And the SECOND[ ] array contains
10, 50, 80
The ALL[ ] array should contains
30, 10, 60, 50, 90, 80
(b) An array P[20][50] is stored in the memory along the column with each of its element occupying 4 bytes, find out the location of P[15][10], if P[0][0] is stored at 5200.
(c)Write a function in C++ to perform Insert operation on a dynamically allocated Queue containing Passenger details as given in the following definition of NODE.
struct NODE
{
long Pno;// Passenger Number
char PName[20];// Passenger Name
NODE *Link;
};
(d)Write a COLSUM( ) function in C++ to find sum of each column of NxM Matrix.
(e)Evaluate the following postfix notation of expression :
50, 60, +, 20, 10, -, *
CBSE 2010
3. (a)Write a function CHANGE( ) in C++, which accepts an array of integer and its size as parameters and divide all those array elements by 7 which are divisible by 7 and multiply other array elements by 3.
Sample Input Data of the array
A[0]A[1]A[2]A[3]A[4]
2112354218
Sample Output of the array
A[0]A[1]A[2]A[3]A[4]
3365654
(b) An Array P[50][60] is stored in the memory along with each of the element occupying 2 bytes, find out the memory location for the element P[10][20], if the Base Address of the array is 6800.
(c)Write complete program in C++ to implement a dynamically allocated Stack containing names of Countries.
(d)Write a function int SKIPSUM( int A [ ] [3], int N, int M) in C++ to find and return the sum of elements from all alternate elements of a two-dimensional array starting from A[0][0].
Hint:
If the following is the content of the array
A[0][0]A[0][1]A[0][2]
4 51
A[1][0]A[1][1]A[1][2]
2 87
A[2][0]A[2][1]A[2][2]
9 63
The function SKPSUM() should add elements A[0][0], A[0][2], A[1][1], A[2][0] and A[2][2].
(e)Evaluate the following postfix notation of expression:
(Show status of Stack after each operation)
False, True, NOT, OR, True, False, AND, OR
CBSE 2009
4. (a)Write a function SORTPOINTS( ) in C++ to sort an array of structure Game in descending order of Points using Bubble Sort.
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)
PnoPNamePoints
103Ritika Kapur3001
104John Philip2819
101Razia Abbas3451
105Tarun Kumar2971
Sample content of the array (after sorting)
PnoPNamePoints
101Razia Abbas3451
103Ritika Kapur3001
105Tarun Kumar2971
104John Philip2819
(b)An array S[40][30] is stored in the memory along the column with each of the element occupying 4 bytes, find out the base address and address of element S[20][15], if an element S[15][10] is stored at the memory location 7200.
(c)Write a function QUEINS( ) in C++ to insert an element in a dynamically allocated Queue containing nodes of the following given structure:
struct Node
{
int Pid// Product id
char Pname[20];
Node *Next;
};
(d)Define a function SWAPCOL( ) in C++ to swap (interchange) the first column elements with the last column elements, for a two dimensional integer array passed as the argument of the function.
Example: If the two dimensional array contains
2149
1377
5863
7212
After swapping the content of first column and last column, it should be:
9142
7371
3865
2217
(e)Convert the following infix expression to its equivalent postfix expression showing stack contents for the conversion:
X - Y / ( Z + U ) * V
CBSE 2008
5. (a)Write a function in C++, which accepts an integer array and its size as parameters and rearranges the array in reverse.
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
(b)An array Arr[40][10] is stored in the memory along the column with each element occupying 4 bytes. Find out the address of the location Arr[3][6] if the location A[30][10] is stored at the address 9000.
(c)Write a function in C++ to insert an element into a dynamically allocated Queue where each node contains a name ( of type string ) as data.
Assume the following definition of THENODE for the same.
struct THENODE
{
char Name[20];
THENODE *Link;
};
(d)Write a function in C++ to print the product of each column of a two dimensional integer array passed as the argument of the function.
Example: If the two dimensional array contains
124
356
432
215
Then the output should appear as:
Product of Column 1 =24
Product of Column 2 =30
Product of Column 3 =240
(e)Evaluate the following postfix notation of expression
(Show status of stack after execution of each operation)
4,10,5,+,*,15,3,/,-
CBSE 2007
6. (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.
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
(b)An array Array[20][15] is stored in the memory along the column with each element occupying 8 bytes. Find out the Base Address and address of the element Array[2][3] if the element Array[4][5] is stored at address 1000.
(c)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.
struct Book
{int BNo;
char BName[20];
Book *Next;
};
(d)Write a function in C++ which accepts a 2D array of integers and its size as arguments and displays the elements which lie on diagonals.
[ Assuming the 2D Array to be a square matrix with odd dimension i.e., 3x3, 5x5, 7x7..]
Example, if the array content is
543
678
129
Output through the function should be:
Diagonal One:579
Diagonal Two:371
(e) Evaluate the following postfix notation of expression:
2583-/6*10+
CBSE 2006
7. (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 :
If the array is 1, 2, 3, 4, 5, 6If the array is 1, 2, 3
The resultant 2 D array is given belowThe resultant 2 D array is given below
123456123
123450120
123400100
123000
120000
100000
(b)An array MAT[30][10] is stored in the memory column wise with each element occupying 8 bytes of memory. Find out the base address and the address of element MAT[20][5], if the location of MAT[5][7] is stored at the address 1000.
(c)
class queue
{int data[10];
int front, rear;
public:
queue(){front = -1;rear = -1;}
void add();// to add an element into the queue
void remove();// to remove an element from the queue
void Delete(int ITEM); // to delete all elements which are equal to ITEM
};
Complete the class with all function definitions for a circular array Queue. Use another queue to transfer data temporarily.
(d)Write a function in C++ to perform a PUSH operation on a dynamically allocated stack containing real number.
(e)Write the equivalent infix expression for :
a, b, AND, a, c, AND, OR
CBSE 2005
8. (a)Write a function in C++ which accepts an integer array and its size as arguments/ parameters and exchanges the value of first half side elements with the second half side elements of the array.
Example:
If an array of eight elements has initial content
2, 4, 1, 6, 7, 9, 23, 10
The function should rearrange the array as
7, 9, 23, 10, 2, 4, 1, 6
(b) An array Arr[15][35] is stored in the memory along the column with each of its elements occupying 8 bytes. Find out the base address and the address of an element Arr[2][5], if the location Arr[5][10] is stored at the address 4000.
(c)Write a function in C++ to perform a PUSH operation in dynamically allocated stack considering the following:
struct Node
{
int X, Y;
Node *Link;
};
class STACK
{
Node * Top;
public:
STACK() { Top = NULL; }
void PUSH();
void POP();
~STACK();
};
(d) Write a function in C++ to print the sum of all the values which are either divisible by 2 or are divisible by 3 present in a two dimensional array passed as the argument to the function.
(e)Evaluate the following postfix notation of expression:
10,20,+,25,15,-,*,30,/
CBSE 2004
9. (a)Define a function Reversearray ( int [ ], int), that would accept a one dimensional integer array NUMBERS and its size N. The function should reverse the contents of array without using any second array.
Note: Use the concept of swapping elements
(If the array initially contains)
{ 2, 15, 3, 14, 7, 9, 19, 6, 1, 10 }
then after reversal the array should contain
{ 10, 1, 6, 19, 9, 7, 14, 3, 15, 2 }
(b)An array ARR[5][5] is stored in the memory with each element occupying 4 bytes of space. Assuming the base address of ARR to be 1000, compute the address of ARR[2][4], when the array is stored:
(i) Row Wise(ii) Column Wise
(c)Write a function in C++ to find and display the sum of each row and each column of a 2 dimensional array of type float.
(d)Evaluate the following Postfix notation of expression, show status of stack for each operation: 500, 20, 30, +, 10, *, +
(e)Define functions stackpush() to insert nodes and stackpop() to delete nodes, for a linked list implemented stack having the following structure for each node:
struct node
{char name[20];
int age;
node *Link;
};
class stack
{node *top;
public:
stack()
{top = NULL;}
void stackpush();
void stackpop();
};
Made by Kanhaya Sir (Mobile No: 9868772318)