STD: XII Assignment For STD XII (Submission Date: 03-06-2019)
STD: XII Assignment For STD XII (Submission Date: 03-06-2019)
3. void main()
{ int n1=15,n2=10;
for(int i=1;i<=2;i++)
{ cout<<++n1<<’$’<<n2+2<<endl;
cout<<-- n2<<’$’<<n1++<<endl;} }
4.void main()
{ char string[]=”I BOW TO MY MOTHERLAND”;
for(int i=0; i<strlen(string)-1;i+=2)
{ if(string[i]>75)
string[i]+=32;
else if(i%2==0)
string[i]=string[i+1];
else
string[i]=string[i]+1;
} cout<<string;}
5. void main()
{ 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);}
6. struct package
{int l,b,h;};
void occupies(package m)
{ cout<<m.l<<”x”<<m.b<<”x”<<m.h<<endl;}
void main()
{ package p1={180,120,80},p2,p3;
++p1.l;
occupies(p1);
p3=p1;
++p3.b;
p3.b++;
occupies(p3);
p2=p3;
p2.b+=50;
p2.h--;
occupies(p2);}
8. int g=20;
void fun(int &x,int y)
{x=x-y;
y=x*10;
cout<<x<<’ ‘<<y<<’ ‘<<endl;}
void main()
{ int g=7;
fun(g,::g);
cout<<g<<’ ‘<<::g<<endl;
fun(::g,g);
cout<<g<<’ ‘<<::g<<endl;}
9. typedef char STRING[80];
void MIXNOW(STRING S)
{ int Size=strlen(S);
for(int I=0;I<Size;I+=2)
{ char WS=S[I];
S[I]=S[I+1];
S[I+1]=WS; }
for (I=1;I<Size;I+=2)
{ if (S[I]>=’M’ && S[I]<=’U’)
S[I]=’@’; }
void main()
{ STRING Word=”CBSEEXAM2019”;
MIXNOW(Word);
cout<<Word<<endl; }
10.#define Big(A,B)(A>B)A+1:B+2
void main()
{char W[]=”Exam”;
int L=strlen(W);
for(int i=0;i<L-1;i++)
w[I]=Big(W[i],W[i+1]);
cout<<w<<endl;}
11. Write a user defined function in C++ to create a 2-d array from the two one-dimensional arrays passed
as parameters as given below in the example.
int a[]={3,5,2}, b[]={-3,2,4};
int c[][3]={{-9,6,12},{-15,10,20},{-6,4,8}};
12.Write a user defined function in C++ to display those elements of a two-dimensional array t[4][4] which
are divisible by 100. Assume the content of the array is already present and the function prototype is as
follows:
void show hundred( int t[4][4]);
13. Write a function in C++ to find the sum of the diagonal elements from a 2-d array of type float. Use the
array and its size as parameters with float as its return type.
14.Define a function swaparray(int[],int), that would accept a one dimensional array Numbers and its size
N. The function should rearrange the array in such a way that the values of alternate locations of the 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
The resultant array will be 5,2,14,9,8,17,16,19
15..Write a function in C++ which accepts an integer array and size as arguments and replaces elements
having even values with its half and elements having odd values with twice its value.
Ex: if the array is 3,4,5,16,9
then the resultant should be 6,2,10,8,18
16.Write a function in C++ which accepts an integer array and size as arguments and exchanges the values of
first half side elements with the second half side elements of the array.
Ex: if the array is 8, 10,1,3,17,90,13,60
resultant array should be 17,90,13,60,8,10,1,3
17. Write a user defined function in C++ to display those elements of a two-dimensional array t[4][4] which
are divisible either by 3 or 5. Assume the content of the array is already present and the function prototype is
as follows:
void show hundred( int t[4][4]);
18. Write a user defined function in C++ to display the sum of row elements and column elements of a two-
dimensional array of integer type.
19.Write a user defined function in C++ insert() that inserts the first n elements from array A into array B at
the beginning.
Ex: int a[]={3,2,7,5,8,9,1,0, 4}, b[15]={1,6,3}.If n=4 after insertion array B will be
{3,2,7,5,1,6,3}
20. Write a user defined function in C++ to take an array of names as an argument, the list is sorted in
alphabetical. The function should locate a name “Computer” by applying binary search and also delete the
name “Computer” from the array if the search is successful otherwise display an error message.
21.Write a user defined function in C++ named lowerhalf() which takes a 2-d array and display the lower
half of the array.
22.Write a user defined function in C++ to accept 2-d array and its size as an argument and exchange the
values in both the diagonals as follows:
1234 Result is: 8 2 3 7
2385 2 1 2 5
6789 6 4 1 9
2781 8 7 8 3
23.Write a user defined function in C++ which accepts an integer array and its size, and assign the elements
into a 2-d array of integers in the following format:
if the array is 1,2,3,4,5,6
the resultant array should be: 1 0 0 0 0 0
1 2 0 0 0 0
1 2 3 0 0 0
1 2 3 4 0 0
1 2 3 4 5 0
1 2 3 4 5 6
24. Write a user defined function in C++ to replace the repeating elements in an array with zero.
Ex; 10,20,30,10,40,20,30
The output will be 10,20,30,0,40,0,0
25. Assume an array E containing elements of structure Student is required to be arranged in descending
order of the marks. Write a C++ function to arrange the same with the help of bubble sort. The array and its
size is required to be passed as parameters to the function. Definition of structure Student is as follows :
struct student { int rollno;
char name[25];
float marks; };
26.Write a function Swap2Change (int P[],int N) in C++ to modify the content of the 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 the array P is 91,50,54,22,30,54
The content of array P should become 91,54,50,22,54,30.
27. Consider a 1D array List containing N names is sorted in alphabetical order. Write a function in C++ to
locate a name KEYNAME by applying Binary Search. Delete the name KEYNAME from the array if
successful otherwise display an error message on the screen.
28. Write a Get1from2() 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 array First[] and odd places(1,3,5---)of
array ALL[] should get from array Second[].
29. Define a function swaparray(int[],int), that would accept a one dimensional array Numbers and its size N.
The function should rearrange the array in such a way that the values of alternate locations of the 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
The resultant array will be 5,2,14,9,8,17,16,19
30. Write a user-defined function AddEnd2(int A[][4],int N,int M) in C++ to find and display the
sum of all the values, which are ending with 2 (i.e., units place is 2).
For example i f the content of array is :
22 16 12
19 5 2
The output should be 36
******************