Lecture Note 1. Introduction To Computer and Programming
Lecture Note 1. Introduction To Computer and Programming
Computer Programming
Lecture Note
Hj. Hazli Bin Roslan
Sem 2, sesi 20172018, FTK
1
Chapter 1 Introduction to computer
and programming
No. Title Page
1. Electronic computer 3
2. Introduction to programming 13
3. Program development cycle 25
4. Algorithm design 32
2
1. Electronic Computer
3
What is the computer?
• Computer is a machine that manipulates data
based on a list of instructions call program Computer
• Examples:
tiny computers, SBCs, PCs, Super computers
4
Electronic Computer
5
COMPUTER HARDWARE
• COMPUTER HARDWARE is a physical
part of a computer.
• Examples of computers :
tiny computer
single board computer
PCs
Workstations
super computers.
• Typical Computer hardware consist
Central processing unit (CPU)
Control unit (CU)
Arithmetic and Logic unit (ALU)
Main memory and external memory
Input devices
Output devices
6
COMPUTER HARDWARE
3 4
1
7
1. CPU
8
2. Memory
Main Memory/Primary memory
• Used to install both program and data
• 2 principles of main memory;
RAM (Random access memory)
Can be read/write anytime
Erased when no power
ROM (read-only memory)
Preloaded with program and data that never change
Typically used to stored computer initial start-up
In computer, ROM
9
2. Memory
External Memory
• Called secondary memory
• Used to store program or data permanently
• Cheaper than main memory and can store more information
• Examples:
HDD, USB drives, floppy disk and tape drives
10
3 & 4 . I/O Devices
Input and Output Devices
means for a computer to communicates with an
outside world
11
3 & 4 . I/O Devices
12
2. Introduction to Programming
13
Human vs machines
14
INTRODUCTION TO PROGRAMMING
• What distinguishes a computer from other machines is
its programmability
• Computer software is a general term used to describe
a collection of computer program that can be loaded
into main memory and executed in the CPU of a
computer.
• Software system is essential part of computer
simplest way divide two categories:
OS
application software
Alternatively, divide into
system software
application software 15
Interaction of users and computer
hardware through software
system 16
OPERATING SYSTEM (OS)
17
OPERATING SYSTEM (OS)
• OS is Software program that responsible for management and coordination
of activities and sharing of computer resources
• An interface between hardware and user
• Provides easy and efficient use of system resource
• OS Evolution
Single_user batch processing: only do one task at a time
Early OSs: manage transition between job (minimize transition time
between jobs)
Multiprogramming: computer resources are shared by many jobs or
task (user still need to wait for their output)
Timesharing (access computer via terminals): computer runs a small
portion of one job then move on to service next user
• Examples of OS: MS Windows, Linux OS such Ubuntu, Solaris etc.
• In Embedded system, usually used special purpose dedicated OS where OS
and application program are combined to reduce the computer resource
requirement 18
An interface between hardware and user
OS inside PC
• Convert human language to
Human
Input digital language
• Human language
Output
• Show result/language
human can understand
19
APPLICATION SOFTWARE
APPLICATION SOFTWARE
• Refers to programs developed to assist
user completing specific task.
• Eg. Web browsers such IE can be used to
access website on internet. Word
processing such MS word for writing docs
and CAD/CAM software for design and
manufacturing and games for
entertainment.
20
PROGRAMMING SOFTWARE
PROGRAMMING SOFTWARE
• Compilers, assemblers and
interpreters allow users to
develop their application
programs.
21
COMPUTER PROGRAMMING
Computer programming can be classified into two:
a. High-level language
i. High level compiled language
ii. High level scripting language
b. Low-level language
22
a. High-level language
High-level language
a) High level language are easier to use and most software are written in
high level language.
b) High-level language is more portable and easier to use.
23
b. Low-level language
i. Machine language
• Is lowest level of language
• Called machine code
• Contains instruction and data directly executed by CPU
• Each instruction contains 0’s and 1’s.
24
3. Program development cycle
25
PROGRAM DEVELOPMENT CYCLE
Procedure required to properly develop programming software
A. Analysis and specification of the
task(Problem definition)
C. Implementation (coding)
E. Obsolescence (usang)
26
A. PROBLEM DEFINITION
a) Analyze and specify about the problem
b) What is the input?
c) What is the output?
d) What are the process involve?
e) How is the output organized?
27
B. ALGORITHM DESIGN
• Reason: to clearly defines and understand the flows of the
program that will be design
• Defined as a step-by-step sequence of instruction that must
be terminate
• Describes how the data to be processed to produce desired
output
• Experience show that this steps will save a lot of times getting
the program to run
28
C. IMPLEMENTATION (CODING)
• Translate the Algorithm into a programming language
• This steps usually easier as gain experience with the language
• Compile the written source code
Compiler will locates errors in using the programming language
• Run the program on sample data
Verify the correctness of results
29
D. MAINTENANCE AND EVOLUTION
OF THE SYSTEM
• Usually these step are so called programmed update
where some modification of algorithm and coding
are required
• Usually, programmer update the feature in this step
• Example : window or utility update
30
E. OBSOLESCENE
31
4. Algorithm design
32
ALGORITHM
• Algorithm originally referred to any computation perform via
set of rules applied to numbers written in decimal form.
• Algorithm = step by step procedure to solve a given problem.
• An algorithm is a representation of a solution to a problem.
• Meaning that, if a problem can be define as a difference
between a desired situation and the current situation, then a
problem solution is a procedure, or method for transforming
the current situation to the desired one.
• Preparing solution to current problem will requires little
intellectual effort and usually involves in understandable
solution or procedure that others can understand.
33
Algorithm Design
• Skip problem define step as the step is
considered basic knowledge for engineering
student.
• two important steps in algorithm:
a) Pseudocode
b) Flowchart
38
Flowchart symbols (most used symbols)
40
Summary of Chapter 1
• General understanding of computer hardware and
software?
• Idea of basic programming language and levels of
language available
• Full knowledge in program, development cycle?
• Able to differentiate between pseudocode and
flowchart
• Able to solve problem using algorithm method.
41
Practice: Pseudocode/Algorithm
Nama saya Ali. Saya tinggal di Parit Raja. Saya
ada dua orang kawan namanya Lee dan Flowchart:
Muthu. Lee ada tiga batang pensil dan Muthu
ada lima batang pensil. Saya meminjam
kesemua pensil daripada Lee dan Muthu.
Kemudian saya berikan kepada adik saya
Aminah separuh daripada pensil yang saya
pinjam daripada Lee dan Muthu.
Pseudocode:
42
Practice: Pseudocode/Algorithm
Flowchart:
Nama saya Ali. Saya tinggal di Parit Raja. Saya ada
Start
dua orang kawan namanya Lee dan Muthu. Lee ada
tiga batang pensil dan Muthu ada lima batang
pensil. Saya meminjam kesemua pensil daripada Lee • Nama saya Ali
dan Muthu. Kemudian saya berikan kepada adik • Saya tinggal di Parit Raja
saya Aminah separuh daripada pensil yang saya • Ada 2 kawan Lee & Muthu
pinjam daripada Lee dan Muthu.
Input Lee = 3
Input Muthu = 5
Pseudocode:
1. Start JUMLAH = Pensil Lee + Pensil Muthu
2. Nama saya Ali
3. Saya tinggal di Parit Raja JUMLAH
4. 2 kawan Lee & Muthu
5. Input Lee = 3
AMINAH = JUMLAH / 2
6. Input Muthu = 5
7. JUMLAH = Pensil Lee + Pensil Muthu
8. Display “JUMLAH” AMINAH
9. AMINAH = JUMLAH / 2
10. Display “AMINAH” End
11. End
43
Exercise
1. Create Pseudocode and flowchart that read 2
integer number, then display total of input number
2. Create Pseudocode and flowchart that read 3
integer number, then display the average of those
numbers and maximum number
44
Exercise 1
Flowchart:
Pseudocode:
Start
End
45