Claas Notes... Array
Claas Notes... Array
Claas Notes... Array
1. Write the definition of a function Change (int P [ ], int N) in C++, which should change all [2] [2015]
the multiples of 10 in the array to 10 and rest of the elements as 1. For example, if an array
of 10 integers is as follows :
After executing the function, the array content should be changed as follows : P[0]
2. Write code for a function void EvenOdd ( int T[ ], int C ) in C++, to add 1 in all the odd [3] [2014]
values and 2 in all the even values of the array T.
Example : If the original content of the array T is
3. Write the definition for a function void Transfer (int A [6], int B [6] ) in C++, which takes [3] [2013]
two integer arrays, each containing 6 elements as parameters. The function should
exchange all odd places (1st, 3rd and 5th ) of the two arrays, for example
If the array A contains
4. Write a function SWAP2BEST (int ARR [ ], int Size) in C++ to modify the content of the [3] [2012]
array in such a way that the 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 ARR is
90, 56, 45, 20, 34, 54
The content of array ARR should become
56, 90, 45, 34, 20, 54
5. Write a Get1From2 ( ) function in C++ to transfer the content from two arrays FIRST [ ] [3] [2011]
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 contain
30, 10, 60, 50, 90, 80
6. Write a function CHANGE( ) in C++, which accepts an array of integer and its size as [3] [2010]
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
7. Given two arrays A and B. Array A contains all the elements of „B‟ but one more element [3] [2009]
extra. Write a c++ function which accepts array A and B and its size as arguments /
parameters and find out the extra element in Array A. (Restriction: array elements are not
in order)
Page 3 of 9
Example:
If Array A is {14, 21, 5, 19, 8, 4, 23, 11}
and Array B is {23, 8, 19, 4, 14, 11, 5 }
Then output will be 5 (extra element in Array A)
8. Write a function in C++ which accepts a integer array and its size as an arguments and [4] [2008]
prints the output (using nested loops) in following format :
Example : if the array is having
12459
Then the output should be
1
22
4444
55555
999999
9. Write a function in C++ which accepts an integer array and its size.as arguments and [4] [2007]
replaces elements having even values with its half and elements having odd 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
6, 2, 10, 8, 18
10. Write a function in C++ which accepts an integer array and its size as arguments / [4] [2006]
parameters and then assigns the elements into a two dimensional array of integers in the
following format:
If the array is 1, 2, 3, 4, 5, 6
The resultant 2 D array is given below
0 0 0 0 0 1
0 0 0 0 2 1
0 0 0 3 2 1
0 0 4 3 2 1
0 5 4 3 2 1
6 5 4 3 2 1
If the array is 1, 2, 3
The resultant 2 D array is given below
0 0 1
0 2 1
3 2 1
11. Write a function bubble sort to sort the passed array of 10 integers in descending order [2] [2006]
using bubble sort.
Page 4 of 9
1. Write a function REVROW (int P [ ] [5], int N, int M) in C++ to display the content of a [3] [2015]
two dimensional array, with each row content in reverse order.
For example, if the content of array is as follows :
15 12 56 45 51
13 91 92 87 63
11 23 61 46 81
The function should display output as:
51 45 56 12 15
63 87 92 91 13
81 46 61 23 81
2. Write a user-defined function AddEnd2 (int A [ ] [4], int N, int M) in C++ to find and [2] [2014]
display the sum of all the values, which are ending with 2 (i.e., units place is 2).
For example if the content of array is :
22 16 12
19 5 2
The output should be 36.
3. Write a user-defined function int SumSingle ( int A [4] [4] ) in C++, which finds and [2] [2013]
returns the sum of all numbers present in the first row of the array, for example, if the array
contains
4. Write a function ALTERNATE ( int A [ ] [ 3 ], int N, int M ) in C++ to display all alternate [2] [2012]
elements from two-dimensional array A (starting from A [ 0 ] [ 0 ] ).
For example : If the array is containing :
23 54 76
37 19 28
62 13 19
The output will be
23 76 19 62 19
5. Write a COLSUM ( ) function in C++ to find sum of each column of a N x M Matrix. [2] [2011]
Page 5 of 9
6. Write a function int SKIPSUM (int A [ ] [3], int N,int M) in C++ to find and return the sum [2] [2010]
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
25. Write a function in C++ which accepts an integer array and its size as arguments / [3] [2009]
parameters and assigns the elements into a two dimensional array of integers in the
following format.
if the array is 9,8,7,6,5,4 The resultant 2D array is given below
if the array is 1, 2, 3
The resultant 2D array is given below
31. Write a function in C++ which accepts a 2D array of integers and its size as arguments and [2] [2007]
displays the elements of middle row and the elements of middle column.
[Assuming the 2D Array to be a square matrix with odd dimension i.e. 3×3, 5×5, 7×7 etc...]
Example, if the array content is
354
769
218
Output through the function should be :
Middle Row : 7 6 9
Middle Column : 5 6 1
Page 6 of 9
2. A two dimensional array ARR [50] [20] is stored in the memory along the row with each of [3] [2015]
its elements occupying 4 bytes. Find the address of the element ARR [30] [10], if the
element ARR [10] [5] is stored at the memory location 15000.
6. An array A[20][30] is stored along the row in the memory with each element requiring 4 [3] [2014]
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.
10. An array S [10] [15] is stored in the memory with each element requiring 2 bytes of [3] [2013]
storage. If the base address of array S is 25000, determine the location of S [5] [10] if the
array S is stored along the column.
14. An array T [20] [10] is stored in the memory along the column with each of the elements [3] [2012]
occupying 2 bytes. Find out the memory the memory location of T [10] [5], if the element
T [2] [9] is stored at the location 7600.
18. An array P[20] [50] is stored in the memory along the column with each of its [2] [2011]
element occupying 4 bytes, find out the 1ocation of P[15][10], if P[0][0] is
stored at 5200.
22. An array P[50][60] is stored in the memory along the column with each of the [3] [2010]
element occupying 2 bytes, find out the memory location for the element P[10]
[20], if the Base Address of the array is 6800.
26. Each element of an array DATA[10][10] requires 8 bytes of storage. If base address of [4] [2009]
array DATA is 2000, determine the location of DATA[4][5], when array is stored
(i) Row-wise.
(ii) Column-wise
28. An array A[10][20] is stored in the memory with each element occupying 2 bytes of [3] [2008]
storage. If the Base address of array in the memory is 800 , determine the location of
A[9][10] when the array is stored as (i) Row Major (ii) column major.
30. An array Arr[15][20] is stored in the memory along the row with each element [4] [2007]
occupying 4 bytes. Find out the Base Address and address of the element Arr[3][2],
if the element Arr[5][2] is stored at the address 1500.
33. An array MAT [15] [7] is stored in the memory along the column with each element [4] [2006]
occupying 2 bytes of memory. Find out the base address and the address of element MAT
[2] [5], if the location of MAT [5] [4] is stored at the address 100.
Page 7 of 9
CHAPTER 2: STACK
1. Write the definition of a member function PUSH( ) in C++, to add a new book in a [4] [2015]
dynamic stack of BOOKS considering the following code is already included in the
program :
struct BOOKS
{ char ISBN[20], TITLE[80];
BOOKS *Link;
};
class STACK
{ BOOKS *Top;
public:
STACK(){Top=NULL;}
void PUSH();
void POP();
~STACK();
};
2. Convert the following Infix expression to its equivalent Postfix expression, showing the [2] [2015]
stack contents for each step of conversion : U * V + R / ( S – T )
3. Evaluate the following postfix expression. Show the status of stack after execution of each [2] [2014]
operation separately : T, F, NOT, AND, T, OR, F, AND
4. Write a function PUSHBOOK ( ) in C++ to perform insert operation on a Dynamic Stack, [4] [2014]
which contains Book_no and Book_Title. Consider the following definition of NODE,
while writing your C++ code.
struct NODE
{ int Book_No;
char Book_Title[20];
NODE *Next;
};
5. Evaluate the following postfix expression using a stack and show the contents of stack [2] [2013]
after execution of each operation: 5, 3, 2, *, 4, 2, /, -, *
6. Write a function in C++ to perform Insert operation in a static circular Queue containing [4] [2012]
Book’s information (represented with the help of an array of structure BOOK).
struct BOOK
{ long Accno; // Book Accession Number
Char Title [20]; // Book Title
};
Page 8 of 9
7. Evaluate the following POSTFIX notation. Show status of Stack after every step of [2] [2012]
evaluation (i.e. after each operator): True, False, NOT, AND, False, True, OR, AND
8. Evaluate the following postfix notation of expression: 50, 60, + , 20, 10, -, * [2] [2011]
9. Write a complete program in C++ to implement dynamically allocated Stack containing [4] [2010]
names of Countries.
10. Evaluate the following postfix notation of expression: (Show status of Stack after each [2] [2010]
operation) False, True, NOT, OR, True, False, AND, OR
11. Write the function to perform push and pop operation on a dynamically allocated stack of [4] [2009]
customers implemented with the help of the following structure:
struct employee
{ int eno;
char ename[20];
employee *link;
};
12. Evaluate the following postfix notation of expression: 5, 11, , 6, 8, +, 12, *, / [2] [2009]
13. Consider the following portion of a program , which implements a linked stack for [3] [2008]
Library. Write the definition of function PUSH(),to insert a new node in the stack with
required information.
struct Library
{ int id;
char names[20];
};
class stack
{ Library *top;
public :
stack() { top=NULL; }
void PUSH();
void POP();
};
14. Convert the following infix expression into postfix. show the stack status after execution [2] [2008]
of each operation: TRUE OR FALSE AND NOT FALSE OR FALSE
16. Evaluate the following postfix expression using a stack and show the contents of the stack [2] [2006]
after execution of each operation. 5, 10, *, 20, 2, /, +
CHAPTER 3: QUEUE
1. Give the necessary declaration of linked implemented Queue containing players information [4] [2013]
(as defined in the following definition of Node). Also write a user defined function in C++ to
delete one Player’s information from the Queue.
struct Node
{ int PlayerNo;
char PlayerName[20];
Node *Link;
}
2. Write a function in C++ to perform Insert: operation on a dynamically allocated Queue [4] [2011]
containing Passenger details as given in the following definition of NODE.
struct NODE
{ long Pno; //passenger Number
char Pname[20] ; //passenger Name
NODE *Link.;
};
3. Write a function in C++ to delete a node containing names of student , from a dynamically [3] [2008]
allocated Queue of names implemented with the help of following structure :
struct student
{ char name[20];
student *next;
} *front , *rear;
4. Write a function in C++ to delete a node containing customer’s information, from a [4] [2007]
dynamically allocated Queue of Customers implemented with the help of the following
structure :
struct Customer
{ int CNo;
char CName[20];
Customer *Link;
};
5. What is circular queue? How is it different from simple queue? Write a function in C++ to [4] [2006]
perform Delete operation in dynamically allocated Queue containing names of students.