For Solution  call and mail: Mo.No.:9810301034,  g9_sharma@yahoo.comSet 2    1-D Array Assignment
1.   WAP input the element of array then display output of array size 16.
2.      WAP to addall elements of array then display the result size 16.
3.      WAP [Square display/ Square then display] the all element of the array then display size 16.
4.      WAP to multiply all element of array then display result size 12.
5.      WAP (Find/Count/Replace even by 0 odd by 1)t even and odd in array element size 16.
6.      WAP (Find/Count/Replace)an element in an array size 16
7.      WAP . (Find/Count/Replace by 0) prime no in array elements size 16
8.      WAP Add all prime and odd numbers of array size 13.
9.      WAP [Reverse display, Reverse then display]array elements and then display size 16.
10.  WAP the no.(element) of the array when no. is even multiply by 2 when add multiply by 3 and display the array.
11.  WAP to add all even and odd element of array in different variable size 11. (Find/Count)


For Solution  call and mail: Mo.No.:9810301034,  g9_sharma@yahoo.com
Set 3    2 D Array Assignment
1.      WAP input the 2D array and add the all element of array then display the result with elementssize 3*3.
2.      WAP [Square display/Square then display]the all elements of array then display size 3*3.
3.      WAP to (Find/Count/Replace) an element in arraysize 3*3.
4.      WAP to change the search elementssize 3*3.
5.      WAP to display diagonal no. of array {Right & Left diagonal square matrix}.
6.      WAP to Add diagonal no. of array{Right & Left diagonal square matrix}.
7.      WAP to replace all diagonal no. of array by 0 {Right & Left diagonal square matrix}.
8.      WAP to replace all diagonal no. of array by N {Right & Left diagonal square matrix}.
9.       WAP to matrix:-  a. Add, b. Subtract, c. Divide, d. MultiplyFor Solution  call and mail: Mo.No.:9810301034,  g9_sharma@yahoo.com

Set 4  2D
1.      From a 2D array ARR[3][3] WAP to prepare one dimensions array ARR2[9] that will  have all the elements of ARR as if they are stored in row major form.
a.      1 2 3
b.      4 5 6
c.       7 8 9   then should contain 123456789
2.        Write program in C++ to print the row sum and column sum of a matrix
3.      Write program to display sum of upper half elements of a square matrix. The function will return the sum of the values.                       
1
2
3
 4
5
6
7
8
9
R1=1+2+3+4+5+7,R2=1+4+5+7+8+9, R3=1+2+3+5+6+9, R4=3+5+6+7+8+9
 For Solution  call and mail: Mo.No.:9810301034,  g9_sharma@yahoo.com

4.      WAP in C++ which accepts a 2D array of integers and its size as arguments and displays the elements of middle row and the elements of middle column. Assuming the 2D array to be a square matrix with odd dimensions i.e., 3x3, 5x5, 7x7  eg.,
4 5 6 output through the function should be
7 8 9Middle row 7 8 9
3 2 1    Middle col. 5 8 2
5.      WAP in C++ which will accept a 2 D Array of integer and return the sum of all the elements divisible by 5 that lie on the even row number. 
6.      WAP in C++ to print the product of each column of a two dimensional integer array passed as the argument of the function. Explain: if the two dimensional arrays contains
1
2
4
3
5
6
4
3
2
2
1
5

Then the output should appear as:   Product of Column 1=24,    Product of Column 2=30, Product of Column 3=240


7.      WAP in C++ which accepts a 2-D array of integers and its size as arguments and prints no of even numbers and odd numbers in each column.                                      
If the array is              11        12        31        41
52  62        71        82
9          10        11        12
The output will be:     Column 1:       Even numbers : 1       Odd numbers : 2
Column 2: Even numbers : 3       Odd numbers : 0
Column 3:       Even numbers : 0       Odd numbers : 3
Column 4: Even numbers : 2       Odd numbers : 1






Very Important Questions:

0
1
2
0
1
17
2
1
12
3
5
2
7
19
8
Q1. 3*3 2d Array




Display :
1  First Row
1
17
2
A[i][0]
2  Last Row
7
19
8
A[i][n-1]
3  First Column
1
12
7
A[0][i]
4 Last Column
2
5
8
A[n-1][i]
5 Mid Row
12
3
5
A[n/2][i]
6 Mid Column
17
3
19
A[i][n/2]
7 Right Diagonal
1
3
8
if(i==j ) A[i][j]
8 Left Diagonal
2
3
7
if((i+j)==(n-1) ) A[i][j]
9 Row Sum
20
20
34
s=s+A[i][j];
10 Column Sum
10
39
15
s=s+A[j][i];
11 Total Sum Of Row/Column
74
74

