0% found this document useful (0 votes)
126 views43 pages

Unit One: Introduction To Programming

This document provides an introduction to programming languages. It discusses the meaning and significance of programming languages, as well as the different levels of programming languages including machine language, assembly language, and high-level languages. It also describes features of programming languages, translators such as compilers and interpreters, the programming environment, and the typical program development cycle of problem analysis, design, coding, and testing/debugging.

Uploaded by

abdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views43 pages

Unit One: Introduction To Programming

This document provides an introduction to programming languages. It discusses the meaning and significance of programming languages, as well as the different levels of programming languages including machine language, assembly language, and high-level languages. It also describes features of programming languages, translators such as compilers and interpreters, the programming environment, and the typical program development cycle of problem analysis, design, coding, and testing/debugging.

Uploaded by

abdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 43

UNIT ONE

INTRODUCTION TO PROGRAMMING

Part One
1
Meaning and Significance of Programming Languages
• A program is a set of codes that instructs the
computer to carry out some processes.
• Programming is the process of writing programs.
• Programming Languages are languages through
which we can instruct the computer to carry out
some processes or tasks.
• They are also designed to communicate ideas about
algorithms between human beings and computers.
• Programming languages can be used to execute a
wide range of algorithms, that is, an instruction could
be executed through more than a procedure of
execution.
2
• Like writing a report or paper in English, French, writing
a computer program in a programming language
requires that the programmer follows a set of rules.
• Each programming language uses a set of symbols that
have a special meaning.
• Each Language also has its own set of rules just like
English or French has its own grammatical rules of
grammar and communication.
• These rules of programming languages are called the
Syntax of the language.
• The language’s syntax dictates how the symbols should
be combined in to statements, capable of conveying
meaningful instruction to the CPU.
• Both systems and application software are produced as a
result of programming activities

3
Levels of Programming Languages
• Programs and programming languages have been in
existence since the invention of computers.
• There are three levels of programming languages. These
are:
1) Machine Language: Machine language is a set binary
coded instruction, which consists of zeros (0) and ones (1).
• Machine language is peculiar to each type of computer.
• The first generation of computers was coded in machine
language that was specific to each model of computer.
• Some of the shortcomings of the machine language were:
• 1. Coding in machine language was a very tedious and
boring job

4
2. Machine language was not user-friendly.
• That is the user had to remember a long list of
codes, numbers or operation codes and know
where instructions were stored in computer
memory.
3. Debugging any set of codes is a very difficult
task since it requires going through the program
instruction from the beginning to the end.
• The major advantage of machine language is that
it requires no translation since it is already in
machine language and is therefore faster to
execute.
5
2. Assembly Language
• This is a low level of programming language which
is different from the machine language.
• That is, the instructions are not entirely in binary
coded form.
• It also consists of some symbolic codes, which are
easier to remember than machine codes.
• In assembly language, memory addresses are
referenced by symbols rather than addresses in
machine language.
• Assembly language is also called Symbolic
language, because it makes use of an assembler to
translate codes into machine language. 6
• The disadvantages of assembly language are
that:
• It is specific to particular machines
• It requires a translator called an assembler.
• The major advantage of the assembly language
is that programs written in it are:-
 Easier to read and more user friendly than
those written in machine language, especially
when comments are inserted in the codes

7
3. High Level Language:
• This programming language consists of English-like
codes.
• It is machine independent language
• High-level language is independent of the computer
because the programmer only needs to pay attention to the
steps or procedures involved in solving the problem for
which the program is to be used to execute the problem.
• High-level language is usually broken into one or more
states such as:
• Main programs, sub-programs, classes, blocks,
functions, procedures, etc.
• The name given to each component differs from one
language to the other.
8
 Some advantages of high-level language:
• It is more user friendly, that is, easy to learn and
write
• It is very portable, that is, it can be used on almost
any computer
• It saves much time and effort when used compared
to any other programming level language.
• Codes written in this language can easily be
debugged.
• But it requires translator program called compiler or
interpreter i.e.; translates programs written in high
level language to machine code.
9
Features of Programming Languages
 There are some conventional features which a
