Lecture 1

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 24

CSC 215

STRUCTURED PROGRAMMING
Professor Aribisala
Saturdays: 12- 2pm
Course outline
-Structured programming elements
-Structured Design principles,
-abstraction, modularity, Stepwise refinement,
-structured design techniques.
-Teaching of a Structured Programming Language,
-Laboratory exercises in a Structured Programming Language.
-Basic and Visual Basic (VB) programming language.
Course Rules
• CSC 215 is a compulsory course, you cannot graduate without it
• Condition to write exam
– Register for the course
– 70% attendance
– Have Class number
• If you miss 3 or more classes, then you are advised to delete
the course because you will not be allowed to write the exam

• The course cannot and will not benefit from upgrade


• CA= 30% (Assignments, Tests and Projects)
• Exam= 70%
• Pass mark in the exam is 45%
• These rules are very similar for all courses
Learning Objectives
• Describe programming
• Describe Structured programming
• Describe the principles of structured programming
• Benefits or advantages of structured programming
• Describe modularization
What is Computer Programming ?
Computer Programming is the act of developing and
implementing various sets of instructions to enable a computer to
perform a certain task.

Computer programs are sets of instructions used by the computer


for performing a certain task.

A programming language is a language that humans used for


communicating with the computer so that it can perform a certain
task.
Imperative Programming
Imperative programming languages are programming languages
where the entire program is a single algorithm

Used before 1960s, e.g. FORTRAN


1. programs were written to be long and complex
a. Difficult to understand
b. Difficult to debug, find and fix errors

2. GOTO statement was used


a. Caused conflicts and confusion in programs

For example. Write a computer program to process admission into


Biochemistry department, LASU
Imperative Programming
Answer Before 1960s
Example Get credit in English O/L
Get credit in Mathematics O/L
Get credit in Chemistry O/L
Get credit in Biology O/L
Get credit in any other science
Attempt English in UTME
Attempt Chemistry in UTME
Attempt Biology in UTME
Score more than 200 in UTME
Score more than 50 in post-UTME
Structured Programming
Structured programming is any programming when functionality is divided into
units like blocks or subroutines. It supports modularization

Modular programming means a program is created from re-usable units of


programs or subprograms or modules

Structured programming, is a programming paradigm aimed at improving the:


1. Clarity
2. quality, and
3. development time

of a computer program by making extensive use of


1. subroutines,
2. block structures and
3. for and while loops—in contrast to using simple tests and jumps such as the
goto statement which could lead to "spaghetti code" which is difficult both to
follow and to maintain.
Structured Programming
Answer After 1960s
Satisfy O/L requirement
Satisfy UTME requirement
Satisfy post-UTME requirement

O/L requirement
Get credit in English, Maths, Chem., Biol. and one other science
Score more than 200 in UTME

UTME requirement
Attempt English, Chemistry, Biology

Post-UME requirement
Score more than 50 in post-UTME
Principles of Structured Programming
Elements of a structured program

1. Control structures
2. Subroutines
3. Blocks
Control Structure
1. Sequencing, which has to do with the logical sequence provided by the
statements in the program. As they are executed, each step in the sequence
must logically progress to the next without producing any undesirable
effects.

2. Selection. This step allows the selection of any number of statements to


execute in the program. These statements will contain certain keywords that
can identify the sequence as a logically ordered executable. These terms are
“if," “then," “endif," or “switch."

3. Repetition. As a program proceeds, a selected statement continues to be


active until the program gets to the point where some other action needs to
take place. The keywords include "repeat," “for," or “do…until." The
repetition factor dictates instructions to the program about how long to
continue the operation before requesting further instructions.
Subroutines
Subroutines. These are callable units such as procedures,
functions, methods, or subprograms are used to allow a sequence
to be referred to by a single statement.

For example
Satisfy_OL_requirement
Satisfy_UTME_requirement
Satisfy_post_UTME_requirement
Block Structure
Blocks are used to enable groups of statements to be treated as if
they were one statement.
If (cgpa > 4.5)
Print(“First Class Student”)
Block-structured languages Print(“Will get a job in the best industry”)
have a syntax for enclosing Print(“Will be a successful person’’)
structures in some formal way Endif

If (cgpa < 1.5)


