0% found this document useful (0 votes)
2 views

Introduction to Structured Programming 8th Feb

The document provides an overview of structured programming and algorithms, detailing key terminologies, levels of programming languages, and their characteristics. It explains the differences between low-level and high-level languages, as well as the stages of program development from problem recognition to implementation and maintenance. Additionally, it covers pseudocodes, algorithms, and examples of C output functions.

Uploaded by

goferom840
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Introduction to Structured Programming 8th Feb

The document provides an overview of structured programming and algorithms, detailing key terminologies, levels of programming languages, and their characteristics. It explains the differences between low-level and high-level languages, as well as the stages of program development from problem recognition to implementation and maintenance. Additionally, it covers pseudocodes, algorithms, and examples of C output functions.

Uploaded by

goferom840
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 51

STRUCTURED PROGRAMMING &

ALGORITHMS
Terminologies
1. Programming – the process of
creating a list of instructions that
computer will use to do a certain
task.
2. Programming language – set of
special symbols/characters that can
be translated into machine readable
form [used to create programs]
3. Source program – a code of
program that has not been
translated into machine readable
form.
4. Object code – a program code that
has been translated into machine
readable form.
5. Language translator – language
processors/utility programs that
convert source code to object code.
6. Assembler – translator that
converts assembly language into
machine code
7. Interpreter - translates high level source code line-
by-line.
8. Compiler – translates the entire high level source
code to object code
Differences between interpreters &
Interpreter Compiler
compilers
•Translates one •Translates entire
statement at a time source code at once
•Takes less memory •Require more memory
•Translates each time it •Object code can be
is run stored & run as required
•Slower than compiling •Faster than translating
LEVELS OF PROGRAMMING
LANGUAGES

There are 2 major categories:

1. Low-level languages

2. High-level languages
LOW-LEVEL LANGUAGES
There are 2 types of low-level language:

A] MACHINE [1ST GENERATION] LANGUAGE


Instructions are written in binary form[1’s & 0’s]
containing opcode and operand

Advantages
• No need for translation
• Execution of instructions is fast
• Economise on memory
• Can be used to develop secret codes
Disadvantages:
• Not portable – machine dependent

• Difficult to learn/use: thus require


highly trained programmers to
develop/ maintain
• Difficult to debug
B] ASSEMBLY [2ND GENERATION] LANGUAGE
• Was developed in the early 1950’s and used
English-like acronyms called mnemonics e.g.
move, sub, add, load etc.

Advantages
• Easier to understand than machine code
• Faster to debug
• The program codes are shorter than machine
code

Disadvantages
• Machine dependent
• Needs a lot of training to understand
• Needs translation: therefore slower to execute
HIGH-LEVEL LANGUAGES
•They use a language very close to
human language.
•They are therefore very user friendly
•Are machine-independent & include:

1.Third generation languages


2.Fourth generation languages
3.Fifth generation languages
4.Object oriented languages [OOPs]
5.Web scripting languages
submission)
• In tabular form, draw five
differences between high level
and low level languages
• Explain four characteristics of a
good flowchart
• Describe five characteristics of a
good algorithm
THIRD GENERATION /STRUCTURED/ PROCEDURAL
LANGUAGES

• They allow a program to be broken into parts called


modules, each of which performs a certain task.
• They engage program control structures in
program development which dictate the logic of a
program.
• Examples include:

(i) Pascal – an academic language for teaching


structured programming

(ii) FORTRAN [FORmula TRANslator] – for coding


(iii) COBOL - [Common Business Oriented Language]

For developing business/commercial applications

(iv) BASIC – [Beginners All-purpose Symbolic Instructional


Code]

It was used for developing business & educational


applications. Used to teach programming

(v) C – used to develop system software that permits


direct control over the hardware e.g. operating
systems
(v) Ada – for developing military, industrial & real- time
systems

(vi) LOGO – for educational use


FOURTH GENERATION LANGUAGES [4GLs]
• They present a programmer with
more programming tools e.g.
command buttons & forms.
• Allow programmers to select
graphical objects called controls to
create designs on a base form.
• They also free programmer from
writing codes since they have
application generators that
generates the codes.
• Examples: Visual Basic, Delphi
Pascal, Visual COBOL
FIFTH GENERATION LANGUAGES
• Used to design artificial intelligence
applications
• Enables a computer to depict human like
intelligence.
• Programmer worries only about what problem
needs to be solved & what conditions need
to be met without worrying about developing
algorithms to solve them.
• Examples: PROLOG, Mercury, LISP & OCCAM.
OBJECT ORIENTED PROGRAMMING LANGUAGES
[OOPs]
• Allows a program to be perceived as having various
objects interacting to make a whole program
• Each object has specific data values unique to it [state]

• Each object has set of things it can accomplish


[functions/behaviour]
• The process of data & the functions that operate on the
data within an object’s called encapsulation.
• Examples: Simula, C++, Java & SmallTalk.

• Enables creation of GUI OSs & applications


