CBSE eBooks

CBSE Guess > eBooks > Class XII > Computer Science By . Mr. MRK

Chapter – 1 C++ Revision Tour

Previous Index Next

1998 Annual Paper:

1.b. Name the header files, to which the following built in functions belongs to:

  1. cos( )
  2. setw( )
  3. toupper( )
  4. strcpy( )

Ans:

  1. cos( ) - math.h
  2. setw( ) - iomanip.h
  3. toupper( ) - ctype.h
  4. strcpy( ) - string.h

1.c. Find the syntax error(s), if any, in the following program:

include<iostream.h>
void main( )
int R; W=90;
{
while W>60
{
R=W-50; switch(W)
{
20:cout<<”Lower Range”<<endl;
30:cout<<”Middle Range “<<endl;
40:cout<<”Higher Range”<<endl;
}
}
}

Ans:

  1. Line 1: It should be, # include<iostream.h>
  2. Line 4:Variables should be separated using commas. It should be int R,W=90;
  3. Line 5:Test expression should be in braces. It should be while (W>60)
  4. Line 10:It should be case 20;
  5. Line 11:It should be case 30;
  6. Line 13:It should be case 40;

So the corrected version of the program is as follows:

#include<iostream.h>
void main( )
{
int R, W=90; while (W>60)
{
R=W-50; switch(W)
{
case 20:cout<<”Lower Range”<<endl;
case 30:cout<<”Middle Range “<<endl;
case 40:cout<<”Higher Range”<<endl;
}
}
}

1.d. Give the output of the following program segment:

char *NAME=”IntRAneT”;
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]);
else
NAME[x]=NAME[x-1]; puts(NAME);

Ans: Output: INTTaNEE

1.e. Write the output of the following program:

#include<iostream.h>
void Execute(int &X,int Y=200)
{
int TEMP=X+Y; X+=TEMP;
if(Y!=200) cout<<TEMP<<X<<Y<<endl;
} void main( )
{
int A=50,B=20; Execute(B);
cout<<A<<B<<endl;
Execute(A,B);
cout<<A<<B<<endl;
}

Previous Index Next