Topic Wise Solved Problems Question – Computer Sir Ki Class

CPP: Topicwise Exam Question: functions-user-defined
01D-2017 2

Find and write the output of the following C++ program code:
Note: Assume all required header files are already included in the program.

```typedef char STRING[80];
void MIXITNOW(STRING S)
{
int Size=strlen(S);
for (int I=0;I<Size-1;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="CRACKAJACK";
MIXITNOW(Word);
cout<<Word<<endl;
}```

CBSE12D-2016

Sum of even and odd values in an array 2

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 53

Then 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)

CBSE12A-2018

Random Number Based Guessing of output of a 2D Array printing 2

Look at the following C++ code and find the possible output(s) from the
options (i) to (iv) following it. Also, write the maximum values that can
be assigned to each of the variables N and M.

Note:

• Assume all the required header files are already being included in
the code.
• The function random(n) generates an integer between 0 and n-1
```void main()
{
randomize();
int N=random(3),M=random(4);
int DOCK[3][3] = {{1,2,3},{2,3,4},{3,4,5}};
for(int R=0; R<N; R++)
{
for(int C=0; C<M; C++)
cout<<DOCK[R][C]<<" ";
cout<<endl;
}
}```

(i)
1 2 3
2 3 4
3 4 5

(ii)
1 2 3
2 3 4

(iii)
1 2
2 3

(iv)
1 2
2 3
3 4

CBSE12A-2017

01D 2

Find and write the output of the following C++ program code:
Note: Assume all required header files are already included in the program.

```typedef char TEXT[80];
void JumbleUp(TEXT T)
{
int L=strlen(T);
for (int C=0;C<L1;C+=2)
{
char CT=T[C];
T[C]=T[C+1]
T[C+1]=CT;
}
for (C=1;C<L;C+=2)
if (T[C]>='M' && T[C]<='U')
T[C]=’@’;
}
void main()
{
TEXT Str="HARMONIOUS";
JumbleUp(Str);
cout<<Str<<endl;
}```
CBSE12A-2016

Random picking from string array 2

Look at the following C++ code and find the possible output(s) from the options (i) to (iv) following it. Also, write the maximum and the minimum values that can be assigned to the variable PICKER.

Note:
– Assume all the required header files are already being included in the code.
– The function random(n) generates an integer between 0 and n-1

```void main()
{
randomize().
int PICKER.
PICKER=1+random(3).
char COLOR[][5]={"BLUE","PINK","GREEN","RED"}.
for(int I=0.I<=PICKER. I++)
{
for(int J=0. J<=I.J++)
cout<<COLOR[J].
cout<<endl.
}
}
```
(i) (ii) (iii) (iv)
PINK BLUE GREEN BLUE
PINKGREEN BLUEPINK GREENRED BLUEPINK
PINKGREENRED BLUEPINKGREEN BLUEPINKGREEN
BLUEPINKGREENRED
CBSE12A-2016