DIT 1302 Introduction to
Structured programming
PROGRAMMING IN C
By Eric Araka
What is Programming
To solve a computing problem, its solution
must be specified in terms of sequence of
computational steps such that they are
effectively solved by a human agent or by a
digital computer.
What is Programming
Program – a very specific set of instructions
(or command lines) that making a
computer do what you want it to do
Programming – the process of creating a
program
◦ the development of a solution to an identified
program, and setting up of a related series of
instructions which, when directed through
computer hardware, will produce the desired
results
Steps in program
development
1. Define the problem
2. Outline the solution
3. Develop the outline into an algorithm
4. Test the algorithm for correctness
5. Code the algorithm into a specific
programming language
6. Run the program on the computer
7. Document and maintain the program
Define the Problem
Divide the problem into three components
(called IPO):
◦ Inputs – what do you have?
◦ Outputs – what do you want to have?
◦ Processing
how do you go from inputs to outputs?
A defining diagram is recommended
Outline the Solution
The major processing steps involved
The major subtasks (if any)
The major control structures (e.g.
repetition loops)
The major variables and record structures
The mainline logic
Develop the Outline into an
Algorithm
Algorithm is a set of precise steps that
describe exactly the tasks to be performed,
and the order in which they are to be
carried out
Pseudocode (a form of structured English) is
used to represent the solution algorithm
Test the Algorithm for
Correctness
The main purpose of desk checking the
algorithm is to identify major logic errors
early, so that they may be easily corrected
Test data needs to be walked through each
step in the algorithm, to check that the
instructions described in the algorithm will
actually do what they are supposed to
Code the Algorithm into a
Specific Programming Language
Only after all design considerations have
been met should you actually start to code
the program into your chosen
programming language (e.g. Visual Basic,
Java, C++)
Run the Program on the
Computer
This step uses a program compiler and
programmer-designed test data to
machine test the code for syntax errors
Program complier translate high-level
languages (e.g. VB) to low-level machine
language before execution
Document and Maintain the
Program
Not the last step in the program
development process
An ongoing task from the initial definition
of the problem to the final test result
Involves both external documentation
(such as hierarchy charts) and internal
documentation that may have been coded
in the program
Example 1: Circle
Calculate the circumference and area
IPO
◦ I: radius
◦ P: calculate circumference and area as
circumference = 2 * P I* radius
area=PI * radius ^ 2
◦ O: radius, circumference, area
Circle (Pseudocode)
Begin program
get radius, PI
circumference = 2 * P I* radius
area=PI * radius * radius
display circumference, area
End program
Programming Language
◦ The specification of the sequence of
computational steps in a particular programming
language is termed as a program
◦ The task of developing programs is called
programming
◦ The person engaged in programming activity is
called programmer
Linear Programming
Linear program is a method for
straightforward programming in a sequential
manner. This type of programming does not
involve any decision making.
◦ Read a data value
◦ Computer an intermediate result
◦ Use the intermediate result to computer the
desired answer
◦ Print the answer
◦ Stop
Structured Programming
Structured programming (sometimes known
as modular programming) is a subset of
procedural programming that enforces a
logical structure on the program being
written to make it more efficient and easier
to understand and modify.
Advantages of Structured Programming
Easy to write:
Several Programmers can work on a single, large program, each
working on a different module. Studies show structured programs take
less time to write than standard programs. Procedures written for one
program can be reused in other programs requiring the same task. A
procedure that can be used in many programs is said to be reusable.
Easy to debug:
Since each procedure is specialized to perform just one task, a
procedure can be checked individually. Older unstructured programs
consist of a sequence of instructions that are not grouped for specific
tasks. The logic of such programs is cluttered with details and
therefore difficult to follow.
Easy to Understand:
The relationship between the procedures shows the modular design of
the program. Meaningful procedure names and clear documentation
identify the task performed by each module. Meaningful variable
names help the programmer identify the purpose of each variable.
Easy to Change:
Since a correctly written structured program is self-documenting, it
can be easily understood by another programmer.
Structured Programming Constructs
It uses only three constructs -
Sequence (statements, blocks)
Selection (if, switch)
Iteration (loops like while and for)
Sequence
Any valid expression terminated by a
semicolon is a statement.
Statements may be grouped together by
surrounding them with a pair of curly
braces.
Such a group is syntactically equivalent to
one statement and can be inserted where
ever
One statement is legal.
Selection
The selection constructs allow us to follow
different paths in different situations. We
may also think of them as enabling us to
express decisions.
The main selection construct is:
if (expression)
statement1
else
statement2
Iteration
Looping is a way by which we can execute any
some set of statements more than one times
continuously .In C there are mainly three
types of loops are used :
while Loop
do while Loop
For Loop
Advantages of Control
Structures
The control structures are easy to use
because of the following reasons:
They are easy to recognize
They are simple to deal with as they have
just one entry and one exit point
They are free of the complications of any
particular programming language
Types of Programming Language
Low Level Language
Assembly Language
High Level Language
Low Level Language
First-generation language is the lowest level
computer language.
Information is conveyed to the computer by
the programmer as binary instructions.
Binary instructions are the equivalent of the
on/off signals used by computers to carry
out operations
Low Level Language
Advantages
◦ Fast and efficient
◦ Machine oriented
◦ No translation required
Disadvantages
◦ Not portable
◦ Not programmer friendly
Assembly Language
Assembly or assembler language was the
second generation of computer language.
By the late 1950s, this language had
become popular. Assembly language
consists of letters of the alphabet.
This makes programming much easier than
trying to program a series of zeros and
ones.
High Level Language
The introduction of the compiler in 1952
spurred the development of third-
generation computer languages.
These languages enable a programmer to
create program files using commands that
are similar to spoken English.
High Level Language
By 1957, the International Business Machine
Corporation (IBM) had created a language called
FORTRAN (FORmula TRANslater).
This language was designed for scientific work
involving complicated mathematical formulas. It
became the first high-level programming language (or
"source code") to be used by many computer users.
Within the next few years, refinements gave rise to
ALGOL (ALGOrithmic Language) and COBOL (COmmon
Business Oriented Language). COBOL is noteworthy
because it improved the record keeping and
data management ability of businesses, which
stimulated business expansion.
High Level Language
Advantages
◦ Portable or machine independent
◦ Programmer-friendly
Disadvantages
◦ Not as efficient as low-level languages
◦ Need to be translated
Examples : C, C++, Java, FORTRAN, Visual
Basic, and Delphi.
Fourth Generation Language
Fourth-generation languages attempt to make
communicating with computers as much like the
processes of thinking and talking to other people
as possible.
Fourth-generation languages typically consist of
English-like words and phrases.
When they are implemented on
microcomputers, some of these languages
include graphic devices such as icons and
onscreen push buttons for use during
programming and when running the resulting
application.
Fourth Generation Language
Many fourth-generation languages use
Structured Query Language (SQL) as the
basis for operations. SQL was developed at
IBM to develop information stored in
relational databases. Examples of fourth-
generation languages include PROLOG, an
Artificial Intelligence language
Interpreter
An interpreter is a computer program that
executes other programs.
This is in contrast to a compiler which does
not execute its input program (the
source code) but translates it into
executable machine code (also called
object code) which is output to a file for
later execution.
Interpreter
Interpreting code is slower than running the
compiled code because the interpreter must
analyses each statement in the program each
time it is executed and then perform the
desired action whereas the compiled code just
performs the action.
COMPILER
A program that translates source code into
object code.
The compiler derives its name from the way
it works, looking at the entire piece of
source code and collecting and reorganizing
the instructions.
Thus, a compiler differs from an interpreter,
which analyzes and executes each line of
source code in succession, without looking
at the entire program.
COMPILER
Every high-level programming language
(except strictly interpretive languages)
comes with a compiler.
In effect, the compiler is the language,
because it defines which instructions are
acceptable.
Steps in program
Development
SDLC – System Development Life Cycle in
Detail
SDLC stands for system development life
cycle. It is a methodology/process
SDLC CONTAINS THE FOLLOWING
PHASES:
Steps in program
Development
Planning - Defining the problem and prioritizing
against other programming projects
Requirement Analysis - Fact Finding problem
specifics through observation, questionnaires and
interviews.
Design - Develop problem alternatives. and models
to represent problem and solution
Development - Coding and testing of the program
Implementation - Installing the program and
training the user
Maintenance - On-going changes to the program
(maintenance)
Steps in program Development
- SDLC
OTHER PROGRAM DEVELOPMENT
PROCESS CONCERNS
The following processes and activities are not defined specifically to one
program development phase but in fact can be a part of several or all of the
PDP phases
DEPLOYMENT
Deployment concerns the techniques that will be used to deliver your
program to your users.
TRAINING/DOCUMENTATION
It is very easy to forget about training and documentation until the project is
complete. Many times training and documentation is either ignored or given
no consideration at all. You need a look this task as one of the ways to ensure
your programs success.
PROJECT MANAGEMENT
Not all programs are contained in a single file and programmed by one
programmer. Depending on the size of the application project, you may be
part of a team who is developing a new system.
Flow Chart
A flow chart is a standardized technique for
graphically representing graphics with a set
of standardized symbols that represent
program logic.
To read the sequence of logic steps in the
following flow chart, just follow the letters.
Flow Chart