Page 227 - C++
P. 227
(b) Anil typed the following C++ code and during compilation he found four errors as
follows : 1
(i) Function strlen should have a prototype
(ii) Undefined symbol cout
(iii) Undefined symbol endl
(iv) Function getchar should have a prototype
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 S[] = "Hello";
for(int i = 0; i<strlen(S); i++)
S[i] = S[i]+1;
cout<<S<<end1;
getchar();
}
(c) Rewrite the following C++ code after removing any/all syntactical errors with each
correction underlined. 2
Note : Assume all required header files are already being included in the program.
void main()
{
cout<<"Enter an integer”;
cin>>N;
switch(N%2)
case 0 cout<<"Even"; Break;
case 1 cout<<"Odd"; Break;
}
(d) Find and write the output of the following C++ program code : 2
Note : Assume all required header files are already included in the program.
#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<<end1;
}
91/1 2