r=r+s;, c=c+s;

Q2.                   Input                                                    Output 1                                            Output 2

0
1
2
3
0
1
17
2
4
1
12
3
5
13
2
7
19
8
6
3
10
7
0
9

0
1
2
3
0
10
7
0
9
1
12
3
5
13
2
7
19
8
6
3
1
17
2
4

0
1
2
3
0
1
17
2
4
1
7
19
8
6
2
12
3
5
13
3
10
7
0
9



=>                    =>


Q3.                   Input                                                    Output 1                                            Output 2

0
1
2
3
0
1
17
2
4
1
12
3
5
13
2
7
19
8
6
3
10
7
0
9

0
1
2
3
0
4
17
2
1
1
13
3
5
12
2
6
19
8
7
3
9
7
0
10

0
1
2
3
0
1
2
17
4
1
12
5
3
13
2
7
8
19
6
3
10
0
7
9


ð   




Searching Sorting


Linear Search:
int linear_search(int a[],int n, int item)
{
for(int i=0; i<n; i++)
{ if(a[i]==item)
return i;
}For Solution  call and mail: Mo.No.:9810301034,  g9_sharma@yahoo.com


Binary Search


int binary_search(int a[],int n, int item)
{int beg,mid,last;
beg=0;
last=n-1;
while(beg<=last)
{
 mid = (beg + last)/2;
if(item==a[i])
return mid;
else if(item>a[mid])
beg=mid+1;
else
last=mid-1;
}
return -1;
}


Sorting
Sorting means arranging the elements in some specific order, i.e. either ascending or descending order. The various sorting techniques available are
(i) Insertion Sort: Initially, the first element is assumed to be sorted. In the first pass, 2nd element is inserted into its proper place in the sorted part of the array. Similarly in the next pass, the 3rd element is placed and so on. Given below is the insertion sort for ascending order.
Array at beginning:
42
29
74
11
65
58
After pass 1
29
42
74
11
65
58
After pass2
29
42
74
11
65
58
After pass 3
11
29
42
74
65
58
After pass 4
11
29
42
65
74
58
After pass 5
11
29
42
58
65
74
Sorted Array
11
29
42
58
65
74


//function for Insertion Sort
void InsertionSort(int a[],int n)
{
 int i,j,temp;
for(i=1;i<n;i++)
{
 temp=a[i];
j=i-1;
while(temp<a[j])&&j>=0)
{
a[j+1]=a[j];
j--;
}
a[j+1]=temp;
cout<,”\n After Pass “<<i ;
for(k=0;k<n;k++)
cout<<a[k];
} }


(ii) Selection Sort: The element with the smallest value (if found) is swapped with the first element. As a result of this interchange, the smallest element is placed in the 1st position of the array. In the second pass, second smallest element is searched and swapped with second element and so on. Given below is the selection sort for ascending order.
Array at beginning:
42
29
74
11
65
58
After pass 1
11
29
74
42
65
58
After pass2
11
29
74
42
65
58
After pass 3
11
29
42
74
65
58
After pass 4
11
29
42
58
65
74
After pass 5
11
29
42
58
65
74
Sorted Array
11
29
42
58
65
74


//function for Selection Sort
void SelectionSort(int a[],int n)
{
 int i,small,pos,temp;
for(i=0;i<n;i++)
{
small=a[i];
pos=i;
for(j=i+1;j<n;j++)
{
if(a[j]<small)
{small=a[j];
Pos=j;
}
}
temp=a[i];
a[i]=a[pos];
a[pos]=temp;
cout<,”\n After Pass “<<i+1 ;
for(j=0;j<n;j++)
cout<<a[j];
}
}


(iii) Bubble Sort: In this technique, two adjacent values are compared and they are exchanged if not in proper order. In every pass, the larger element settles at its appropriate position in the bottom. Given below is the bubble sort for ascending order.
Array at beginning:
42
29
74
11
65
58
After pass 1
29
42
11
65
58
74
After pass2
29
11
42
58
65
74
After pass 3
11
29
42
58
65
74
After pass 4
11
29
42
58
65
74
After pass 5
11
29
42
58
65
74
Sorted Array
11
29
42
58
65
74


//function for Bubble Sort
void BubbleSort(int a[],int n)
{
 int temp;
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1;j++)
{
if(a[j]>a[j+1])
{temp=a[j];
A[j]=a[j+1];
A[j+1]=temp;
} }
cout<,”\n After Pass “<<i+1 ;
for(int k=0;k<n;k++)
cout<<a[k];
} }


