Chapter 1 - Computer Programming
Chapter 1 - Computer Programming
January 2022
Table of Contents
Chapter One .................................................................................................................................. 3
1.1 Introduction to Programming ................................................................................................ 3
1.2 Types of Programming Languages ....................................................................................... 3
1.2.1 Major categories of computer program.............................................................................. 4
1.2.2 Types of programming languages by paradigm................................................................. 6
1.3 Problem Solving Techniques ................................................................................................ 8
1.3.1 Types of algorithm ............................................................................................................. 8
A Computer is an electronic device that accepts data, performs computations, and makes logical
decisions according to instructions that have been given to it; then produces meaningful
information in a form that is useful to the user. In current world we live in, computers are almost
used in all walks of life for different purposes. They have been deployed to solve different real
life problems, from the simplest game playing up to the complex nuclear energy production.
Computers are important and widely used in our society because they are cost-effective aids to
problem solving in business, government, industry, education, etc.
In order to solve a given problem, computers must be given the correct instruction about how
they can solve it. The terms computer programs, software programs, or just programs are the
instructions that tells the computer what to do. Computer requires programs to function, and a
computer programs does nothing unless its instructions are executed by a CPU. Computer
programming (often shortened to programming or coding) is the process of writing, testing,
debugging/troubleshooting, and maintaining the source code of computer programs. Writing
computer programs means writing instructions that will make the computer follow and run a
program based on those instructions. Each instruction is relatively simple, yet because of the
computer's speed, it is able to run millions of instructions in a second. A computer program
usually consists of two elements:
Data – characteristics
Code – action
Computer programs (also know as source code) is often written by professionals known as
Computer Programmers (simply programmers). Source code is written in one of programming
languages. A programming language is an artificial language that can be used to control the
behavior of a machine, particularly a computer. Programming languages, like natural language
(such as English), are defined by syntactic and semantic rules which describe their structure and
Available programming languages come in a variety of forms and types. Thousands of different
programming languages have been developed, used, and discarded. Programming languages can
be divided in to three major categories: low-level, assembly and high-level languages.
Computers only understand one language and that is binary language or the language of 1s and
0s. Binary language is also known as machine language, one of low-level languages. In the initial
years of computer programming, all the instructions were given in binary form. Although the
computer easily understood these programs, it proved too difficult for a normal human being to
remember all the instructions in the form of 0s and 1s. Therefore, computers remained mystery
to a common person until other languages such as assembly language was developed, which
Assembly language: As computer became more popular, it became quite apparent that machine
language programming was simply too slow tedious for most programmers. Assembly languages
are also called as low level language instead of using the string of member’s programmers began
using English like abbreviation to represent the elementary operation. The language provided an
opportunity to the programmers to use English like words that were called MNEMONICS. For
example:
Assembly language is nothing more than a symbolic representation of machine code, which
allows symbolic designation of memory locations. However, no matter how close assembly
language is to machine code, computers still cannot understand it. The assembly language must
be translated to machine code by a separate program called assembler. The machine instruction
created by the assembler from the original program (source code) is called object code. Thus
assembly languages are unique to a specific computer (machine). Assemblers are written for
each unique machine language.
Although programming in assembly language is not as difficult and error prone as stringing
together ones and zeros, it is slow and cumbersome. In addition it is hardware specific. The lack
of portability between different computers led to the development of high-level languages—so
called because they permitted a programmer to ignore many low-level details of the computer's
hardware. Further, it was recognized that the closer the syntax, rules, and mnemonics of the
programming language could be to "natural language" the less likely it became that the
programmer would inadvertently introduce errors (called "bugs") into the program. High-level
languages are more English-like and, therefore, make it easier for programmers to "think" in the
programming language. High-level languages also require translation to machine language
before execution. This translation is accomplished by either a compiler or an interpreter.
Compilers translate the entire source code program before execution. Interpreters translate source
The question of which language is best is one that consumes a lot of time and energy among
computer professionals. Every language has its strengths and weaknesses. For example,
FORTRAN is a particularly good language for processing numerical data, but it does not lend
itself very well to organizing large programs. Pascal is very good for writing well-structured and
readable programs, but it is not as flexible as the C programming language. C++ embodies
powerful object-oriented features
As might be expected in a dynamic and evolving field, there is no single standard for classifying
programming languages. Another most fundamental ways programming languages are
characterized (categorized) is by programming paradigm. A programming paradigm provides the
programmer's view of code execution. The most influential paradigms are examined in the next
four sections, in approximate chronological order.
In an unstructured programming paradigm all the instructions of a program are written one after
the other in a single function and hence suitable for writing only small and simple applications.
For large applications, unstructured programming paradigms cause difficulties in terms of clarity
of the code, modifiability, and ease of use. Although this type of programming paradigm is not
recommended, still most programmers start learning to program using this technique.
Procedural programming specifies a list of operations that the program must complete to reach
the desired state. Each program has a starting state, a list of operations to complete, and an
ending point. This approach is also known as imperative programming. Integral to the idea of
procedural programming is the concept of a procedure call.
Two of the most popular procedural programming languages are FORTRAN and BASIC.
The most popular structured programming languages include C, Ada, and Pascal.
Object-oriented programming is one the newest and most powerful paradigms. In object-
oriented programs, the designer specifies both the data structures and the types of operations
that can be applied to those data structures. This pairing of a piece of data with the operations
that can be performed on it is known as an object. A program thus becomes a collection of
cooperating objects, rather than a list of instructions. Objects can store state information and
interact with other objects, but generally each object has a distinct, limited role.
Computer solves varieties of problems that can be expressed in a finite number of steps leading
to a precisely defined goal by writing different programs. A program is not needed only to solve
a problem but also it should be reliable, (maintainable) portable and efficient. In computer
programming two facts are given more weight:
1. The first part focuses on defining the problem and logical procedures to follow in
solving it. There are system analysis and design tools, particularly flowchart and pseudo
code, that can be used to define the problem in terms of the steps to its solution.
2. The second introduces the means by which programmers communicate those procedures
to the computer system so that it can be executed. The programmer uses programming
language to communicate the logic of the solution to the computer.
Before a program is written, the programmer must clearly understand what data are to beused,
the desired result, and the procedure to be used to produce the result. The procedure, or solution,
selected is referred to as an algorithm. An algorithm is defined as a step-by-step sequence of
instructions that must terminate and describe how the data is to be processed to produce the
desired outputs. Simply, algorithm is a sequence of instructions. Algorithms are a fundamental
part of computing.
There are two commonly used tools to help to document program logic (the algorithm). These
are Pseudocode and flowcharts. We will use the two methods here. Generally, flowcharts work
well for small problems but Pseudocode is used for larger problems.
1.3.1.1 Pseudocode
Pseudocode (derived from pseudo and code) is a compact and informal high-level description of
a computer algorithm that uses the structural conventions of programming languages, but
typically omits detailes such as subroutines, variables declarations and system-specific syntax.
The programming language is augmented with natural language descriptions of the details,
where convenient, or with compact mathematical notation. The purpose of using pseudocode is
The programming process is a complicated one. You must first understand the program
specifications, of course, and then you need to organize your thoughts and create the program.
This is a difficult task when the program is not trivial (i.e. easy). You must break the main tasks
that must be accomplished into smaller ones in order to be able to eventually write fully
developed code. Writing pseudocode will save you time later during the construction & testing
phase of a program's development.
Example: Write a program that obtains two integer numbers from the user then it will print
out the sum of those numbers.
Pseudo code:
Start
Prompt the user to enter the first integer
Prompt the user to enter a second integer
Compute the sum of the two user inputs
Display the result
Stop
1.3.1.2 Flowchart
Print C
End
Algorithm description.
Start
Read the number x
If x is less than zero
Write a message negative
Else
Write a message not negative
Stop
Initialization: - Setting of variables of the computation to their initial values and setting
the counter for determining to exit from the loop.
Computation: - Processing
Test: - Every loop must have some way of exiting from it or else the program would
endlessly remain in a loop.
Increment: - Re-initialization of the loop for the next loop.
Example 3: - Write the algorithmic description and draw a flow chart to find the following
sum.
Sum = 1+2+3+…. + 50
Algorithmic description
Start
1. Initialize sum to 0 and counter to 1
1.1.If the counter is less than or equal to
50
2. Write sum
Stop