Professional Documents
Culture Documents
C++ Worksheet 2
C++ Worksheet 2
Execut
C++ IDE is a single place of work incorporating all the tools required for C++ program development.
c. Save the above source code with the file name “Hello.cpp” in the folder you created above.
d. Compile the source code.
e. Check in your ‘myCpps’ folder whether a file called “Hello.obj” and “Hello.exe” has been
created or not.
f. Execute (run) the program that you have already compiled
g. Compare the size of the three files “Hello.cpp”, “Hello.obj” and “Hello.exe”. What do you
observe?
h. Edit the source code by adding the statement “cout << “Press any key to continue”;” just below
“cout << “Hello World\n”;.
i. Try to run the code. What do you observed? Is the change reflected on the output? If not, why?
IV. Types of errors.
There are three types of errors. These are:-
Syntax Error: - this error occurs when we violate the grammatical rule of the programming
language.
Run time errors: - this error occurs when we ask the computer to do something it can’t do.
Logical Errors: - this error occurs when we ask the computer to do something, but mean for it to do
something else.
a. Open the program syntaxerr.cpp from the Lab 2 folder. Compile the code. How many syntax
error have you got? Correct all the syntax error and recompile the code and try to run it.
Although all syntax errors can be detected with compiler, most syntax errors are not as easy to
spot as this one.
b. Open the program runerr.cpp from the Lab 2 folder. Compile the code. Have you got any error
message from the compiler? If not, run the program. Is the program crashed? If so, can you
identify the statement that crashes the program?
Run time errors are more difficult to spot than syntax error.
c. Open the program logicalerr.cpp from the Lab 2 folder. Compile the code. . Have you got any
error message from the compiler? If not, run the program for the case first number=15 and second
number=21. Have you got what you expected?
Most logic errors are most difficult to spot and create a challenge for the programmer.