(iv) Merge Sort: Merging is the process of combining two or more sorted arrays into another array which is also sorted. In merge sort the array is sorted while merging.
Suppose we have to merge array A and array B. The first element of array A is compared with the first element of array B. If the first element of array A is smaller than the first element of array B, the element from array A is moved to the new array C. The subscript of array A is now increased since the first element is now set and we move on. If the element from array B should be smaller, it is moved to the new array C. The subscript of array B is increased. This process of comparing the elements in the two arrays continues until either array A or array B is empty. When one array is empty, any elements remaining in the other (non-empty) array are "pushed" into the end of array C and the merge is complete.


//function for Merge Sort
void MergeSort(int a[],int b[],int c[],int m,int n)
{ int i=0,j=0,k=0,r;
while(i<m &&j<n)
{ if(a[i]<=b[j])
{c[k]=a[i];
i++;
}
else
{c[k]=b[j];
j++;
}
k++;
}
if(i==m)
{for(r=j;r<n;r++)
{ c[k]=b[r];
k++;
}
}
else
{
for(r=i;r<m;r++)
{
 c[k]=a[r];
k++;
}
}
}For Solution  call and mail: Mo.No.:9810301034,  g9_sharma@yahoo.com


WORKSHEET 2D/1D
Q1.  Write a function in C++ to combine the contents of two equi-sized arrays A and B by computing their corresponding elements with the fornula 2 *A[i]+3*B[i], where value I varies from 0 to N-1 and transfer the resultant content in the third same sized array.
Q2.  Write a function in C++ to merge the contents of two sorted arrays A and B, into the third array C. Assume array A is sorted in ascending order, B is sorted in descending order, the resultant array is required to be in ascending.
Q3.  Write a function in C++ which will accept a 2 D Array of integer and return the sum of all the elements divisible by 5 that lie on the even row number.
Q4.  Assume an array A containing elements of structure Accountant is required to be arranged in descending order of salary. Write a C++ program to arrange the same with the help of bubble sort. The array and its size is required to be passed as parameters to the functions. Definition of structure Account is as under:
struct Account {              int Accno;            char AName[25]; };
Q5.  Given two arrays of integers x and y of sizes m and n respectively. Write a function named MERGE( ) which will produce a third array named z, such that the following sequence is  followed:
1.      All odds numbers of x from left to right are copied into z from left to right.
2.      All even number of x from left to right are copied into z from right to left.For Solution  call and mail: Mo.No.:9810301034,  g9_sharma@yahoo.com
3.      All odd numbers of y from left to right are copied into z from left to right.
4.      (iv)All even number of y from left to right are copied into z from right to left.
Eg: x is{3,2,1,7,6,3}  And y is {9,3,5,6,2,8,10} Then z = {3,1,7,3,9,3,5,10,8,2,6,6,2}
Q6.  Write a user define function to multiply two given 2D Matrices using functions.
Q7.  Write a user defined function named upperhalf( ) which takes a 2D array A, with size n rows  and n cols as
arguments and print the upper half of the matrix
1 2 3                                                    1 2 3
6 7 8                                                       7 8
2 3 4                                                          4
Q8.  Write a user defined function named lowerhalf () which takes a 2D array, with size n, n rows and n cols as arguments and prints the lower half of the matrix.
Eg;   
1 2 3                                    1
5 6 7                                    5 6
9 1 2                                    9 1 2
Q9.  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 .eg:  if the array contains  3, 4, 5, 16, 9 then the function should be rearranged as 6, 2,10,8, 18
Q10.   Write a function in C++ which accepts an integer array and its size as argument / 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 6
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
Q11.   Write a function in C++ which accepts a 2D array of integers and ts size as arguments and  displays the elements of middle row and the elements of middle column. Assuming the 2D array to be a square matrix with odd dimensions i.e., 3x3, 5x5, 7x7
eg.,
4 5 6
7 8 9
3 2 1output through the function should bemiddle row 7 8 9 , middle column  5 8 2
Q12.   Define a function Reversearray(int[], int) that would accept a one dimensional integer array NUMBERS and its size N. The function should reverse the content of the array without using any second array. Note: use the concept of swapping the elements.
Eg; if the array initially contains  2,15,7,8,10,1,13  after swapping should contain 31,1,10,8,7,15,2
Q13.   Given an array named A with following elements 3,-5,1,3,7,0,-15,3,-7,-8  write a C++ function to shift all the negative numbers to le ft so that the resultant array may look like -5,-15,-7,-8,3,1,3,7,0,3
Q14.   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 odd location eg., if the array initially contains  2, 4, 1, 6, 5, 7, 9, 2, 3, 10 then it should contain                 4, 2, 6, 1, 7, 5, 2, 9, 10, 3
Q15.   From a 2D array ARR[3][3] write a program to prepare one dimensions array ARR2[9] that will  have all the elements of ARR as if they are stored in row major form.
1 2 3
4 5 6
7 8 9then should contain 123456789
Q16.   Arrange the following array of integers in ascending order using bubble sort technique. Array elements are:
26, 21, 20, 23, 29, 17, 14
Q17.   Write a function check( ) to check if the passed array of 10 integers is sorted or not. The  function should return 1 if arranged in ascending order, -1 if arranged in descending order, 0 if it is not sorted.
Q18.   Suppose a company keeps single dimensional array YEAR[100] such that YEAR[K] contains the number of employees appointed in the year K. Write a C++ program for each of the following task:
a.       To print each of the years in which no employee was appointed.
b.      To find the number of years in which no employee was appointed.
Q19.   Write a user defined function in C++ to find the sum of all positive numbers of a 2D array ARC [7][7]
containing integers.
Q20.   Write an interactive menu driven program to create two 3x3 matrices and carry out the  following operations.
Sum of two matrices, difference of two matrices, Product of two matrices
a.       Display the input and output matrices in proper matrix form. While creating the matrix keep in mind that each input must not exceed 20.
Q21.   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
Q22.   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.   Explain: if the two dimensional arrays contains
1
2
4
3
5
6
4
3
2
2
1
5
     