programming language must possess, these features are:
• It must have syntactic rules for forming statements.
• It must have a vocabulary that consists of letters of the
alphabet.
• It must have a language structure, which consists of
keywords, expressions and statements.
• It may require a translator before it can be understood by
a computer.
• Programming languages are written and processed by the
computer for the purpose of communicating data
between the human being and the computer.
10
Translators
• A translator is a program that translates another
program written in any programming language other
than the machine language to an understandable set
of codes for the computer and in so doing produces
a program that may be executed on the computer.
• The need for a translator arises because only a
program that is directly executable on a computer is
the machine language.
• Examples of a translator are:-
1. Assembler: This is a program that converts
programs written in assembly or low-level language
to machine language.
11
2 Interpreters and Compilers:
• These consist of programs that convert programs in
high level programming language into machine
language.
• The major difference between interpreters and
compilers is that a:-
 A compiler converts the entire source program into
object code before the entire program is executed
 Interpreter translates the source instructions line by
line.
• In the former, the computer immediately executes
one instruction before translating the next instruction

12
Features of Translators
• They exist to make programs
understandable by the computer
• There exist different translators for
different levels and types of programming
languages
• Without them, the programs cannot be
executed.

13
The Programming Environment
• The Editor: An editor allows a program to be
retrieved from the disk and amended as
necessary.
• In order to type any program from the keyboard
and save the program on a disk, it will be
necessary to run a program called an editor.
• The Compiler: This will translate a program
written in high level language stored in a text
mode on a disk to the program stored in a
machine-oriented language on a disk.

14
• The Linker/Loader: A linker/loader picks
up the machine-oriented program and
combines it with any necessary software
(already in machine oriented form) to
enable the program to be run.
• Before a compiled program can be run or
executed by the computer, it must be
converted into an executable form.

15
Program Development Cycle
• The major five stages involved in developing an efficient
program are:-
1) Problem Analysis: This is where the clear statement of
the problem is stated.
• The programmer must be sure that he understands the
problem and how to solve it.
• He must know what is expected of the problem, i.e.
 what the program should do?
 the nature of the output and
 the input to consider so as get the output.
 understand the ways of solving the problem and
 the relationship between the input and the expected
output 16
2) Design
• The planning of the solution to the problem in the first
stage takes place in this stage.
• The planning consists of the process of finding a logical
sequence of precise steps that solve the problem.
• Such a sequence of steps is called an algorithm.
• Every detail, including obvious steps should appear in the
algorithm.
• The three popular methods used to develop the logic plan are:
 flowcharts
 a pseudo code, and a top-down chart.
• These tools help the programmer break down a problem into
a sequence of small tasks the computer can perform to solve
the problem.
17
3) Coding
• Translation of the algorithm in stage two into a
programming language takes place here.
• The process for writing the program is called coding.
• The programmer uses the algorithm devised in the design
stage along with the choice of the programming language he
got from stage three.
4) Testing and Debugging:
• The process involves the location and removal of error in
the program if any.
• Testing is the process of checking if the program is
working as expected and finding errors in the program.
• And debugging is the process of correcting errors that are
found (An error in a program is called a bug.).
18
5) Documentation
• This is the final stage of program development.
• It consists of organizing all the material that
describes the program.
• The documentation of the program is intended to
allow another person or the programmer at a later
date, to understand the program.
• Internal documentation remarks consist of statements
in the program that are not executed, but point out the
purpose of various parts of the program.
• Documentation might also consist of a detailed
description of what the program does and how to use
the program.
19
• Other types of documentation are flowchart and
pseudo code that were used to construct the
program.
• Although documentation is listed as the last step
in the program development cycle, it should take
place as the program is being coded.
• It is sometimes the first step during program
execution because the programmer can use
another program documentation in developing a
new program by just improving on the previous
work.

