Sie sind auf Seite 1von 32

Lecture 1

Introduction To
Computers

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 1


Todays Topics
Computer Systems
Computing Environments
Computer Languages
System Development

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 2


Figure 1-1: A computer system

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 3


Figure 1-2: Basic hardware components

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 4


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 | DCP2073 Basic C Programming Slide 5


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 | DCP2073 Basic C Programming Slide 6


Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 7
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


additional
bits for larger data

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 8


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 meaning


of 01000001?
Interpretation depends on the current instruction

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 9


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 | DCP2073 Basic C Programming Slide 10


Secondary Memory Media

A computer might have any of these


types 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 | DCP2073 Basic C Programming Slide 11


The Processor

Typically called the CPU


Central Processing Unit
Follows program instructions
Typical capabilities of CPU include:

add
subtract
multiply
divide
move data from location to location

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 12


Figure 1-3: Types of software

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 13


Figure 1-4: Software

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 14


Figure 1-5: Personal computing environment

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 15


Figure 1-6: Time-sharing Environment

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 16


Figure 1-7: Client-server environment

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 17


Figure 1-8: Types of computer languages

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 18


Example:

Machine Language:
the only language understood by a computer Assembly/Symbolic language

0101 1000 0001 0000 MOVE #$1,D1


0101 1011 0001 0000 MOVE #$8,D0
0101 0000 0001 0000 ADD D0,D1

High-level language

LUAS = PANJANG * LEBAR


IF LUAS > 50
GOTO BESAR
ELSE
GOTO KECIL

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 19


Figure 1-9: Building a C program

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 20


Figure 1-10: Executing programs

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 21


Figure 1-11: Process of system development

Building programs
Edit
Compile
Link
Run

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 22


Figure 1-11: Process of system development
Understand the problem:
Input
Output
Process
Develop the solution
(Algorithm):
Structure chart
Pseudocode
Flowchart
Converting design to
computer codes.

e.g:
Flowchart -> C program
Algorithm is the steps
to solve problems

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 23


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 | DCP2073 Basic C Programming Slide 24


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 programs algorithm
Most difficult to diagnose
Computer does not recognize it.

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 25


Program Errors (cont.)

Syntax error example


x = 2; This line consists an
y = 3 error. Each statement
must be ended
z = x + y; with a semi-colon ;

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 26


Program Errors (cont.)

Run-time error example


This line produces
x = 0; an error, because the
y = 3/x; division by zero. This
error is only discovered
when the program runs.

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 27


Program Errors (cont.)

Logic error example

Enter a number >> 10


Enter another number >> 25

The total of those two


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

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 28


Program Design

Structure Chart
Pseudo-code
Flowchart

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 29


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

Example:

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 30


Pseudo code

Describe an algorithm in English-like statements

Example: Algorithm for multiplying two


numbers

1. Get the first number, let say A


2. Get the second number, let say B
3. Calculate the result let say C, C= A * B
4. Display the result, C

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 31


Flowchart
Represents an algorithm in graphical symbols

Example: Algorithm for multiplying two numbers

Start

Get A
Get B

Calculate Resut
C=A*B

Display the
Result C

Stop

Chapter 1: Introduction To Computer | DCP2073 Basic C Programming Slide 32

Das könnte Ihnen auch gefallen