Then the output should appear as:
Product of Column 1=24, Product of Column 2=30, Product of Column 3=240
Q23.   Write a function in C++ which accepts an integer array and its size as arguments / parameters   and arrange all 
the odd numbers in the first row and even numbers in the second row of a two  dimensional array as follows.  
The unused cells of 2D dimensional array must be filled with 0.
If the array is     1, 2, 3, 4, 5, 6  
The resultant 2-D array is given below  
1   3 5 0             0             0            
0   0 0 6             4             2
Q24.    Write a function in C++ which accepts a 2-D array of integers and its size as arguments and prints no of even
numbers and odd numbers in each column.                                                      


If the array is          
11         12           31           41
52         62           71           82
9           10           11           12

The output will be
Column 1:         Even numbers : 1             Odd numbers : 2
Column 2:         Even numbers : 3             Odd numbers : 0
Column 3:         Even numbers : 0             Odd numbers : 3
Column 4:         Even numbers : 2             Odd numbers : 1
For Solution  call and mail: Mo.No.:9810301034,  g9_sharma@yahoo.com
Q25.    Write a user-defined function in C++ to display the sum of column elements of a two-dimensional arrray  R[7][7] containing integers.
Q26.    Write a user-defined function in C++ to display the multiplication of row element of two-dimensional 
array A[4][6] containing integer.
Q27.   Suppose A, B, C are arrays of integers of size M, N, and M + N respectively. The numbers in array A  appear in
ascending order while the numbers in array B appear in descending order. Write a user defined function in C++ to produce third array C by merging arrays A and B in ascending order. Use  A, B and C as arguments in the
function.
Q28.   Write a user-defined function in C++ to find and display the sum of both the diagonal elements of a two-dimensional array MATRIX [6] [6] containing integers.
Q29.   Considering the following key set: 42, 29, 74, 11, 65, 58. Use bubble sort to sort the data in ascending order and
indicate the sequences of steps required.
Q30.   Define a function SwapArray( int [ ], int), that would accept a one dimensional integer array  NUMBERS and
its size N. The function should rearrange the array in such a way that the values of alternate locations of theFor Solution  call and mail: Mo.No.:9810301034,  g9_sharma@yahoo.com
array are exchanged(Assume the size of the array to be even)Example:
If the array initially contains   {2, 5, 9, 14, 17, 8, 19, 16},
then after rearrangement the array should contain   {5, 2, 14, 9, 8, 17, 16, 19}
Q31.    Write a function in C++ which accepts an integer array and its size as  arguments/parameters and  exchanges the
values of first half side elements with the second half side elements of the array. Example:If an array of eight
elements has initial content as  2,4,1,6,7,9,23,10   The function should rearrange the array as    7,9,23,10,2,4,1,6
Q32.    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.
Q33.   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; };
Q34.   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
2 1 4 9
1 3 7 7
5 8 6 3
7 2 1 2
After swapping of the content of 1st column and last column, it should be:
9 1 4 2
7 3 7 1
3 8 6 5
2 2 1 7


