Topic 1: Programming
welcome
Definition of basic
2
terms
Programming:
Programming is the translation of user ideas into
a representation or form that can be understood
by the computer.
The tools of writing programs are called
programming languages.
Programming language:
A programming language is a set of rules used to
write computer programs. Like human languages,
Structured Programming
Structured programming is an approach to
writing programs that are easier to read, test,
3
debug and modify.
The approach assists in the development of
large programs through stepwise refinement
and modularity.
Programs designed this way can be developed
faster. When modules are used to develop large
programs, several programmers can work on
different modules, thereby reducing program
development time.
structured programming serves to:
i. increase programmer productivity,
ii. program reliability (readability and execution
time),
Steps in program
development
Design program objectives
It involves4 forming a clear idea in terms of the information you want to
include in the program, computations needed and the output. At this
stage, the programmer should think in general terms, not in terms of
some specific computer language.
Design program
The programmer decides how the program will go about its
implementation, what should the user interface be like, how should the
program be organized, how to represent the data and what methods to
use during processing. At this point, you should also be thinking
Steps in program
5
development…
DeveDevelop the program
loping a program in a compiled language such
as C requires at least four steps:
• Editing (or writing) the program
• Compiling it
• Linking it
• Executing it
Steps in program
development…
Editing
• You write a computer program with words and symbols that
are understandable to human beings.
• This is the editing part of the development cycle.
• You type the program directly into a window on the screen
and save the resulting text as a separate file.
• This is often referred to as the source file . The custom is
that the text of a C program is
• stored in a file with the extension .c for C programming
language
Steps in program
development…
Compiling
You cannot directly execute the source file. To run on
any computer system, the source file must be
6
translated into binary numbers understandable to the
computer's Central Processing Unit. This process
produces an intermediate object file - with the
extension .obj.
Linking
The main reason for linking is that many compiled
languages come with library routines which can be
added to your program. Theses routines are written by
the manufacturer of the compiler to perform a variety
of tasks, from input/output to complicated
mathematical functions. In the case of C the standard
input and output functions are contained in a library
Steps in program
development…
Executable files
The text editor produces .c source files, which go to the
compiler, which produces .obj object files, which go to the
linker, which produces .exe executable file. You can then run .exe
files as you run applications, simply by typing their names at
the DOS prompt or run using Windows menu.
Test the program
This involves checking whether the system does what it is
supposed to do. Programs may have bugs (errors). Debugging
involves the finding and fixing of program errors.
Maintain the program
Occasionally, changes become necessary to make to a given
program. You may think of a better way to do something in a
Program Development
1. Define the problem. Human thought
2. Plan the problem solution. writing the algorithm
[pseudo-natural language (English, Arabic) or
drawing the flowchart diagram).
3. Code the program. High Level Programming
Language (C, C++, Java, …)
4. Compile the program. Machine Code
5. Run the program.
6. Test and debug the program.
Asma Alosaimi 9
When planning for a problem solution, algorithms are used to
outline the solution
An algorithm is a step-by-step procedure for solving a
programming problem within finite number of steps
Pseudocode – Short structured English like statements that outline
the step-by-step procedure for solving a programming problem
A flowchart – A pictorial or graphical representation of an
algorithm.
Asma Alosaimi 10
Pseudocode
• Pseudocode is a detailed description of what a computer program
must do, expressed in short, structured, English like statements rather
than in a programming language.
Asma Alosaimi 11
Pseudocode Example
Write a Program to Print the Sum of two
integer Numbers
1. Start
2. Read the first number (N1)
3. Read the second number(N2)
4. Sum = N1 + N2
5. Print Sum
6. End
Asma Alosaimi 12
Flowchart
• A flowchart is a pictorial representation of an algorithm , showing the
steps as boxes of various kinds
• example: [rectangles, diamonds, ovals], and their order by
connecting these with arrows.
Asma Alosaimi 13
Flowcharts Symbols
Start
14
Start/EndEnd
Print n1
Read/Print Read n1
N2 =Operations
Arithmetic n1+3 N2 = 5
Decision , can be
n1used
> 3 with
loops
Solution
start
Draw a flowchart for a program that calculates
and print the area and the perimeter of
Read L, W
a rectangle.
• Input
• Length area = L * W
• width
• Processing perimeter = 2 (L+W)
• Area = length*width
• Perimeter = 2*( length + width) Print area
• Output
• Area Print perimeter
• Perimeter
Asma Alosaimi
End 15
Example 2
• Draw the flow chart for a program that calculates the total
salary for an employee using this equation:
Total_Sal = Salary +Overtime
Asma Alosaimi 16
Solution
Input start
Salary
Overtime Read Salary
Processing
Total_Sal = Salary +Overtime Read Overtime
Output
Total_Sal Total_Sal =
Salary +Overtime
Print Total_Sal
Asma Alosaimi
End 17