Introduction
1
Electronic Data Processing Concept
2
IPO DIAGRAM
Input
Output
PROCESS
Algorithm
3
A finite set of instructions which, if followed,
accomplish a particular task.
Criteria of Algorithm
4
Input
Output
Definiteness
Finiteness
effectiveness
Digital Computer
5
A machine that is capable of storing data and
executing algorithms.
Physical components of Digital Computer
6
Central Processing Unit (CPU)
Memory
PRIMARY Memory
Read Only Memory (ROM)
Random Access Memory (RAM)
Secondary Memory
Magnetic, hard disk, CD-ROM
Input/Output devices (I/O)
Software
7
Computer programs which serves as an interface
between the user and the hardware
Categories of Software
Application
System
Computer Program
8
Like an algorithm
Components of computer program
Data
Instructions for manipulating data
Is written using a certain computer programming
language
Computer Programming Language
9
A programming describes the:
vocabulary (set of symbols and words)
Syntax (rules)
Semantics (meaning)
Note!
Used to write a valid computer program
Types of Computer Programming Languages
10
Low-Level Languages
Machine language
Assembly language
High-Level Languages
FORTRAN
ALGOL
COBOL
BASIC
PASCAL, C++ AND JAVA
LOW-LEVEL LANGUAGE
11
Require the programmers to have a good
understanding of the underlying hardware for which
the programs are intended to run
Programs written in this languages are not portable
They are not to exceed in two different and incompatible
processors
HIGH-LEVEL LANGUAGES
12
The language is quasi-English and (2) it does not
require the programmer to know the actual computer
hardware.
Programs written in high-level languages are able to
exhibit portability
Steps in Program Planning and
Development
13
What is programming?
14
a problem-solving activity.
A person with good problem solving skills will tend
to be good programmers.
Steps in program planning and development
15
1. problem analysis
2. setting up an algorithm
3. coding
4. encoding
5. running, testing, and debugging
6. documentation
Problem Analysis
16
Steps on how to go about analyzing a certain problem for
computer application:
1. Review the problem carefully and understand what you
are asked to do.
2. Determine what information is given (input) and what
result must be produced (output).
3. Assign names to each input and output item.
4. Determine the manner of processing that must be done
on the input data to come up with the desired output
(i.e., determine what formulas are needed to
manipulate the given data).
Example
17
Given the scores for the two departmental quizzes,
two machine projects, final exam, and teacher's
evaluation, write a program that will compute for the
final grade based on the following computation:
1.50% Average of 2 departmental quizzes
2.+ 15% Average of 2 machine projects
3.+ 30% Final exam
4.+ 5% Teacher's evaluation
Setting Up an Algorithm
18
After the problem has been clearly defined, a list or sequence of steps
that will solve the given problem must be formulated. This sequence of
steps is called an algorithm.
An algorithm can be described in many ways. A natural language such
as Filipino, English, or Chinese can be used but we must be very careful
that the algorithm be organized in a logical and clear manner.
Graphical forms or notations such as flowcharts can be used, an
improvement of the former, but is more sophisticated. It is important
to note that in whatsoever manner an algorithm is written, it remains to
be NOT executable simply because it cannot be entirely understood by
the computer.
To cite an example, let us use the final grade problem. A possible
algorithm written in English that will solve the problem would be:
19
1. Get Qz1 and Qz2 scores.
2. Get Mp1 and Mp2 scores.
3. Get FE score.
4. Get TE score.
5. Calculate Qz1+Qz2
Mp1+Mp2
6. FG = 50% x Q--+ 15% x MP+ 30% x FE + 5% x TE
7. Display the final grade FG.
20
An algorithm may also be viewed as a recipe.
The manner in which the series of steps in a recipe is
written is similar to creating an algorithm.
But, it should be noted that an algorithm is more than a
recipe.
An algorithm has to be exact.
An example statement in a recipe would be “add salt to
taste”.
In an algorithm, this is not acceptable because the
statement is subjective and not quantifiable. Everything
should be definite.
Coding
21
to convert this into a list of instructions in a code or
language that the computer can understand and
execute.
Example Algorithm
22
Program Get FE score.
main() cin>>fFE;
{ Get TE score.
double fQ1, fQ2; cin>>fTE;
double fMP1, fMP2;
double fFE, fTE, fFG;
fFG = 0.50 * ((fQ1 + Calculate FG.
Get Qz1 and Qz2 scores. fQ2)/2) + 0.15 * ((fMP1 + fMP2)/2) +0.3 *
cin>> fQ1; fFE + 0.05 * fTE;
cin>> fQ2;
Display the final grade
Get Mp1 and Mp2 scores. Cout<< "FG = “ << fFG;
cin>>fMP1;
cin>>fMP2; }
Encoding
23
The process of entering the program through a
computer terminal directly into computer memory.
24
The list of instructions that will implement the
algorithm can be understood by the computer simply
because "it is written in the vocabulary of the
programming language and conforms to the
grammatical rules of the language.“
This list of instructions understood by the computer is
now called a program.
In the example, we converted our algorithm for
computing the final grade to a C program.
The cin statements ask for input from the user while
the cout statement displays the output.
25
Errors that come out during program execution are
termed as bugs.
Computer programmers use terms as bug-ridden
and buggy to describe a program which is poorly
written thus containing a lot of errors.
The art of correcting these errors is called
debugging.
Running, Testing, and Debugging
26
The fifth step in program development would be to execute or
run the program.
The program is executed or run on different input data.
Testing is the art of creating different sets of sample data
upon which the program will be run.
The programmer must submit the program to as many
combinations of test data as possible to anticipate and correct
any error that might come out before releasing the program to
users.
The process of executing a program with test input data and
checking the output results against the requirements is
referred to as desk checking
Classification of BUGS and ERRORS
27
1. Syntactical or logical errors
2. Compile or run-time errors
Logical Errors
28
are hard to identify.
What is erroneous here are the outputs seen
onscreen which did not conform to or match the
expected results.
Such errors arise during the formulation of
algorithm or in the coding of the program that
implements the algorithm due to the wrong analysis
or perhaps wrong approach of the programmer as he
tackles the problem given.
Syntactical Errors
29
Are result from failure to an old story about a group
of follow the syntax of the language.
Syntax refers programmers who couldn't to the
grammatical rules of the language figure out what
was wrong with defining its legal constructs.
Examples of which their programs, until they are
unrecognized instructions, missing opened up the
computer and punctuation marks and misspelled
names.
Run-Time Errors
30
Errors that appear during program execution
Once a program starts running, it means that the
program is already free of syntax errors and
compilation has successfully finished.
However, it may still have logical errors that may
cause the abnormal termination of the program.
Compile-Time Errors
31
halt the compilation of the program.
Compilation means translating the program codes
into a form that the physical computing machine can
understand.
Program codes are translated completely so long as
their syntax is correct.
Once a syntax error is encountered during
compilation, this is considered to be a compile-time
error.
Example of Run-Time Errors
32
1. dividing a certain number by zero.
2. program executing in an endless loop wherein the
only way to stop it is to manually stop the execution
of the program.
Introduction to Programming in C++
Seventh Edition
Chapter 1:
An Introduction to Programming
Chapter Objectives
34
Define the terminology used in programming
Explain the tasks performed by a programmer
Understand the employment opportunities for
programmers and software engineers
Explain the history of programming languages
Explain the sequence, selection, and repetition
structures
Write simple algorithms using the sequence,
selection, and repetition structures
Programming a Computer
35
It is important to understand the relationship
between the terms programs, programmers, and
programming languages.
Programs - The directions that humans give to
computers
Programmers - The people who create these
directions
Programming Languages - Special languages
used by programmers to communicate directions to a
computer
The Programmer’s Job
36
Programmers help solve computer problems
Employee or freelance
Typical steps involved
1. Meet with user to determine problem
2. Convert the problem into a program
3. Test the program
4. Provide user manual
What Traits Should a Software Developer Possess?
1. Analytical skills
2. Communication skills
3. Creativity
4. Customer-service skills
5. Detail oriented
6. Problem-solving skills
7. Teamwork
8. Technical skills
37
Employment Opportunities
38
Computer software engineer: designs an appropriate
solution to a user’s problem
Computer programmer: codes a computer solution
Coding is the process of translating a computer
solution into a language a computer can understand
Some positions call for both engineering and
programming
A Brief History of Programming Languages
39
There are many different types of programming
languages. This chapter will discuss:
Machine languages
Assembly languages
High-level procedure-oriented languages
High-level object-oriented languages
Machine Languages
40
The first programmers had to write the program
instructions using only combinations of 0s and 1s
Example: 0000 0101 1100 0000
Instructions written in 0s and 1s are called machine
language or machine code
Each type of machine has its own language
Machine languages are the only way to communicate
directly with the computer
Programming in machine language: tedious and
error-prone; requires highly trained programmers
Assembly Languages
41
Assembly languages made writing code simpler
than using only 0s and 1s
Mnemonics – symbols used to represent the actual
machine language instructions
Example: 00000101 vs. BALR
Assembly programs require an assembler to
convert instructions into machine code
Easier to write programs in assembly language
But still tedious and requires highly trained programmers
High-Level Languages
42
High-level languages allow programmers to use
English-like instructions
Example: taxAmount = total * taxRate
Each high-level language instruction is equivalent
to more than one machine language instruction
Compilers translate high-level instructions into
0s and 1s (machine language)
Interpreters translate the program line by line
as the program is running
High-Level Languages (cont.)
43
When writing a procedure-oriented
program, the programmer concentrates on the
major tasks that the program needs to perform
Examples: COBOL, BASIC, C
An object-oriented program requires the
programmer to focus on the objects that the
program can use to accomplish its goal
Examples: C++, Visual Basic, Java, C#
Object-oriented programs allow for an object to
be created that can be reused in more than one
program
Control Structures
44
All computer programs are written using one or more
of three basic control structures:
Sequence
Repetition
selection.
Another term used for control structures are logic
structures, because they control the logic flow of the
program.
While in every program that is written the sequence
structure will be used, in most all programs all three
control structures will be used.
The Sequence Structure
45
The sequence structure directs the computer to
process the program instructions, one after another,
in the order in which they are listed in the program
An algorithm is a finite number of step-by-step
instructions that accomplish a task
Example: steps to pump gas at a self-service pump
The Sequence Structure (cont.)
46
Figure 1-1 An example of the sequence structure
The Selection Structure
47
The selection structure directs the computer to
make a decision (evaluate a condition), and then take
an appropriate action based upon that decision
The selection structure allows the programmer to
evaluate data, therefore properly controlling the logic
flow of the program
Another name for the selection structure is the
decision structure
Example: stopping or going at a signal light
The Selection Structure (cont.)
48
Figure 1-2 An example of the selection structure
The Selection Structure
49
(cont.)
Figure 1-3 Another example of the selection structure
The Repetition Structure
50
The repetition structure, commonly called
iteration or looping, directs the computer to
repeat one or more program instructions until some
condition is met
This condition may be checked at the beginning or
end of the set of instructions to be processed
dependent upon the language being used
The repetition structure allows the programmer to
repeatedly process a set of instructions, while only
typing them in once
The Repetition Structure (cont.)
51
Figure 1-4 Original algorithm and modified
algorithm showing the repetition structure
The Repetition Structure (cont.)
52
What could you do if you do not know precisely how
many steps separate Harold from the boxes?
The Repetition Structure (cont.)
53
Figure 1-5 Algorithm showing the modified
condition in the repetition structure
Summary
54
Programs are step-by-step instructions that tell a
computer how to perform a task
Programmers use programming languages to
communicate with the computer
First programming languages were machine
language using 0s and 1s
Assembly languages followed, using mnemonics
High-level languages can be used to created
procedure-oriented or object-oriented programs
Summary (cont.)
55
An algorithm is a finite number of step-by-step
instructions that accomplish a task
Algorithms utilize three basic control structures:
sequence, selection, and repetition
The sequence structure directs the computer to
process the program instructions, one after another,
in the order in which they are listed
The selection structure directs the computer to make
a decision (evaluate a condition), and then take an
appropriate action based upon that decision
Summary (cont.)
56
The repetition structure, commonly called iteration
or looping, directs the computer to repeat one or
more program instructions until some condition is
met
The sequence structure is used in all programs
Most programs also contain both the selection and
repetition structures
Seatwork #1 - Algorithm
57
A local business employs five salespeople and pays a
3% bonus on a salesperson’s sales
Your task is to create an algorithm for the program
that calculates the amount of each salesperson’s
bonus
The program should print each salesperson’s name
and bonus amount