WEB SCRIPTING LANGUAGES
• Used to develop and add functionalities on web
pages
• The most commonly used languages are
Hypertext Markup Language [HTML], PHP, CSS,
XML, JAVASCRIPT…
• HTML has limitations & is not used alone when
developing functional websites.
PROGRAM DEVELOPMENT
Program development task is broken
into the following stages:
• Problem recognition
• Problem definition
• Program design
• Program coding
• Program testing and debugging
• Program implementation and
maintenance
STEP 1: PROBLEM RECOGNITION

• It involves taking note of a problem that requires

programming attention. Here a problem is identified

to exist and programmer seeks to

understand/interpret it. This can come to a

programmer’s notice through various ways like:


• New marketing opportunity

• Changes in government regulations

• Introduction of new technology

• Obsolescence/ineffectiveness of the current

system
• STEP 2: PROBLEM DEFINITION

• Specify objectives/users

• Specify desired output – output devices & formats

• Specify desired input – input devices & formats

• Specify desired processing – type of computers, OS,


type of processing, need for network.
• Study the feasibility of implementing the program
[economic, legal, operational, technical, schedule]
• Document the analysis
STEP 3: PROGRAM DESIGN
• Determine program logic using top down design:
modularisation – can use structure chart showing
inputs, processing & outputs
• Use program design tools to represent the logic:
[pseudocodes & flowcharts]
• Structured walkthrough
STEP 4: PROGRAM CODING
Choose programming language

Follow syntax
STEP 5: PROGRAM TESTING & DEBUGGING

Involves detection, location & correction of errors

Two types of errors:


Syntax errors – result from improper use of
programming language. Can be detected by translators.
A program with syntax errors cant execute
Logical errors – result from improper use of control
structures or functions. Cant be detected by translators.
A program with them will execute but abort prematurely
or give wrong results
Methods of error detection

(i)Desk checking/ dry running – involves picking errors


on the program while still on paper before transcription.

(ii)Using debugging utilities – running translators


helps detect/locate syntax errors

(iii)Test data – used to do trial runs. Normal, extreme


and exceptional data should be used.
STEP 6: IMPLEMENTATION & MAINTENANCE
/REVIEW

Implementation – delivery and installation of the


program for use

It also involves user training and file conversion

There are four ways of converting to the new system:


Parallel

Direct

Phased

Pilot
Review & maintenance – post

implementation support to make sure the

program is error free, updated and used

correctly.
PROGRAM DOCUMENTATION

Writing support materials that explain how the


program can be installed by operators, used by
users or modified by programmers.

There are 3 types of documentation:

1.User oriented – gives procedures for use of the


program

2.Operator oriented – helps install and maintain


the program

3.Programmer oriented – provides technical


information to allow modification of the program
PSEUDOCODES
Are English-like statements describing the
logic/ processing flow of a program

Rules
1.Single start and stop points
2.Unambiguous statements
3.Input, processing & output operations
must be clearly depicted using keywords
4.Clearly outlined/ indented
5.Short and clear statements
ALGORITHMS
• Set of logical and finite steps that solve a specific
problem

Characteristics
1.Finiteness
2.Logically related statements
3.Clear & precise steps
4.Non-ambiguity of the statements
Delimiters – unique characters or string
that mark the start or end of a particular
statement, string or function.
C Output
•printf() is one of the main output function. The function sends formatted output to the screen. For example,

Example 1: C Output
#include <stdio.h>
int main()
{
// Displays the string inside quotations
printf(“Example of C Output");
return 0;
}

•Example 2: Integer Output


•#include <stdio.h> int main() { int testInteger = 5; printf("Number = %d", testInteger); return 0; }
•Run Code
•Output
•Number = 5We use %d format specifier to print int types. Here, the %d inside the quotations will be replaced by the value
of testInteger.
•Example 3: float and double Output
•#include <stdio.h> int main() { float number1 = 13.5; double number2 = 12.4; printf("number1 = %f\n", number1);
printf("number2 = %lf", number2); return 0; }
•Run Code
•Output
•number1 = 13.500000 number2 = 12.400000To print float, we use %f format specifier. Similarly, we use %lf to print double values.
•Example 4: Print Characters
•#include <stdio.h> int main() { char chr = 'a'; printf("character = %c", chr); return 0; }
•Run Code
•Output
•character = a
•To print char, we use %c format specifier.

Explanation
•The printf() is a library function to send
formatted output to the screen. The function
prints the string inside quotations.
•To use printf() in our program, we need to
include stdio.h header file using the #include
<stdio.h> statement.
•The return 0; statement inside
the main() function is the "Exit status" of the
program. It's optional.
Example 2: Integer Output
#include <stdio.h>
int main()
{
int Num = 5;
printf("Number = %d", Num);
return 0;
}
Output
Number = 5
• %d is used to format specifier
to print int types.
• Here, the %d inside the
quotations will be replaced by
the value of num.
Example 3: float and double Output
#include <stdio.h>
int main()
{
float num1 = 3.4;
double num2 = 5.5;

printf(“Value 1 = %f\n", num1);


printf(“Value 2 = %lf", num2);
return 0;
}
Output
Value 1 = 3.400000
Value 2 = 5.500000

•To print float, we use %f format


specifier.
•Similarly, we use %lf to
print double values.
Example 4: Print Characters
#include <stdio.h>
int main()
{
char chr = ‘Q';
printf(“Character = %c",
chr);
return 0;
Output
character = Q

You might also like