Page 168 - C++
P. 168
(c) Rewrite the following C++ code after removing any/all Syntactical Error(s) with each correction underlined.
Note: Assume all required header files are already being included in the program. (2)
typedef char [80] String;
void main ( )
{
String S= “Peace”;
int L=strlen(S) ;
cout<<S<< ‘has’<<L<< ‘characters’<<end1;
}
Ans. #include<string.h>
#include<iostream.h>
typedef char String [80];
void main ( )
{
String S = “Peace”;
int L= strlen(S) ;
cout<<S<< “has” << L << “characters”<<endl;
}
(d) Find and write the output of the following C++ program code: (3)
Note: Assume all required header files are already being included in the program.
void main()
{
char *NAME=”a ProFiLe”;
for(int x=0;x<strlen(NAME);x++)
if(islower(NAME[x]))
NAME[x]=toupper(NAME[x]);
else if(isupper(NAME[x]))
if(x%2!=0)
NAME[x]=tolower(NAME[x-1]);