Question 31:
Find syntax error(s), if any, in the following program: (Assuming all desired header file(s) are already included)
typedef String [80] char;
void main()
{
String S;
for (L=0; L<26; C++)
S[L] = L+65;
S[L]="\0":
cout<<S<<endline :
} Delhi 2013C
Answer:
tvpedef char Strlnq[80] : void main ( ) { String S; for (int L= 0: L<26; L++) S[L]=L+65; S[L]="\0" ; cout<<S<<end l ; }
Question 32:
Based on the following C++ code, find out the expected correct output(s) from the options (i) to (iv). Also, find out the minimum and the maximum value that can be assigned to the variable Guess used in the code at the time when value of Turn is 3.
void main( )
{
char Result[][10]={"GOLD",
"SILVER”,"BRONZE"}:
int Getit=9,Guess :
for(int Turn=l;Turn<4;Turn++)
{
Guess=random(Turn); cout<<Getit-Guess<<Result [Guess]<<"*" ;
}
}
(i) 9GOLD*9GOLD*8SILVER*
(ii) 9GOLD*7BRONZE*8GOLD*
(iii) 9GOLD*8SILVER*9GOLD*
(iv) 9GOLD*8SILVER*8GOLD*
All India 2013
Answer:
Correct output is (i) 9G0LD*9G0LD*8SILVER*
Maximum value of Guess is 2
Minimum value of Guess is 0.
Question 33:
Based on the following C++ code, find out the expected correct output(s) from the options (i) to (iv). Also, find out the minimum and the maximum value that can be assigned to the variable Trick used in the code at the time when value of Count is 3
void main() { char StatusC][10]={"EXCEL”, "GOOD"."OK"i; int Turn=10,Trick; for(int Count=1;Count<4;Count++) { Trick=random(Count); cout<<Turn-Trick<<Status [T ri ck]«"#" ; } }
(i) 10EXCEL# 10EXCEL#80K#
(ii) 10EXCEL#80K#9GOOD#
(iii) 10EXCEL#9GOOD# 10EXCEL#
(iv) 10EXCEL# 10GOQD#80K# Delhi 2013
Answer:
Correct output is (iii) 10EXCEL#9GOOD#10EXCEL#
Minimum value of Trick is 0
Maximum value of Trick is 2
Question 34:
Observe the following program and find out, which output(s) out of (i) to (iv) will not be expected from the program? What will be the minimum and the maximum value assigned to the variable Turn?
#i nclude<iostream.h> #include<stdlib.h> void main() ( randomize(); int Game[]={10.16},P; int Turn=random(2)+5; for(int T=0; T<2; T++) { P=random(2) ; cout<<Game[P]+Turn<<"#" ; } }
(i) 15#22# (ii) 22#16#
(iii) 16#21# (iv) 2I#22# Delhi 2012
Answer:
(i), (iii) and (iv) can never be the output.
Minimum value of Turn =5
Maximum value of Turn =6
Question 35:
Observe the following program and find out which output(s) out of (i) to (iv) will not be expected from the program? What will be the minimum and the maximum value assigned to the variable Chance?
#i nclude<iostream.h> #include<stdlib.h> void main() { randomze( ) ; int Arr[]={9,6},N; int Chance=random(2)+10; for(int CO;C<2;C++) { N=random(2); cout<<Arr[N]+Chance<<"#" ; } }
(i) 9#6#
(ii) 19#17#
(iii) 19#16#
(iv) 20# 16# All India 2012
Answer:
(i), (ii) and (iv) will not be expected from the program
Maximum value of Chance =11
Minimum value of Chance =10
Question 36:
Rewrite the following program after removing the syntactical errors (if any). Underline each correction.
#include[iostream.h]
typedef char Text (80);
void main( )
{
Text T="Indian";
int Count=strlen(T) ;
cout<<T<< ' has ' <<Count<< ' characters '<<endl;
} Delhi 2011
Answer:
# include<iostream.h> #include<strinq.h> typedef char Text[80]: void main() { Text T="Indian"; int Count=strlen(T) ; cout<<T<<"has"<<Count <<"characters"<<end1 ; }
Question 37:
Rewrite the following program after removing the syntactical errors (if any). Underline each correction.
#include<iostream.h>
typedef char[80] string;
void main()
{
string S="Peace";
int L=strlen (S) ;
cout<<3<< 'has'<<L<<'characters'<<endl;
} Delhi 2011
Answer:
#include<iostream.h> #include<string.h> tvpedef char strinq[80]: void main() { string S="Peace"; int L=strlen(S); cout<<S<< " has "<<L<<characters" <<endl; }
Question 38:
Find the output of the following program;
#include<iostream.h>
void SwitchOver(int AC], int N.intSplit)
{
for ( int K=0 ; K<N ; K++
if(K<Spl it)
A[K]+=K;
else
A[K]*=K;
}
void Display(int A[],int N)
{
for (int KO ; K<N ; K++)
(K%2=0)?cout<<A[K]<<"%" :cout <<A[K]<<endl ;
}
void main()
{
int H[]={30.40.50,20,10,5);
Switch0ver(H,6,3);
Display (H,6);
} All India 2011
Answer:
Output
30%41 52%60 40%25
Question 39:
Find the output of the following program
#includeCiostream.h>
#include<ctype.h>
void changeIt(char Text[],char C)
{
for(int K=0;Text[K]!="\0";K++)
{
if(Text[K]>="F"&&Text[K]<="L")
Text[K]=tolower(Text[K]);
else
i f (Text[K]—"E"| |Text[K]=="e" ) Text[KJO;
else
if(K%2= =0)
Text[K]=toupper(Text[K]) ;
else
Text[K]=Text[K-1];
}
}
void main()
{
char 0ldText[]="p0wERALone";
changeIt(0ldText,); cout<<"New Text: "<<01dText<<endl ;
} Delhi 2010
Answer:
Output
New Text :PPW%RRllN%
Question 40:
Find the output of the following program:
#include<iostream. h>
#include<ctype.h>
void MyCodetchar Msg[],char CH)
{
for(int cnt=0; Msg[cnt]!="\0"; cnt++)
{
if(Msg[cnt]>=”B"&& Msg [cnt]<="G")
Msg[cnt]=tolower(Msg[cnt]);
else
if(Msq[cnt]=="A"||Msg [cnt]=="a" )
Msg[cnt]=CH;
else if (cnt % 2==0)
Msg[cnt]=toupper(Msg[cnt]) ;
else
Msg[cnt]=Msg[cnt-1] ;
}
}
void main()
}
char MyText[]="ApEACeDriVE" ;
MyCodetMyText, "@");
cout<<"NEW TEXT: "<<MyText<<endl;
) All India 2010
Answer:
Output
NEW TEXT:@@e@ccddIIe