CBSE computer and communication technology

Sponsor Area

Question
CBSEENCO12011513

Write the type of C++ tokens (keywords and user-defined identifiers) from the following :

(i) For
(ii) delete
(iii) default
(iv) Value

Solution

(i) For - user defined identifier
(ii) delete - keyword
(iii) default - keyword
(iv) Value - user defined identifier

Sponsor Area

Question
CBSEENCO12011514

Anil typed the following C++ code and during compilation, he found four errors as follows:

(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();
}

Solution

In the given program header files are missing such as iostream.h, stdio.h and string.h.

Question
CBSEENCO12011515

Rewrite the following C++ code after removing any/all syntactical errors with each correction underlined.

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;
}

Solution

void main()
{
      int N;
      cout<<'Enter an integer';
      cin>>N;
      switch(N%2)
{
     case 0 :
     cout<<'Even'; break;
     case 1 :
     cout<<'Odd' ; break;
}

Each correction is bold and underlined.

Question
CBSEENCO12011516

Find and write the output of the following C++ program code :

#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<<endl;
	getch();
}

Solution

Output: zyom

Question
CBSEENCO12011517

Find and write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.

void main()
{
	int A[]={10,12,15,17,20,30};
	for(int i = 0; i<6; i++)
	{
		if(A[i]%2==0)
			A[i] /= 2;
		else if(A[i]%3==0)
			A[i] /= 3;
		if(A[i]%5==0)
			A[i] /=5;
	}
	for(i = 0; i<6; i++)
		cout<<A[i]<<'#';
	getch();
}

Solution

Output: 1#6#1#17#2#3#