Examples Print(“Pass degree”)
If …. Endif VB Print(“Will find it difficult to get a job”)
BEGIN..END, BASIC Print(“Degree is not recognized anywhere”)
{ … } Curly bracket in C/C++ endif
Complexity problem in programming
What are the problems of programing solved by
structured programming?

Structured programming addresses the complexity of


programing language, since a complex program is
difficult to understand. It aimed at improving the clarity,
quality, and development time of a computer
program by making extensive use of subroutines, block
structures and for and while loops—in contrast to using
simple tests and jumps such as the goto statement
which is difficult both to follow and to maintain.
How does SP solve Complexity problem?
Structured programming solve Complexity problem in 3 ways
a. Top Down Analysis
b. Modularisation
c. Structured code
Top Down Analysis
1. Top down analysis is an act of breaking a big task into smaller tasks.
Programming is an act of telling the computer to do something or to solve a
problem. Before you can tell the computer to solve a problem, you have to
understand how to solve the problem and develop algorithm for solving the
problem. Sometimes, problems are complicated and you might need to break
them into smaller tasks.

2. Modularization
Modularization is an act of breaking programs into modules, subroutines or
subprograms. Each module has a specific job and it is easy to write. Hence,
modular programming simplifies programming. Modularization is very related
to top down analysis because smaller problems are written as subprograms or
modules.
How does SP solve Complexity problem?
3. Structured Coding

If programs are broken into modules, what are


modules broken into? The answer is set of
instructions. Structured coding involves the
arrangement of the instructions into definable
structures or controlled structures. Such grouping
makes execution easy.
More on Structured programming
Advantages of Structured programming
1. Structured programming increases productivity by allowing multiple
programmers to work on different parts of the project independently at the
same time.
2. Modules can be re-used many times, thus it saves time, reduces complexity,
and increases reliability.
3. Easier to update/fix the program by replacing individual modules rather
than larger amounts of code.
4. Ability to either eliminate or at least reduce the necessity of employing
GOTO statement.
5. Programs are more easily and more quickly written, that is, the logic of a
well-organized, modular program is much easier to follow.
6. Programs are more reliable. Fewer logical and organizational errors occur in
the initial stages of program development and writing.
7. Programs are easier to maintain.
More on Structured programming
Disadvantages of Structured programming
1. Lack of encapsulation: The encapsulation concept is lacked in structured
programming which means that programs will be longer. The same or
similar code will appear in more than one location; this means that the
programs will have a greater chance of errors. The testing will be lengthy
as well since every piece of code will have to be tested.

2. It is difficult to effectively locate and fix errors in the program.

3. Due to lack of information hiding, sometimes there is a conflict of variables


when different parts of the program overwrite the same variable.
Project Grouping
• Project 1: Develop an application that calculates
wages
• Project 2: GPA for a 200 level student
• Project 3: Calculate account balance
• Project 4: solve quadratic equation
• Project 5: Diagnose malaria
• Project 6: Determine if a student is on good
standing
• Project 7: Generate an invoice, bought 10 items
Project Grouping
• Project 8: Determine admission status for a
student who applied to study LAW
• Project 9: Determine admission status for a
student who applied to study Zoology
• Project 10: Determine admission status for a
student who applied to study Computer
Science
• Project 11: Determine if someone is obese or
not
• Project 12: Develop an application to convert
Celsius degree to Fahrenheit.
Getting Started
• As Visual Basic 2013 is a GUI-based programming language,
• the first step in developing an application is to build a
graphical user interface.
• To build a graphical user interface, you need to add controls
from the toolbox to the form and then customize their
properties. Note that the default form is also a control by
itself and you can change its properties first before adding
additional controls. After adding controls to the form, you
then need to write code for all the controls so that they can
respond to events triggered by the user’s actions such as
clicking the mouse. Therefore, Visual Basic 2013 is also an
event-driven programming language. We will learn more
about the concept of event-driven programming and
coding in later lessons.
Project Grouping
• 2.1 Changing the Properties of the Default-
Form using the Properties Window
• When you start a new Visual Basic 2013
project, the IDE will display the default form
along with the Solution Explorer window and
the Properties window for the form as shown
in Figure 2.1
Project Grouping
• 2.2 Changing the Properties of the Default-
Form at Run-Time
• You can also change the properties of the form
at run-time by writing the relevant codes. The
default form is an object and an instant of the
form can be denoted by the name Me. The
property of the object can be defined by
specifying the object’s name followed by a dot
or period:
• ObjectName.property

You might also like