20
1. 1 Overview of Algorithms
• What is an algorithm? Although there is no universally
agreed-on wording to describe this notion, there is a general
agreement about what the concept means:
• An algorithm is a finite sequence of unambiguous
instructions for solving a problem, i.e., for obtaining a
required output for any legitimate input in a finite amount
of time.
• As shown in the following figure, after a problem has been
identified, the problem is then carefully analyzed in order to
present a suitable algorithm.
• An algorithm is then designed and presented to the computer
in a particular programming language.
• The computer will then generate the output, based on the
input. 21
Figure.1: The position of algorithms in problem solving 22
1.2 Computational Problems and Algorithms
• A computational problem is a specification of
the desired input-output relationship.
• An instance of a problem is all the inputs needed
to compute a solution to the problem.
• An algorithm is a well defined computational
procedure that transforms inputs into outputs,
achieving the desired input-output relationship.
• A correct algorithm halts with the correct output
for every input instance.
 We can then simply say that an algorithm is a
procedure for solving computational problems
23
1.3 Characteristics of Algorithms
 The following are the major considerations in the design
of algorithms
• An algorithm must have a beginning and an end
• The non ambiguity requirement for each step of an
algorithm cannot be compromised.
• The range of inputs for which an algorithm works has to
be specified carefully
• The same algorithm can be represented in several
different ways
• Several algorithms for solving the same problem may exist
• Algorithms for the same problem can be based on very
different ideas and can solve the problem with
dramatically different speeds
• It must terminate at a reasonable period of time 24
1.4 Algorithm Design and Analysis Stages
• The diagram below represents the stages in algorithm design

25
A) Problem Definition
• Conventionally, when providing solutions for any given problem,
the problem solver must fully have the understanding of the
problem, that is he/ she must think about the problem's exceptional
cases and must ask questions again and again in order to avoid
doubt(s), and fully understand the subject matter.
B) Identifying Computational Requirement(s)
• After the programmer has fully understood the problem, all he/she
needs do, is to identify the computational requirement(s) needed to
solve the problem.
C) Algorithmic Decisions (Pre-Design Decisions)
• Before a programmer designs an algorithm, he/she decides the
method to implement in solving the problem, whether its exact or
approximate, which are called exact algorithm or approximate
algorithm respectively.
• Also during this stage the programmer decides and chooses the
appropriate data structure needed to represent the inputs.
26
D) Algorithm Design
• In this phase the programmer battles with the problem of how he
or she should design an algorithm to solve the given problem.
• Also, the programmer specifies the fashion which the algorithm
will follow, either pseudo code algorithm fashion or Euclid
algorithm fashion.
E) Algorithm Evaluation
• The algorithm evaluation phase is the testing phase whereby the
programmer confirms that the algorithm yields the desired result
for the right input that is in a reasonable amount of time.
• The programmer proves the correctness of the algorithm.
F) Proving an Algorithm’s Correctness
• Since an algorithm has been specified, you have to prove its
correctness.
• That is, you have to prove that the algorithm yields a required
result for every legitimate input in a finite amount of time.
27
G) Algorithm Analysis
• In this phase, we check the efficiency of the algorithm in
terms of time and space which are termed as time
efficiency and space efficiency respectively.
H) Coding the Algorithm
• Most algorithms finally transit into computer
programs.
• The transition(coding of an algorithm) involves a
challenge and an opportunity.
• The challenge is the development of the algorithm into a
program, either incorrectly or inefficiently, while the
opportunity is that the coded algorithm eventually
becomes an automated solution to the given problem.

