Previous Years Examination Questions (Topic 3)
(1 Mark Questions)
Question 1:
Anil typed the following C++ code and during compilation he found three errors as follows:
(i) Function strlen should have prototype
(ii) Undefined symbol cout
(iii) Undefined symbol endl All India 2017
On asking, his teacher told him to include necessary header files in the code. Write the names of the header files, which Anil needs to include, for successful compilation and execution of the following code:
void main() { char Txt [ ] = "Weicome"; for (int C=0; (Xstrlen(Txt);C++) Txt [C] = Txt[C]+1: cout<<Txt<<endl: }
Answer:
For strlen → <string.h>
For cout, endl → <iostream.h>
Question 2:
Observe the following program very carefully and write the names of those header file(s), which are essentially needed to compile and execute the following program successfully. All India 2015
typedef char STRING[80] ; void main( ) ( STRING Txt [] = "We love Peace"; int Count = 0: while(Txt [Count]! = "\0") if(isalpha (Txt[Count]) ) Txt [Count++] = "@"; else Txt [Count++] = "#"; puts (Txt); }
Answer:
<ctype.h> → isalpha <stdio.h> → puts
Question 3:
Observe the following program very carefully and write the names of those
header file(s), which are essentially needed to
compile and execute the following program successfully. Delhi 2015
typedef char TEXT[80]; void main() { TEXT Str [ ]="Peace is supreme"; int Index = 0; while(Str[Index]1= "\0") if(isupper(Str [Index])) Str[Index++] = "#" ; else Str[Index++]="*" ; puts(Str); }
Answer:
<ctype.h>→isupper <stdio.h>→ puts
Question 4:
Name the header files that shall be needed for successful compilation of the following C++ code All Indio 2014 C
void main() { char str[20], str[20]; gets(str) ; strcpy(strl,str): strrev(str); puts(str) ; puts(strl); }
Answer:
<stdio.h> → puts, gets <std1ib> → strcpy(),strrev()
Question 5:
Observe the following C++ code and write the name(s) of the header file(s), which will be essentially required to run it in a C++ compiler.
void main()
{
char Text[20],C;
cin>>Text;
C=tolower(Text[0]) ;
cout<<C<<"is the first char of"
<<Text<<endl ;
} Delhi 2014
Answer:
<iostream.h>cout, cin <ctype.h>tolower( )
Question 6:
Observe the following C++ code and write the name(s) of the header file(s), which will be essentially required to run it in a C++ compiler.
void main()
{
char CH, STRC20]:
cin>>STR;
CH=toupper(STRCO]);
cout<<STR<<"starts with"<<CH<<endl ;
} All India 2014
Answer:
<iostream.h>cin, cout <ctype.h> toupper()
Question 7:
Which C++ header file(s) are essentially required to be included to run/execute the following C++ source code?
NOTE Do not include any header file, which is/are not required,
void main( ) { char STRING [ ] ="SomeThing" ; cout<<”Bal ance Characters : "<<160- strlen(STRING)<<endl ; } Delhi 2012
Answer:
<iostream.h>→Cout <string.h>→ strlen()
Question 8:
Which C++ header file(s) are essentially required to-be included to run/execute the following C++ source code?
NOTE Do not include any header file, which is/are not required
void main()
{
char STRING[]="SomeThing" ;
cout<<"Remaining SMS Chars :"<<160-
strlen(STRING)<<endl ;
} All India 2012
Answer:
<iostream.h> → cout <string.h> → strlen()
Question 9:
Write the names of the header files, which is/are essentially required to run/execute the following C++ code.
void main()
{
char C, string[]="Excellence Overload";
forfint 1=0 ; string[I] !='\0';I++)
if(string[I]== " ”)
cout<<endl;
else
{
C=toupper(string[I]) ;
cout<<C;
} Delhi 2011
Answer:
<iostream.h>→cout <ctype.h>→toupper()
Question 10:
Write the names of the header files, which is/are essentially required to run/execute the following C++ code.
void main()
{
char CH,Text[] = "+ve Altitude";
fortint I = 0;Text [I]!=‘\0’;I++)
if(TextCI] -- 1) cout<<endl ;
else
{
CH = toupper(Text[I]);
cout<<CH;
}
} All India 2011
Answer:
<ctype.h>→toupper() <iostream.h>→cout
0 comments:
Post a Comment
Thanks for leaving a comment. As soon as it's approved, it will appear.