Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Adama Science & Technology University

School of Electrical Engineering & Computing


Computer Science & Engineering Program
Worksheet 2(Phases ,C++ IDE & errors)
Objectives

 To see the phases that a C++ program passes


 To work with C++ IDE(Integrated Development Environment)
 To identify different types of errors

C++ Program creating tools


The C++ System includes three major components:
 Program development environment (Editor + Compiler)
 The Language (Your C++ language knowledge)
 C++ Standard Library (Commonly used functions)
I. Once a programmer gets these components of the C++ system, C++ programs typically go through six
phases to be executed. These are:-
 Edit: - in this phase a program is created using a text editor. (e.g. Turbo C++ editor, notepad,
DOS-Editor, etc). The result of the edit phase is a collection of text files containing C++ source
code. C++ source files usually have a ".cpp" or ".cc" extension.
 Preprocess: - the preprocess and compile phases are usually done together, with the preprocessor
running first, next the compiler and then the link. The preprocessor makes changes to a C++
source file and saves these changes in a temporary file. We normally don't care what this
temporary file looks like.
 Compile: - the compiler translates the C++ source code into machine (or object) code that the
computer can execute. The type of machine code depends on the type of computer. The result of
the compile phase is a binary file containing machine code.
Object files usually have a ".o" or ".obj" ending/extension.
While object file contain machine code, they do not contain a complete program, so they cannot be
executed by themselves.
 Link: A linker combines the object files into a single executable file that the computer can run.
The linker may also extract object code from libraries. Libraries are files containing the object
code of commonly used functions. The executable file contains machine code. Executable files in
a MS-DOS or Microsoft Windows system have a ".com" or ".exe" ending.
 Load:- A loader program loads the executable file from the disk into memory so that it can be run.
 Execute:- Each instruction of the machine code are fetched from the RAM one by one in to the
CPU and executed by the processor. Cs.lib Processor
CPU
Library Files

Execut

Edit Preprocess Link Load


Hello.cpp Hello.obj Hello.exe RAM
&Compile
Source Code Object Code Executable file Primary Memory

II. CodeBlock C++ IDE (Integrated Development Environment)

C++ IDE is a single place of work incorporating all the tools required for C++ program development.

a. How can the IDE be opened (Three ways)?


1
Adama Science & Technology University
School of Electrical Engineering & Computing
Computer Science & Engineering Program

 From the start menu


 By going through the directory path
 By using the run command from the start menu and entering the path in the run dialog
box.
b. Pull down each of the menu item and explore each of the menu commands.
III. Working with your first program
a. Create a folder on ypur desktop named myCpps
b. Open a new window and write the following simple C++ source code.
#include <iostream>
using namespace std;
#include <conio.h>
int main()
{
cout << “Hello World\n”;
getch();
return 0;

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.

You might also like