CHAPTER 1
Introduction to Computer Program
Introduction to Computer.
Basic operations in a computer system.
Computer Programs.
Generation of Programming Languages.
Language Translators.
The importance of programming.
Programming Process
Structured Programming vs. Object Oriented
Programming.
Principles of Structured Programming
Introduction to Computer
Computer = an electronic device that input, stores, processes
data (input, output, storage and processing devices) and generate the
useful information.
Basic components of a computer systems :9 Hardware
Equipment that processes data to create information includes
input, output, storage and processing devices.
9 Software
Step-by-step instructions that tell the computer how to do its
work.
It is also called a program.
Its purpose to convert data to useful information.
Basic Operations in a Computer
System
STORAGE
INPUT
Whatever data that is put
into a computer using an
input devices
E.g. Mouse, keyboard
PROCESSING
Convert input data into
information.
E.g. CPU
Store the data or information for
future use (permanently or
temporarily)
E.g. Hard disk, memory
OUTPUT
Generate the useful
information using output
devices
E.g. Monitor, printer
Computer Software
SOFTWARE
SYSTEM SOFTWARE
provides an environment for user
to execute the application software.
Enables the application software
to interact with computer
hardware.
Eg. Operating System
APPLICATION SOFTWARE
end user software.
A program that performs a
common task to the user.
Eg. Word, Excel.
Computer Programs
Program = a set of instructions that the computer needs to follow
to process the data into information.
Computer Program = a sequence of instructions that the
computer carries out to fulfill the task.
Computer Programmer = a person who writes a computer
program.
Computer Programming = the act of designing and
implementing computer programs using the programming languages.
Programming Language = provides a way to program a
computer using instructions that can be understood by computers and
human. It has its own vocabulary and rules of usage.
Generation of Programming
Languages
9
1st generation (low-level language)
z
2nd generation
z
High-level language resembles some human language (English) eg.
COBOL, FORTRAN, BASIC.
Procedural languages.
4th generation
z
Assembly language (low-level language) that allows a computer user to
write a program using simple word instead of numbers.
3rd generation
z
Machine Language is the basic language of the computer, representing
data as 1s and 0s.
Very high-level language, much more user-oriented and allow users to
develop programs with fewer commands compared with procedural
languages eg. SQL, NOMAD
5th generation
z
Natural Language uses human language to give people a more natural
connection with computers.
Language Translator
Language Translator = a program that accepts a humanreadable source statements and produces machine-readable
instructions. There are Assembler, Compiler, Interpreter.
SOURCE CODE
ASSEMBLER
a program that
translates the assembly
language program into
machine language.
a program is a plain text written
using any text editor
COMPILER
a program that translates
high-level language into
machine language.
Translate the source code
once and saves to be reused.
Requires less memory and
runs faster.
Eg. PASCAL, C++, COBOL
INTERPRETER
a program that translates
source code of high-level
language into machine
language.
Each instruction is
interpreted into machine
language.
Program is easier to develop.
Eg. BASIC.
The Importance of Programming
9
9
9
9
Easy to express tasks from a particular problem
domain.
Allow user to instruct computer to do a specific task
in a certain instances.
A skill required for a computer scientist and software
engineering.
A skill required to create a successful computer
program.
The Importance of Good Programs
Spacing
Indent
Each instruction has indention depends on its structure.
Comment
Each instruction begins with new line.
Help a human reader to understand the program.
Variable name
Use descriptive name
Rules of naming the variable :9 Other than reserved word.
9 Alphanumeric A-Z, a-z, 0-9, _ (underscore).
9 Length recommended 3 8 characters long.
Programming Process
Define
the problem
Develop an algorithm
Code the program
Test and debug the program
Document and maintain the program
Define the problem
Define what the job is, NOT HOW.
What program is to accomplish
What is the output.
What is the input.
Any formula (calculation).
Develop an Algorithm
Algorithm
a set of sequential instructions that are followed
to solve a problem.
Involves decisions to change the actions or cause
parts of algorithm to be repeated.
An algorithm can be represented by a pseudocode
or flowchart.
Pseudocode
expresses an algorithm in everyday English rather
than programming language.
Describe instructions in your own word.
Flowchart
a diagram to represent a flow of an algorithm.
Basic flowchart :Rectangle represents processing or
taking an action.
Diamond represents making a decision.
Parallelogram represents an Input and
output.
Begin and end
Code the program
Algorithm pseudocode or flowchart is converted into
program code, using the vocabulary or rules of usage of
the programming language that you are using.
Errors can be made during coding which prevent the
successful compiling and linking.
Common errors : Syntax error = caused by a typographical errors and
incorrect use of the programming language.
Logic error = an error due to incorrect order of statements,
incorrect formula others that can cause the incorrect output.
Runtime error = occurs when a program gives the computer
instructions that it is incapable of executing. Causes a program
to terminate abnormally (crash or abort).
Test and Debug the program
To provide input to make sure the result is correct or as
needed by the user.
Involves various testing stages : Alpha testing = a desk-check, read through the program to
make sure there are no syntax and logic errors.
Debug the program to detect, locate and remove all errors in
a computer program, by entering some of the input data.
Beta testing = runs the real-world data to test the program to
make sure it works correctly (variety of live data).
Document and Maintain the program
Documentation
Written description of a program, what it does and
how to use.
Purpose for reference to other programmers if any
maintenance to be taken.
Maintenance
Any activities to keep the program in good working
condition, error free and up-to-date.
Involves any amendments, additional coding or
repairs to the programs.
Structured Programming VS
Object Oriented Programming
Structured Programming
Is a disciplined approach to writing programs that are clearer than
unstructured programs, easier to test, debug and modify.
Top-down approach to writing programs that breaks programs in
modular forms and users standard logic tolls called control
structures (Sequential, Selection, Case, Iteration).
Object Oriented Programming
Is a disciplined approach to programming that results in program
that are easier to read, understand and less likely to contain
errors.
Data and instructions for processing the data are combined into
self-sufficient object that can be used in other program.
Principles of Structured Programming
Use Standard logic tools (Control structures) : Sequential = one program statement follows another in
sequence order.
Selection = represents a choice, offers two paths to follow
when decisions must be made by a program.
Case = variation on selection. More than a single yes-or-no
decision.
Iteration = process may be repeated as long as a certain
condition remains true.