You are on page 1of 45

BNR 20803

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

• Computer consists of hardware and software

• Device capable of performing computations and


making logical decisions

• Computers process data under the control of


sets of instructions called computer program Super computer

• Its physical part of the computer

• Examples:
 tiny computers, SBCs, PCs, Super computers

4
Electronic Computer

Totalled 9 billion of microprocessor manufactured for computers, only 2% used


for PC’s, the remaining 8.8 billion is for Embedded system

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

Input Devices Output Devices

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.

i. High level compiled language


 Is readable English like language
 Easier to read and write and can be understand by normal user
 Examples; C, C++ programs
 Compiler language

ii. High level scripting language


 Scripting language can also be called interpreted language
 Examples: matlab, mathematica
 The use of code similar to C/C++

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.

ii. Assembly language


• Use more meaningful language that machine code
• Higher level than machine language
• Example of code “add”

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)

B. Design of the software (object


and algorithm design)

C. Implementation (coding)

D. Maintenance and evolution of the


system

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

• As the written program become ages, it becomes


practically unusable or unsustainable to revise it,
both economically and practical ability.

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

• important! ability to do conversion between


both steps.
34
Pseudocode
What is pseudocode?

• One of the tools that can be used to write a


preliminary plan that can be developed into
computer program.
• Pseudocode is a generic way of describing an
algorithm without use of any specific programming
language syntax.
• As its name, it cannot be executed on real computer,
but it models and resembles real programming code,
and written at roughly the same level of detail.
35
Why use pseudocode?

• In algorithm design, the steps of the algorithm are


written in free English text and although brevity is
desired, they may be as long as needed to describe
the particular operation.
• The steps of an algorithm are said to be written in
pseudocode
• So, many languages such Pascal, have syntax that is
almost identical to pseudocode and hence make the
transition from design to coding extremely easy.
36
Pseudocode form
• Step number is optional
• Sub-procedure is indented to show it
is under one of the main procedure
• Use understandable language

Pseudocode general rules!


• Should present step-by-step solution
that can be understand by other
people.
• Sub-process should be indent from
the main procedure/ solution.
• Can include step numbers in the
pseudo code to shows the number of
main procedure taken in the solution 37
Flowchart
WHAT IS FLOWCHART?

• It is a tool developed in the computer industry, for


showing the steps involved in a process.
• A flowchart is a diagram made up of boxes,
diamonds and other shapes, connected by arrows.
• Each shape represents a step in the process and the
arrows show the order in which they occur.
• In simple words, flowchart is the steps involves to
solve the problem

38
Flowchart symbols (most used symbols)

1. Start/End (1) terminal symbol indicates


the starting or ending of the program,
process or interrupt program
2. Process box (2) in rectangular shape
indicates any type of internal operation
inside the processor or memory
3. Input / Output (3) box used for any input
or output operation. Its indicates that
the computer is to obtain data or output
results.
4. Decision box (4) use to ask a question
that can be answered in a binary format
(Yes/No, True/False)
39
General rules of flowchart

• Flowchart should have start/begin and end.


• Every shapes represent specific and must be label
accordingly.
• Every shape should be connected using arrows and
should have in and out except for start and end.

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

Start Read a & b


Read a , b
Total = a + b Total = a + b
Display Total
End
Display Total

End

45

You might also like