General Instructions :
(i) SECTION A refers to programming language C++.
(ii) SECTION B refers to programming language Python.
(iii) SECTION C is compulsory for all.
(iv) Answer either SECTION A or SECTION B.
(v) It is compulsory to mention on the page 1 in the answer-book whether you are attempting SECTION
A or SECTION B.
(vi) All questions are compulsory within each section.
(vii) Questions 2(b), 2(d), 3 and 4 have internal choices
Questions
(a) Write the type of C++ Operators (Arithmetic, Logical, and Relational Operators) from
the following: (2)
(i)!
(ii) !=
(iii) &&
(iv) %
Ans.
(i)Logical (ii) Relational (iii)Logical (iv) Arithmetic
(b) Observe the following program very carefully and write the name of those header file(s), which are essentially needed to compile and execute the following program successfully: (1) void main() { char text[20], newText[20]; gets(text); strcpy(newText,text); for(int i=0;i<strlen(text);i++) if(text*i+ = =’A’) text[i] = text[i]+2; puts(text);
}
Answer: stdio.h string.h
(c) Rewrite the following C++ code after removing any/all Syntactical Error(s) with each correction underlined. (2) Note: Assume all required header files are already being included in the program. #define float PI 3.14 void main( ) { float R=4.5,H=1.5; A=2*PI*R*H + 2*PIpow(R,2); cout<<‘Area=’<<A<<endl; } #define PI 3.14 //Error 1 void main( ) { float R=4.5,H=1.5; A=2*PI*R*H + 2*PI*pow(R,2); cout<<‘Area=’<<A<<endl;
}
OR
(d) Find and write the output of the following C++ program code: (2) Note: Assume all required header files are already being included in the program. void main( ) { int Ar[ ] = { 6 , 3 , 8 , 10 , 4 , 6 , 7} ; int *Ptr = Ar , I ; cout<<++*Ptr++ << '@' ; I = Ar[3] -Ar[2] ; cout<<++*(Ptr+I)<<'@'<<"\n" ; cout<<++I + *Ptr++ << '@' ; cout<<*Ptr++ <<'@'<< '\n' ; for( ; I >=0 ; I -=2) cout<<Ar[I] << '@' ;
} Answer:
7@11@
6@8@
11@3@
(e) Find and write the output of the following C++ program code: (3) Typedef char STRING[80]; void MIXNOW(STRING S) { Int Size=strlen(S); for(intI=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+=’@’; }</size;i+=2)>
<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+="">void main() { STRING Word=”CBSEEXAM2019”; MIXNOW(Word); cout<<Word<<endl; } Ans. BCE@XEMA0291 (f) Observe the following program and find out, which output(s) out of (i) to (iv) will be expected from the program? What will be the minimum and the maximum value assigned to the variable Alter? (2) Note: Assume all required header files are already being included in the program. void main( ) { randomize( ); int Ar[]={10,7}, N; int Alte r=random(2) + 10 ; for (int C=0;C<2;C++) { N=random(2) ; cout<<Ar*N+ +Alter<<”#”; } } (i) 21#20# (ii) 20#18# </size;i+=2)>
(iii) 20#17# (iv) 21#17#
Ans:
The output expected from the program is (iii) 20#17# Minimum Value of Alter = 10 Maximum Value of Alter = 11