Programming Chapter 1
Programming Chapter 1
Computer Programming involves writing instructions and giving them to the computer to
complete a task. A computer program or software is a set of instructions written in a computer
language in order to be executed by a computer to perform a useful task.
Ex: Application software packages, such as word processors, spreadsheets and databases are
all computer programs
Computer Programmer is a person who translates the task you want a computer to do into a
form that a computer can understand.
Programming language refers to a series of specifically defined commands designed by human
programmers to give directions to digital computers. It is a means of communication between a
human being (programmer) and a computer. A programmer uses this means of communication in
order to give the computer instructions. A programming language is an artificial language that
can be used to control the behavior of a machine, particularly a computer. Programming
languages, like human languages, are defined through the use of syntactic and semantic rules, to
determine structure and meaning respectively. Programming languages differ from natural
languages in that natural languages are only used for interaction between people, while
programming languages also allow humans to communicate instructions to machines.
All programming language instructions must be expressed in binary code before the computer
can perform them.
Page 1 of 11
Introduction to Programming using C++ 2015
All programs must be translated before their instructions can be executed. Computer translation
languages can be grouped according to which translation process is used to convert the
instructions into binary code:
Assemblers
Interpreters
Compilers
Assembler: a program used to translate Assembly language programs into machine language. It
produces one line of binary code per original program statement. The entire program is
assembled before the program is sent to the computer for execution.
Program in
Program in
Assembly Assembler Machine
language language
Compiler: a program used to translate high-level programs. It translates the entire program into
binary code before anything is sent to the CPU for execution.
Program in
High level Program in
language Compiler Machine
language
Page 3 of 11
Introduction to Programming using C++ 2015
The table below (table 1.1) shows the detail of activities performed in each of the above mentioned
steps.
Page 4 of 11
Introduction to Programming using C++ 2015
Page 6 of 11
Introduction to Programming using C++ 2015
Pseudo code: is English like language for representing the solution to a problem. Pseudo code
is independent of any programming language. Pseudo code (or a flow chart) is the first step in
the process of planning the solution to a problem (also called developing an algorithm).
Flow chart: is a graphical way of representing the solution to a problem. The symbols used in
flow charts are shown in table 1.2 below.
Page 7 of 11
Introduction to Programming using C++ 2015
that you need to clearly indent (or bracket) sections of code that belong inside a conditional
statement or loop, and you need to be consistent about the wording you use. No standard for
pseudocode syntax exists, as a program in pseudocode is not an executable program.
The purpose of using pseudocode is that it may be easier for humans to read than conventional
programming languages, and that it may be a compact and environment-independent generic
description of the key principles of an algorithm. Writing pseudocode will save you time later
during the construction & testing phase of a program's development.
Example 1: -Adding two numbers: When you are asked to add numbers, what you know for sure
is that addition operation involves two operands at a given time. The first step is to have the two-
operand values. Then we add these operands and store the result to another operand. This is just
a description. To check if this works lets assume the following.
Input; - x, y
Process: Compute the arithmetic sum of the two numbers, put result on variable
Output: display the sum of two numbers
1. Begin
Start
2. Read X, Y
Read X,Y 3. Calculate Sum
3.1. Formula:
Sum= X+Y
Sum=X+Y
4. Display Sum
Display Sum
5. End
Stop Structures
Basic Control
Page 8 of 11
Introduction to Programming using C++ 2015
In general speaking, the problems in programming can have either of these structures: sequence,
selection and repetition.
Start 1. Begin
2. Input a, b, c
Input a,b, c
3. Calculate Sum
3.1. Formula:
Sum= a+b+c
Sum=a+b+c
4.1. Formula:
Display Average
Average=Sum/3
5. Display Average
Stop
6. End
Start 1. Begin
2. Read a,b
Read a,b
3. If a>b
No Print a
Is
a>b 4. Else
Yes
Print b
Print a Print b
5. End
Stop
Page 10 of 11
Introduction to Programming using C++ 2015