Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |...

Post on 23-Dec-2015

242 views 0 download

Tags:

Transcript of Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |...

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 1

Introduction To Computers

Lecture 1

byJumail Bin Taliba

Faculty of Computer Science & Information System

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 2

Today’s Topics

•Computer Systems•Computing Environments•Computer Languages•System Development

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 3

Figure 1-1: A computer system

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 4

Figure 1-2: Basic hardware components

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 5

Computer Hardwares– Five main components

• Input devices– Allows communication to the computer

• Output devices– Allows communication to the user

• Processor (CPU)

• Main memory (primary storage)– Memory locations containing the running program

• Secondary memory (auxiliary storage)– Permanent record of data often on a disk

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 6

Computer Memory

• Main Memory– Long list of memory locations

• Each contains zeros and ones• Can change during program execution

– Binary Digit or Bit• A digit that can only be zero or one

– Byte• Each memory location has eight bits

– Address • Number that identifies a memory location

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 7

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 8

Larger Data Items

• Some data is too large for a single byte– Most integers and real numbers are too large

– Address refers to the first byte

– Next few consecutive bytes can store the additionalbits for larger data

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 9

Data or Code?

• ‘A’ may look like 01000001• 65 may look like 01000001• An instruction may look like 01000001

• How does the computer know the meaningof 01000001?– Interpretation depends on the current instruction

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 10

Secondary Memory

• Main memory stores instructions and data while a program is running.

• Secondary memory– Stores instructions and data permanently– A file stores data or instructions in

secondary memory

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 11

Secondary Memory Media

• A computer might have any of thesetypes of secondary memory– Hard disk

• Fast• Fixed in the computer and not normally removed

– Floppy disk• Slow• Easily shared with other computers

– Compact disk• Slower than hard disks• Easily shared with other computers• Can be read only or re-writable

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 12

The Processor

• Typically called the CPU– Central Processing Unit– Follows program instructions – Typical capabilities of CPU include:

addsubtractmultiplydividemove data from location to location

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 13

Figure 1-3: Types of software

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 14

Figure 1-4: Software

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 15

Figure 1-5: Personal computing environment

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 16

Figure 1-6: Time-sharing Environment

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 17

Figure 1-7: Client-server environment

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 18

Figure 1-8: Types of computer languages

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 19

Machine Language: the only language understood by a computer

LUAS = PANJANG * LEBAR IF LUAS > 50

GOTO BESAR ELSE

GOTO KECIL

0101 1000 0001 00000101 1011 0001 00000101 0000 0001 0000

MOVE #$1,D1MOVE #$8,D0ADD D0,D1

Assembly/Symbolic language

High-level language

Example:

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 20

Figure 1-9: Building a C program

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 21

Figure 1-10: Executing programs

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 22

Figure 1-11: Process of system development

Building programs•Edit•Compile•Link•Run

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 23

Figure 1-11: Process of system development

Understand the problem:•Input•Output•Process

Algorithm is the stepsto solve problems

Develop the solution (Algorithm):•Structure chart•Pseudocode•Flowchart

Converting design to computer codes. e.g: Flowchart -> C program

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 24

Testing and Debugging

• Bug– A mistake in a program

• Debugging– Eliminating mistakes in programs– Term used when a moth caused a failed relay

on the Harvard Mark 1 computer. Grace Hopper and other programmers taped the moth in logbook stating: “First actual case of a bug being found.”

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 25

Program Errors

• Syntax error– Violation of the grammar rules of the language– Discovered by the compiler

• Error messages may not always show correct location of errors

• Run-time error– Error detected by the computer at run-time

• Logic error– Error in the program’s algorithm– Most difficult to diagnose– Computer does not recognize it.

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 26

Program Errors (cont.)

Syntax error example

x = 2;y = 3z = x + y;

This line consists an error. Each statement must be endedwith a semi-colon ‘;’

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 27

Program Errors (cont.)

Run-time error example

x = 0;y = 3/x;

This line produces an error, because thedivision by zero. Thiserror is only discoveredwhen the program runs.

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 28

Program Errors (cont.)

Logic error example

Enter a number >> 10Enter another number >> 25

The total of those two numbers is 15

This is a logic error. The total should be 35 not 15.

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 29

Program Design

• Structure Chart• Pseudo-code• Flowchart

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 30

Structure ChartRepresents a program as a collection of sub-programs (modules)

Example:

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 31

Describe an algorithm in English-like statements

Example: Algorithm for multiplying two numbers

1. Get the first number, let say A2. Get the second number, let say B3. Calculate the result let say C, C= A * B4. Display the result, C

Pseudo code

Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 |Last Updated: July 2005 Slide 32

Represents an algorithm in graphical symbols

Example: Algorithm for multiplying two numbers

Start

Stop

Get AGet B

Display theResult C

Calculate ResutC=A*B

Flowchart