CSC111
Introduction to Computer Science
Course Instructors:
Prof. B. S. Aribisala
Dr. U. C. Ogude
Department of Computer Science
Lagos State of University
Introduction to
Programming
.
Programs
A program is a set of step-
by-step instructions that
directs the computer to
do the tasks you want it to
do and produce the
results you want.
Programming Languages
A programming
language is a set of
rules that provides a
way of telling a
computer what
operations to perform.
What Can a Program Do?
A program can only instruct a computer to:
• Read Input
• Sequence
• Calculate
• Store data
• Compare and branch
• Iterate or Loop
• Write Output
Calculate
A program can
instruct a computer Add 1 to
to perform Counter
mathematical
operations.
Store
A program will often
instruct a computer to Place 1
store intermediate in
results.
Counter
Compare and Branch
A program can instruct a computer to compare
two items and do something based on a match
or mismatch which, in turn, redirect the
sequence of programming instructions.
• There are two forms:
• IF-THEN
• IF-THEN-ELSE
IF-THEN
Entry
Test false true
condition p
Exit
True
statement a
IF-THEN-ELSE
Entry
Test
condition p false true
“false” “true”
statement a Exit statement a
Iterate
A program loop is a
form of iteration. A
computer can be
instructed to repeat
instructions under
certain conditions.
No
Programs are Solutions
to Problems
Programmers arrive at these solutions by
using one or more of these devices:
Logic flowcharts
Structure charts
Pseudocode
Structured Programming
Logic Flowcharts
These represent the
flow of logic in a
program and help
programmers “see”
program design.
Common Flowchart Symbols
Common Flowchart Symbols
Terminator. Shows the starting and ending points of the
program. A terminator has flowlines in only one direction,
either in (a stop node) or out (a start node).
Data Input or Output. Allows the user to inputdata and results
to be displayed.
Processing. Indicates an operation performed by the computer,
such as a variable
assignment or mathematical operation.
Decision. The diamond indicates a decision structure. A
diamond always has two
flowlines out. One flowlineout is labeled the “yes” branch and
the other is labeled the
“no” branch.
Predefined Process. One statement denotes a group of
previously defined statements.
For instance, “Calculate m!” indicates that the program executes
the necessary commands
to compute m factorial.
Flowchart for a
Cash Register Program
Start
sum=0
Input price
sum=sum+price
Yes More
items?
No
tax=sum x 0.0725
total=sum+tax
Output sum, tax,
and total
Stop
Psuedocode
This device is not visual but is considered a
“first draft” of the actual program.
Pseudocode is written in the programmer’s
native language and concentrates on the logic
in a program—not the syntax of a
programming language.
Pseudocode for a
Cash Register Program
sum=0
While More items do
Input price
sum=sum+price
End While
tax=sum x 0.0725
total=sum+tax
Output sum, tax, total
The Program Development Cycle
WRITE THE CODE
TEST AND DEBUG THE
PROGRAM
COMPLETE THE
DOCUMENTATION