Programming Chapter 1
Programming Chapter 1
E.C
1.1. What is computer • For a computer to be able to do anything (start up, play
Computer is a general purpose electronic machine that is a song, run a word processor), it must first be given the
a dump machine & can’t do anything by itself unless it is • The instructions are written by humans in different
Hardware: refers to the physical components of your the machine can run (0101010101111)
computer such as the system unit, mouse, keyboard, 1.3. Reasons to study programming
monitor etc. Increased capacity to express programming concepts
Increased ability to learn new languages
Software: is the instruction that makes the computer
Understand the significance of implementation
work. Increased ability to design new languages
1.2. What is computer programming Mastering different programming paradigms(structures)
To solve problems
Is the art of making computer do what you want to do or it is
writing a set of instruction to get the computer to perform
Problem solving
some task.
A computer program is simply a set of instruction to tell the
computer to perform the particular task or a set of instruction
1|Page
Chapter 1 – Introduction to computer programming 2014
E.C
2|Page
Chapter 1 – Introduction to computer programming 2014
E.C
In this phase we focus on “HOW” question. How can Syntax rule: correct way of writing or expressing
we implement the new system to achieve system commands using one of programming languages that
objective or solution for the problem?
direct the control of the computer system.
You will develop algorithm (Algorithm is a step by step
procedure for solving problems). 5. Testing
There are different ways of describing of algorithm. Also called program verification or debugging.
o Pseudo codes The goal is to test the program for several
o Flow chart representative cases& ensure that the appropriate
the computer. They must first be translated into Error in the program is called bug and the process of
step) in one of the various programming language. Three types of error: -syntax error, run time error and
3|Page
Chapter 1 – Introduction to computer programming 2014
E.C
4|Page
Chapter 1 – Introduction to computer programming 2014
E.C
Are machine dependent i.e. a particular Like machine language it is also machine
machine language can be used on only one dependent.
type of computer. It requires translator for translation
process i.e. it requires more time.
ii) Low level language Since it is machine dependent therefore
It was developed to overcome some of the many programmer should have the knowledge of
inconveniences of machine language. the hardware also.
Represents operations and operands in the form of iii) High level language
alphabetic symbols instead of 0’s and 1’s. High level language gives formats close to English
These alphabetic symbols will be known as mnemonic language
codes and can have maximum up to 5 letter The purpose of developing high level languages is to
combination e.g. ADD for addition, SUB for subtraction, enable people to write program easily and in their own
START, LABEL etc. because of this feature it is also native language environment (English).
known as ‘symbolic programming language’. High level language are basically symbolic languages
This language is also very difficult and needs a lot of that use English words and mathematical symbols
practice to master it because very small English rather than mnemonic codes.
support is given to this language. Each instruction in the high level language is translated
The instruction of low level language will also be into many machine language instructions thus showing
converted to machine codes by translator to be one-to-many translation.
executed by the computer. o Advantage of high level language
Example: - assembly language User friendly.
o Advantage of low level language Similar to English with vocabulary of words
It is easier to understand and use as and symbols.
compared to machine language. I.e. it is easier to learn.
It is easy to locate and correct errors. Require less time to write and easier to
It is modified easily. debugged errors.
o Disadvantage of low level language They are easier to maintain.
5|Page
Chapter 1 – Introduction to computer programming 2014
E.C
Problem oriented rather than ‘machine’ language and low-level language to machine code
based. program are called translators.
Programs written in a high level language The translators not only translate the instructions into
can be translated into many machine machine code but also it detects whether the program
language and therefore can run on any fulfills the syntax of the programming language. A
computer for which there exists an program passes through different stages before it
appropriate translator. carries out its function. First the program will be
It is independent of the machine on which translate to object code (compilation time), then it will
it is used. I.e. programs developed in high be loaded to the memory and finally it will be executed
level language can be run on any (run time) or carries out its function.
computer.
o Disadvantage of high level language Language Translation and Utility Software
A high level language has to be translated Source code: high-level language instructions
into the machine language by a translator Compiler: translates high-level code into machine
and thus a price in computer time is paid. language
Example: - FORTRAN, COBL, C, C++ Object code: translated instructions ready for computer
For every modern language, there is a program that
Translation and execution takes the source code and produces object code in
machine language
The only language that the computer understands is There are three types of translators; assembler,
the machine language. Therefore any program that is interpreter, and compiler.
written in either low-level or high level language must Compiler - A set of programs that translate the source
be translated to machine code so that the computer code of higher-level software languages into machine
could process it.
language, or object code
A program written in high-level or low-level language is
called source code program and, the translated Translates source code once and produces a complete
machine code is called the object code program. machine language program
Programs that translate a program written in high level Advantages - fast
6|Page
Chapter 1 – Introduction to computer programming 2014
E.C
Interpreter - An interpreter translates source code Unstructured programming refers to write small and simple
instructions, one instruction at a time, from a higher level program, which consists of only one main program. All the
language such as BASIC into machine language
action such as providing the input, processing and display
It translates a line of source code into one or more lines output are done within one program only. This style of
of object code and then instructs the computer to
programming restricted for developing small application, but
perform those instructions until another line has to be
translated if the application become large it possess real difficulties in
Advantages - fairly easy to write, and easy to debug terms of clarity of the code, modifiability and easy to use.
Disadvantage - SLOW
Examples - basic, lisp 2. Structured programming
Process of writing a program in small, independent parts.
This makes it easier to control a program’s
Source code Translators development and to design and test its individual
Object code
component parts.
Structured programs are built up from units called
1.5 Programming paradigms modules, which normally correspond to single
The major land marks in the programming world are the procedures or functions.
different kinds of features or properties observed in the The most popular structured programming languages
development of programming language. Among those the include C, Ada, and Pascal.
following are worth mentioning:-
Structured programming can performed in to two ways,
7|Page
Chapter 1 – Introduction to computer programming 2014
E.C
8|Page
Chapter 1 – Introduction to computer programming 2014
E.C
9|Page
Chapter 1 – Introduction to computer programming 2014
E.C
It is an artificial & informal language that will convert to Display an output prompt that explains the answer as the
structured programs for executed on computer. sum
By making use language. Display the result
10 | P a g e
Chapter 1 – Introduction to computer programming 2014
E.C
Repetition
11 | P a g e
Chapter 1 – Introduction to computer programming 2014
E.C
I. Pseudo code
E.g3. Write an algorithm description and draw a flow chart to
Algorithm description. find the sum of n natural numbers.
I. Pseudo code
1. Start /begin
2. Read a number x
1. Start /begin
3. If x is less than zero write a message negative
2. Read a number N
4. else write a message not negative
3. Initialize i to 1 and sum to 0
5. End/Stop
4. If i less than or equal to N goto step 6
5. Else if goto step 9
6. sum = sum + i
7. i = i+1
8. goto 4
9. print sum
10.End/Stop
12 | P a g e
Chapter 1 – Introduction to computer programming 2014
E.C
13 | P a g e