PRACTICE EXECISES a)#include<iostream.h> #include<ctype.h> void main( ) { char Text[ ] = “Comp@uter!”‖; for(int I=0; Text[I]!=‘\0‘;I++) { if(!isalpha(Text[I])) Text[I]=‘*‘; else if(isupper(Text[I])) Text[I]=Text[I]+1; else Text[I] = Text[I+1]; } cout<<Text; } b) Give output of following code. #include<iostream.h> int m=5; void check(); void main( ) { int m=20; { int m=10*::m; cout<<"m="<<m<<"::m="<<::m<<endl; } check(); cout<<"m="<<m<<"::m="<<::m<<endl; check(); cout<<"::m="<<::m<<"m="<<m<<endl; } void check() { ++m;} d) Give output of following code fragment: char msg[] = “a ProFile”; for (int i = 0; i < strlen (msg); i++) if (islower(msg[i])) msg[i] = toupper (msg[i]); else if (isupper(msg[i])) if( i % 2 != 0) msg[i] = tolower (msg[i-1]); else msg[i--]; cout << msg << endl; e)Give output int Execute( int M) { if (M % 3 = 0) return M * 3; else return M + 10; } void output( int B = 2) { for (int T = 0; T < B; T++) cout << Execute(T) << “*”; cout << endl; } void main() { output (4); output ( ); output (3); } f) Write the output of the following program : #include<iostream.h> int calc(int u) { if(u%2==0) return u+10; else return u*2; } void pattern(char M, int B=2) { for(int cnt=0;cnt<b;cnt++) cout<<calc(cnt)<<m; cout<<endl; } void main() { pattern(‘*’); pattern(‘#’,4); pattern(‘@’,3); } g) Find the output of the following program: #include<iostream.h> #include<conio.h> void ChangeContent(int Arr[], int Count) { for(int C=1 ; C<Count ; C++) { Arr[C-1]+=Arr[C] ; }} void main() { clrscr( ); int A[ ]={3, 4 , 5}, B[ ]={10,20,30,40}, C[ ]={900, 1200}, L ; ChangeContent(A,3); ChangeContent(B,4); ChangeContent(C,2); for(L=0 ; L<3 ; L++) {cout<<A[L]<<"#"; }cout<<endl; for(L=0 ; L<4 ; L++) {cout<<B[L]<<"#" ; }cout<<endl; for(L=0 ; L<2 ; L++) { cout<<C[L]<<"#" ;}getch();} h) Write the output of the following program: #include<iostream.h> #include<string.h> #include<ctype.h> void convert (char str[], int len) { for (int count =0; count <len; count++) { if ( isupper(str[count])) str[count]=tolower(str[count]); else if ( islower(str[count])) str[count]=toupper(str[count]); else if ( isdigit(str[count])) str[count]=str[count]+2; else str[count]= ‘#’; }} void main() { char text[]= “AISSCE 2008@”; int size =strlen(text); convert (text,size); cout<<text<<endl; for (int c =0, r=size-1; c<=size/2;c++, r--) { char temp= text[c]; text [c]= text[r]; text[r]= temp; }cout<< text << endl; } i)Give the output of the following program. #include < iostream.h > #include <conio.h > int a = 10; int main( ) { void demo ( int &, int , int []); clrscr( ); int a = 20; demo ( ::a,a,&b); cout << ::a << “\t” << a << “\t” << b; } void demo ( int &x, int y , int z ) { a += x; y *= a; z = a+y; cout << x << “\t” << y << “\t” << z << endl; } j) Write the output of the follwoing program segment char NAME[]="ComPUteR"; for(int x=0;x<strlen(NAME);x++) if(islower(NAME[x])) NAME[x]=toupper(NAME[x]); else if(isupper(NAME[x])) if(x%2==0) NAME[x]=tolower(NAME[x])); else NAME[X]=NAME[x-1]; puts(NAME); k) In the following program, find the correct possible output(s)from the options: #include<stdlib.h> #include<iostream.h> void main( ) { randomize( ); char Area[ ][10]={“NORTH”‖,”SOUTH”‖,”EAST”‖,”WEST”}; int ToGo; for(int I=0; I<3;I++) { ToGo=random(2) + 1; cout<<Area[ToGo]<<‖:‖; } } Outputs: (i) SOUTH : EAST : SOUTH : (ii) NORTH : SOUTH : EAST : (iii) SOUTH : EAST : WEST : (iv) SOUTH : EAST : EAST : L)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. m) 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 123 123 678 78 234 4 n) 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; 123 1 567 56 912 912 o)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., 456 789 321 output through the function should be middle row 7 8 9 middle col. 5 8 2 p)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. 123 456 789 then should contain 123456789 q)Write an interactive menu driven program to create two 3x3 matrices and carry out the following operations. a. Sum of two matrices b. difference of two matrices c. Product of two matrices Display the input and output matrices in proper matrix form. While creating the matrix keep in mind that each input must not exceed 20. 1 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. 2 Write a function in C++ which accepts an integer array and its size as argument 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 as 2,4,1,6,7,9,23,10 The function should rearrange the array as 7,9,23,10,2,4,1,6. 3Write a function in c++ to find and display the sum of each row and each column of 2 dimensional array. Use the array and its size as parameters with int as the data type of the array. 4 Write a function in C++, which accepts an integer array and its size as parameters and rearrange the array in reverse. Example if an array of five members initially contains the elements as 6,7,8,13,9,19 Then the function should rearrange the array as 19,9,13,8,7,6 5 Write a function in C++, which accept an integer array and its size as arguments and swap the elements of every even location with its following odd location. Example : if an array of nine elements initially contains the elements as 2,4,1,6,5,7,9,23,10 Then the function should rearrange the array as 4,2,6,1,7,5,23,9,10 6 Write a function in C++ which accepts an integer array and its size as arguments and replaces elements having odd values with thrice and elements having even values with twice its value. Example : If an array of five elements initially contains the elements 3,4,5,16,9 Then the function should rearrange the content of the array as 9,8,15,32,27 7 Write 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; }; 8 Write a c++ function to shift all the negative numbers to left and positive number in the right side. 9 Define a function SWPCOL() in C++ to swap ( interchange) the first column elements with the last column elements, for a two dimensional array passed as the argument of the function. Example : if the two dimensional array contains 2149 1377 5863 7212 After swapping of the content of 1st and last column, it should be 9142 7371 3865 2217 10 Define a function SWPROW() in C++ to swap ( interchange) the first row elements with the last row elements, for a two dimensional array passed as the argument of the function. Example : if the two dimensional array contains 2149 1377 5863 7212 After swapping of the content of the array will be 80 7212 5863 1377 2149 11 Write a function in C++ to print the product of each column of a 2D integer array passed as the argument of the function Example : if the two dimensional array contains 2149 1377 5863 7212 Then the output should appears as Product of Column1 = 70 Product Column2 = 48 Product of column3= 168 Product of Column4=378 12 Write a function in C++ to print the product of each row of a 2D integer array passed as the argument of the function Example : if the two dimensional array contains 2149 1377 5863 7212 Then the output should appears as Product of Row1 = 72 Product Row2 = 147 Product of Row3= 720 Product of Row4=28 13. Write a function which accept 2D array of integers and its size as arguments and displays the sum of elements which lie on diagonals. [Assuming the 2D array to be a square matrix with odd dimension ie 3 x 3 , 4 x 4 etc ] Example of the array content is 543 678 129 Output through the function should be Diagonal One Sum : 21 Diagonal Two: 11 14. 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 ie 3 x 3 , 5 x 5, 7 x 7 etc ] Example of the array content is 543 678 129 Output through the function should be Middle row: 6 7 9 Middle Column 4 7 2 15. Write a function in C++ which accepts an integer array and its size as arguments 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 if the array is 1,2,3 The resultant 2D array is The resultant 2D array is 123456 123 123450 120 123400 100 123000 120000 100000 16. Write a function in C++ which accepts an integer array and its size as arguments 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 if the array is 1,2,3 The resultant 2D array is The resultant 2D array is 123456 123 012345 012 001234 001 000123 000012 000001 17. Write a function in C++ which accepts an integer array and its size as arguments 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 if the array is 1,2,3 The resultant 2D array is The resultant 2D array is 100000 100 120000 120 123000 123 123400 123450 123456 18. 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 19. Write a user defined function lowerhalf() which takes a 2D array, with size n rows and n cols as argument and prints the lower half of the matrix 20 Write the function to find the largest and second largest number from a two dimensional array. The function should accept the array and its size as argument. 21 Write a function in C++ to merge the contents of two sorted arrays A & B into third array C. Assuming array A is sorted in ascending order, B is sorted in descending order, the resultant array is required to be in increasing order. 22. Define a function to accept any 20 names and return the number of vowels of the largest name. 23. Define a function to accept any 30 sentences and exchange the longest sentence with the smallest sentence. 24. Define a function to accept any 50 words and arrange each word characters in decreasing order.