COMPUTER SCIENCE C++

2007 Delhi :

1.a) Differenctiate between a Run Time Error and Syntax Error. Also give suitable examples of each in c++.

Ans: Run Time Errors: Errors that occur during the execution of a program are called as run time errors. It is caused of some illegal peration taking place or inavailability of desired or required conditions for the execution of the program. For instance, if a program is trying to open a file which does not exist or it could not be opened, it results into an execution error. Similarly, if enough memory is not available or an expression is trying to divide a number by zero are run-time errors.

2

Eg: Division by zero.c=a/b;
User will give the values of a and b at the time of program execution.If he give the value of b as ‘0’ , then division by zero, ie a run time error occurs.

Syntax Errors: 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.

void main( )
{ char String[20];
gets(String);
strcat(String,”CBSE”);
puts(String);}

1

Ans) stdio.h string.h

1. c) Rewrite the following program after removing the syntactical error(s) if any.Underline each correction.

#include<iostream.h>
const int Max 10;
void main()
{ int Numbers[Max];
Numbers = {20,50,10,30,40};
for(Loc=Max-1;Loc>=10;Loc--)
cout>>Numbers[Loc];}

2

Ans)

#include<iostream.h>
const int Max = 10;// Constant Variable ‘Max’ //must be initialized.Declaration Syntax Error
void main( )
{ int Numbers[Max]={20,50,10,30,40};
for(Loc=Max-1;Loc>=0;Loc--)
cout>>Numbers[Loc];
}

 

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( mrkdata@yahoo.com )


Warning: include_once(../../ebooks-footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp6.php on line 111

Warning: include_once(): Failed opening '../../ebooks-footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp6.php on line 111

Warning: include_once(../../../footer19.php): Failed to open stream: No such file or directory in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp6.php on line 113

Warning: include_once(): Failed opening '../../../footer19.php' for inclusion (include_path='.:/opt/cpanel/ea-php83/root/usr/share/pear') in /home/cbseguess/public_html/ebooks/xii/coumputer-science/cpp6.php on line 113