Q35.   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 Date of the array  -   21,12 ,35 ,42 ,18 
Content of the array after calling CHANGE( ) function   3 ,36 ,5 ,6 ,54
Q36.   Write a 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 contain   30, 10, 60, 50, 90, 80.
Q37.   Write a function in C++ to combine the contents of two equi-sized arrays A and B by computing their
corresponding elements with the formula  A[i] * 3*B[i] where value i varies from 0 to N-1 and transfer
the resultant content in the third same sized array.
Q38.   Write a C++ program to find the sum and average of one dimensional integer array.
Q39.   Write a C++ program to swap first and last element of an integer 1-d array.
Q40.   Write a C++ program to reverse the element of an integer 1-D array.
Q41.   Write a C++ program to find the largest and smallest element of an array.
Q42.   Write a menu driven C++ program with following option
a. Accept elements of an array
b. Display elements of an array
c. Sort the array using insertion sort method
d. Sort the array using selection sort method
e. Sort the array using bubble sort method
Q43.       Write C++ functions for all options. The functions should have two parameters name of the array and number of elements in the array.
Q44.       P is one-dimensional array of integers. Write a C++ function to efficiently search for a data VAL from P. If VAL is present in the array then the function should return value 1 and 0 otherwise.
Q45.       Suppose a one-dimensional array AR containing integers is arranged in ascending order. Write a user-defined function in C++ to search for an integer from AR with the help of Binary search method, returning an integer 0 to show absence of the number and integer 1 to show presence of the number in the array. Function should have three parameters : (i) array AR (ii) the number to be searched and (iii) the number of elements N in the array.
Q46.       Suppose A, B, C are arrays of integers of size M, N, and M + N respectively. The numbers in array A appear in ascending order while the numbers in array B appear in descending order. Write a user defined function in C++ to produce third array C by merging arrays A and B in ascending order. Use A, B and C as arguments in the function.
Q47.       Suppose X. Y, Z are arrays of integers of size M, N, and M + N respectively. The numbers in array X and Y appear in descending order. Write a user-defined function in C++ to produce third array Z by merging arrays X and Y in descending order.
Q48.       Given two arrays of integers A and B of sizes M and N respectively. Write a function named MIX () with four arguments, which will produce a third array named C. such that the following sequence is followed.
All even numbers of A from left to right are copied into C from left to right.
All odd numbers of A from left to right are copied into C from right to left.
All even numbers of B from left to right are copied into C from left to right.
All old numbers of B from left to right are copied into C from right to left.
A, B and C are passed as arguments to MIX (). e.g., A is {3, 2, 1, 7, 6, 3} and B is {9, 3, 5, 6, 2, 8, 10} the resultant array C is {2, 6, 6, 2, 8, 10, 5, 3, 9, 3, 7, 1, 3}
Q49.       Write a menu driven C++ program to do following operation on two dimensional array A of size m x n. You should use user-defined functions which accept 2-D array A, and its size m and n as arguments. The options are:
To input elements into matrix of size m x n
To display elements of matrix of size m x n
Sum of all elements of matrix of size m x n
To display row-wise sum of matrix of size m x n
To display column-wise sum of matrix of size m x n
To create transpose of matrix B of size n x mFor Solution  call and mail: Mo.No.:9810301034,  g9_sharma@yahoo.com
Q50.       Write user defined functions for square matrix to calculate
Left diagonal sum, Right diagonal sum
Q51.       Write a user-defined function in C++ to display the multiplication of row element of two-dimensional array A[4][6] containing integer.
Q52.       Write a user defined function named Upper-half() which takes a two dimensional array A, with size N rows and N columns as argument and prints the upper half of the array.
e.g.,
2 3 1 5 0                                                             2 3 1 5 0
7 1 5 3 1                                                             1 5 3 1
2 5 7 8 1     The output will be                     1 7 8
0 1 5 0 1                                              0 1
3 4 9 1 5                                                              5
Q53.       Write a function in C++ which accepts a 2D array of integers and its size as arguments and 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. 3x3, 5x5, 7x7 etc...]
Example, if the array contents is
3  5  4
7  6  9
2  1  8
Output through the function should be :
Middle Row : 7 6 9
Middle column : 5 6 1
Q54.       Write a program to add two array A and B of size m x n.
Q55.       Write a program to multiply array A and B of order NxL and LxMFor Solution  call and mail: Mo.No.:9810301034,  g9_sharma@yahoo.com
for Note's and Assignment call Message : 9810301034 and email on g9_sharma@yahoo.com

Comments

Popular posts from this blog

C# Connectivity with MySql Server..