Chapter 1 - Computer Programming
Chapter 1 - Computer Programming
Chapter 1 - Computer Programming
Chapter One
1. Problem solving using computers
1.1 Introduction to computer programming
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 Amharic,Afaan Oromo,Affaraf), are defined by syntactic and semantic rules which
describe their structure and meaning respectively. The syntax of a language describes the
possible combinations of symbols that form a syntactically correct program. The meaning given
to a combination of symbols is handled by semantics. Many programming languages have some
Page 1 of 12
Samara University Department of Computer Science
form of written specification of their syntax and semantics. In general, programming languages
allow humans to communicate instructions to machines.
Assembly language correspondences symbolic instructions and executable machine codes and
was created to use letters (called mnemonics) to each machine language instructions to make it
easier to remember or write. For example:
ADD A, B – adds two numbers in memory location A and B
MOV A,B – moves the value in memory location A to B
Assembly language is nothing more than a symbolic representation of machine code, which
Page 2 of 12
Samara University Department of Computer Science
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.
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.
Page 3 of 12
Samara University Department of Computer Science
Page 4 of 12
Samara University Department of Computer Science
execution becomes a systematic search in a set of facts, making use of set of inference rules. A
set of Known facts and a set of rules result in deduction of other facts. Computation is modeled
by evaluation. Evaluation starts with a goal and attempts to prove it with a known fact or by
deducing it from some rule. Programmer states only the logic of the program. Eg prolog
programming language uses this paradigm.
Page 5 of 12
Samara University Department of Computer Science
are flowcharts, structured chart, and Pseudocode. We will use the three methods here.
Generally, flowcharts work well for small problems but Pseudocode is used for larger problems.
1.4.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
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. No standard for pseudocode syntax exists, as a program in pseudocode is not an
executable program. As the name suggests, pseudocode generally does not actually obey the
synatx rules of any particular language; there is no systematic standard form, although any
particular writer will generally borrow the appearance of a particular language.
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 pseudo code will save you time later during the construction & testing
phase of a program's development.
Example:
Original Program Specification:
Write a program that obtains two integer numbers from the user. It will print out the sum of
those numbers.
Pseudocode:
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 an output prompt that explains the answer as the sum
Display the result
Page 6 of 12
Samara University Department of Computer Science
CelsusToFarh
(main func)
Centigrade Fahrenheit
Centigrade
1.4.3 Flowchart
A flowchart (also spelled flow-chart and flow chart) is a schematic representation of an
algorithm or a process. The advantage of flowchart is it doesn’t depend on any particular
programming language, so that it can used, to translate an algorithm to more than one
programming language. Flowchart uses different symbols (geometrical shapes) to represent
different processes. The following table shows some of the common symbols.
Page 7 of 12
Samara University Department of Computer Science
Example 1: - Draw flow chart of an algorithm to add two numbers and display their result.
Algorithm description
• Read the rules of the two numbers (A and B) Start
• Add A and B
• Assign the sum of A and B to C
Read A, B
• Display the result ( c)
C= A+B
The flow chart is:
Print C
End
Page 8 of 12
Samara University Department of Computer Science
Example 2: Write an algorithm description and draw a flow chart to check a number is negative
or not.
Algorithm description:
1/ Read a number x
2/ If x is less than zero write a message negative
else write a message not negative
Some times there are conditions in which it is necessary to execute a group of statements
repeatedly. Until some condition is satisfied. This condition is called a loop. Loop is a sequence
of instructions, which is repeated until some specific condition occurs. A loop normally consists
of four parts. These are:
• 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
1. Initialize sum to 0 and counter to 1
Page 9 of 12
Samara University Department of Computer Science
This process may involve end users who come up with an idea for improving their work or may
only involve IS people. Ideally, the process occurs in tandem with a review of the organization's
strategic plan to ensure that IT is being used to help the organization achieve its strategic
Page 10 of 12
Samara University Department of Computer Science
objectives. Management may need to approve concept ideas before any money is budgeted for
its development.
A preliminary analysis, determining the nature and scope of the problems to be solved is carried
out. Possible solutions are proposed, describing the cost and benefits. Finally, a preliminary plan
for decision making is produced.
The process of developing a large information system can be very costly, and the investigation
stage may require a preliminary study called a feasibility study, which includes e.g. the following
components:
a. Organizational Feasibility
• How well the proposed system supports the strategic objectives of the organization.
b. Economic Feasibility
• Cost savings
• Increased revenue
• Decreased investment
• Increased profits
c. Technical Feasibility
• Hardware, software, and network capability, reliability, and availability
d. Operational Feasibility
• End user acceptance
• Management support
• Customer, supplier, and government requirements
End users must be involved in this process to ensure that the new system will function
adequately and meets their needs and expectations.
Page 11 of 12
Samara University Department of Computer Science
1.5.5 Implementation
The real code is written here. Systems implementation is the construction of the new system and
its delivery into production or day-to-day operation. The key to understanding the
implementation phase is to realize that there is a lot more to be done than programming.
Implementation requires programming, but it also requires database creation and population, and
network installation and testing. You also need to make sure the people are taken care of with
effective training and documentation. Finally, if you expect your development skills to improve
over time, you need to conduct a review of the lessons learned.
1.5.6 Testing
Normally programs are written as a series of individual modules, this subject to separate and
detailed test. Integration and System testing; Brings all the pieces together into a special testing
environment, then checks for errors, bugs and interoperability. The system is tested to ensure that
interfaces between modules work (integration testing), the system works on the intended
platform and with the expected volume of data (volume testing) and that the system does what
the user requires (acceptance/beta testing).
1.5.7 Maintenance
What happens during the rest of the software's life: changes, correction, additions, and moves to
a different computing platform and more. This, the least exciting and perhaps most important
step of all, goes on seemingly forever.
Page 12 of 12