Académique Documents
Professionnel Documents
Culture Documents
References
H. M. Deitel & P. J. Deitel.
C How to Program,
5th Edition.
Prentice Hall, 2004.
Collaboration
The goal of assignments (homework) is to give you
practice in mastering the course material.
You must write up each problem solution or
program by yourself without assistance, even if
you collaborate with others to solve the problem.
You are asked on your assignment hand-in to
identify your collaborators. If you did not work
with anyone, you should write "Collaborators:
none". If you obtain a solution through research
(e.g., on the world wide web), acknowledge your
source, but write up the solution in your own
words.
Plagiarism and other anti-intellectual behavior
cannot be tolerated in any academic environment.
LYS, SAM, IB, HK
Part 1 Slide 3
What is a computer?
A computer is a machine that stores data (numbers,
words, pictures), interacts with devices (the
monitor screen, the sound system, the printer), and
executes programs.
A computer program is a sequence of instructions
and decisions that the computer carries out to
achieve a task.
Programs describe specific actions.
A computer executes very simple instructions.
A computer executes instructions very rapidly.
A computer is a general purpose machine.
What is a computer?
A computer must be programmed to perform
tasks. Different tasks require different programs.
A computer program consists of a finite sequence
of very basic operations.
A typical operation may be one of the following:
put a red dot onto a certain screen position
send the letter B to the printer
get a number from a certain location in memory
add up two numbers
if this value is negative, stop the program
repeat this instruction ten times
What is a computer?
Hardware
Physical devices of a computer system
Software
Programs that run on computers
What is programming?
A computer program tells a computer, in very
detail, the sequence of steps that are needed to
fulfill a task.
The act of designing and implementing these
programs is called computer programming.
Programmers develop computer programs to make
computers perform new tasks.
A professional computer scientist or software
engineer does a great deal of programming.
The activity of programming is an important part
of computer science.
Anatomy of a computer
At the heart of the computer lies the central
processing unit (CPU).
The CPU locates and executes the program
instructions; it carries out arithmetic operations
such as addition, subtraction, multiplication, and
division; it fetches data from external memory or
devices or stores data back.
Anatomy of a computer
The computer keeps data and programs in storage.
There are two kinds of storage:
primary storage, also called random-access memory
(RAM) or simply memory.
secondary storage, usually a hard disk.
Primary storage loses all its data when the power
is turned off. Secondary storage persists without
electricity.
Most computers have removable storage devices:
floppy disks, tapes, compact discs (CDs),
flashdisks.
Anatomy of computer
To interact with a human user, a computer
requires peripheral devices.
input devices: keyboard, mouse.
output devices: display screen, printer.
Computer System
Five logical units of a computer system
Input unit: Mouse, keyboard
Output unit: Printer, monitor, audio speakers
Primary Storage unit (Memory unit): RAM
Central processing unit (CPU)
supervises operation of other devices
contains Arithmetic and Logic Unit (ALU)
ALU performs calculations
Secondary storage unit
Hard-disk drives, floppy-disk drives, CD drives
RAM Chips
A Hard Disk
A CD-ROM Drive
A Personal Computer
LYS, SAM, IB, HK
Part 1 Slide 19
A Motherboard
Schematic Diagram of a
Personal Computer
LYS, SAM, IB, HK
Part 1 Slide 21
Running a Program
Program—a sequence of instructions for a computer to follow
Program
Data
Computer Output
(input for the program)
/* A first program in C */
#include <stdio.h>
/* function main begins program execution */
int main()
{
printf( “Selamat belajar programming" );
return 0; /*indicate that program ended successfully */
Edit–Compile–Debug Loop
Problem Solving
Given a problem, find an appropriate algorithm.
Algorithms are implemented as executable
computer programs.
Algorithm is an unambiguous, executable, and
terminating specification of a way to solve a
problem.
Algorithms
Unambiguous
Executable
Terminating
If you can't find an algorithm, the computer can't
solve your problem.
Programming Languages
Machine language
“Natural language” of computer component
Machine dependent
Assembly language
English-like abbreviations represent computer operations
Assembler converts it to machine language
High-level language
Allows for writing more “English-like” instructions
Contains commonly used mathematical operations
Compiler converts it to machine language
Interpreter executes high-level language programs
without compilation
Assembly Language
(middle level)
a more or less human .model small
.stack
readable version of machine .data
language message db "Hello world, I'm learning
Assembly !!!", "$"
words, abbreviations, letters
and numbers replace 0s and .code
1s main proc
easily translated from human mov ax,seg message
readable to machine
mov ds,ax
Source Machine
Compiler
Code Code
Types of Errors
Syntax
Run-Time
Logic
Syntax Errors
a “grammatical” error
caught by compiler (“compiler-time error”)
automatically found, usually the easiest to fix
cannot run code until all syntax errors are fixed
error message may be misleading
Example:
Misspelling a command, for example “rturn” instead of “return”
Run-Time Errors
An execution error (during run-time)
Not always so easy to fix
Error message may or may not be helpful
Example:
Division by zero - if your program attempts to divide an integer by
zero it automatically terminates and prints an error message.
Logic Errors