CBSE Guess > Papers > Important Questions > Class XII > 2010 > Computer Science > Computer Science By MRK
CBSE CLASS XII
2007 Outside Delhi
1.a. Differentiate between a Logical Error and Syntax Error. Also give suitable examples of each in C++.
Ans Logical Error. A logical error is that error which causes a program to produce incorrect or undesired output.
An incorrectly implemented algorithm or use of a variable before its initialization, or unmarked end for a loop, or wrong parameters passed are causes logical errors. These must be handled carefully.
For instance, if we are trying to print the table of a number 5 and if we say
counter=1;
while(counter>8)
{ cout<<n*counter;
counter=counter+1;
}
Here the loop would not be executed even once as the condition (counter>8) is not fulfilled at all. Therefore, no output will be produced. Such an error is logical error.
Syntax Error: Syntax errors occur when rules of a programming languages (syntax) is misused. Ie when a grammatical rule of C++ is violated.
Eg (i) c=a+b
In this statement, since there is no semicolon at the end of the statement, there will occurs a syntax error.
(ii)cin<<a; In this statement, since stream insertion operator (<<) has given instead of stream extraction operation(>>), there will occurs a syntax error.
1.b. Name the header file(s) that shall be needed for successful compilation of the following C++ code. 1
void main( )
{ char Text[40];
strcpy(Text,”AISSCE”);
puts(Text); }
Ans. string.h, stdio.h
1.c. Rewrite the following program after removing the syntactical error(s), if any. Underline each correction. 2
#include<iostream.h>
const int Size 5;
void main( )
{ int Array[Size];
Array={50,40,30,20,10};
for(Ctr=0;Ctr<Size;Ctr++)
cout>>Array[Ctr];
}
Ans.
#include<iostream.h>
const int Size=5;
void main( )
{ int Array[Size];
Array={50,40,30,20,10};
for(Ctr=0;Ctr<Size;Ctr++)
cout<<Array[Ctr];
}
1.e. Find the output of the following program3#include<iostream.h>
void Indirect(int Temp=20)
{ for(int I=10;I<=Temp;I+=5)
cout<<I<<”,”;
cout<<endl;
}
void Direct(int &Num)
{ Num+=10;
Indirect(Num);
}
void main( )
{ int Number=20;
Direct(Number);
Indirect( );
cout<<”Number =”<<Number<<endl;
}
Ans. Output: 10,15,20,25,30,
10,15,20,
Number =30
Paper By Mr. MRK
Email Id : [email protected]@yahoo.com |
|