28
PROGRAM DESIGN TOOLS
• It has been stated earlier that an algorithm is a set of procedures
for solving a problem.
• The tools used to clearly represent an algorithm are programming
tools.
• Example- Problem: Design an algorithm to find the average of two
numbers.
• Discussion: Since an algorithm is just the solution steps for a
problem, it can be represented by ordinary English expressions.
• Solution:
1. Start
2. Get the first number
3. Get the second number
4. Add the two numbers together
5. Find average of two numbers(sum/2)
5. Show the result
6. Stop 29
A) Flowcharts
• A flowchart consists of special geometric symbols
connected by arrows.
• Within each symbol is a phrase presenting the activity at
that step.
• The shape of the symbol indicates the type of operation that
is to occur.
• For instance, the parallelogram denotes input or output.
• The arrows connecting the symbols, called flow lines, show
the progression in which the steps take place.
• Flowcharts should “flow” from the top of the page to the
bottom.
• Although the symbols used in flowcharts are standardized,
no standards exist for the amount of detail required within
each symbol. 30
• A table of the flowchart symbols adopted by the American
National Standards Institute (ANSI) follows.
• The following figure shows the flowchart for the postage
stamp problem.
• The main advantage of using a flowchart to plan a task is
that it provides a pictorial representation of the task, which
makes the logic easier to follow.
• We can clearly see every step and how each step is
connected to the next.
• The major disadvantage with flowcharts is that when a
program is very large, the flowcharts may continue for
many pages, making them difficult to follow and modify.

31
32
Figure : Table of the flowchart symbols adopted by the American National
Standards Institute (ANSI) 33
Figure 5: The flowchart for the postage stamp problem 34
B) Pseudo Codes
• A pseudo code is an abbreviated version of an actual computer code
(hence, the term pseudo code).
• The geometric symbols used in flowcharts are replaced by English-
like statements that outline the process.
• As a result, a pseudo code looks more like a computer code than a
flowchart does.
• The pseudo code allows the programmer to focus on the steps
required to solve a problem rather than on how to use the computer
language.
• When the pseudo code is completed, it can be easily translated into
the programming language you select.
• The pseudocode has several advantages. It is compact and probably
will not extend for many pages as a flowchart would.
• Also, the plan looks like the code to be written and so is preferred by
many programmers
35
• The pseudo code for the above example is
given below:

36
Test yourself
1. Draw a flow chart and write the pseudo code for the
problem to determine whether the number is Positive or
Not Positive.
2. Use two numbers (a and b). Draw a flow chart and
Write a pseudo code program to determine whether the
number is smaller or larger than each other.
3. The perimeter P and Area of a triangle whose sides have
lengths a, b and c are given by:
P=a+b+c
Area  s( s  a)(s  b)(s  c)
• Where s=(a+b+c)/2. draw a flow chart or write a
pseudo code program with input a, b, c and output P and
Area.
37
Programming Paradigms
1. Traditional (Structural or Process Oriented)
programming Paradigm

2. Object Oriented Programming Paradigm

38
A) Traditional Procedural Programming
• In traditional, procedural programming, data and
functions (subroutines, procedures) are kept separate
from the data they process.
• This has a significant effect on the way a program
handles data:
 The programmer must ensure that data are
initialized with suitable values before use and that
suitable data are passed to a function when it is
called
• If the data representation is changed, e.g. if a record
is extended, the corresponding functions must also
be modified.
• Both of these points can lead to errors and neither
support low program maintenance requirements.
• It is suitable only for small programs or problems.
39
Major procedural programming languages are COBOL,
FORTRAN, C, AND C++.
40
Object Oriented Programming Paradigm
• Object-oriented programming shifts the focus of attention
to the objects, that is, to the aspects on which the problem
is centered.
• A program designed to maintain bank accounts would
work with data such as balances, credit limits, transfers,
interest calculations, and so on.
• An object representing an account in a program will have
properties and capacities that are important for account
management.
• OOP objects combine data (properties) and functions
(capacities).
• A class defines a certain object type by defining both the
properties and the capacities of the objects of that type.
• Objects communicate by sending each other “messages,”
which in turn activate another object’s capacities.
41
Major object-oriented languages
are C++, Java etc.
42
Advantages of OOP
 Object-oriented programming offers several major
advantages to software development:
■ Reduced susceptibility to errors: an object controls
access to its own data.
• More specifically, an object can reject erroneous
access attempts
■ Easy re-use: objects maintain themselves and can
therefore be used as building blocks for other
programs
■ Low maintenance requirement: an object type can
modify its own internal data representation without
requiring changes to the application.
It supports encapsulation, inheritance and
polymorphism.
It is suitable for large and complex problem
43

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy