• What a computer is
• What a computer program is
• The Programmer’s Algorithm
What Is a
• Computer?
Computer
– Executes statements (computations/logical
decisions)
• Hardware :Physical devices of computer
system
• Software: Programs
Central Processing
that run on computers
Unit
Control Unit
Input Output
device Device
Arithmetic/Logic
Unit
Memory Unit My My
data Progam
Computer Organization
• Six logical units of computer system
– Input unit (Mouse, keyboard)
– Output unit (Printer, monitor, audio speakers)
– Memory unit (Retains input and processed
information)
– Central processing unit (CPU) which
consists of:
• Control unit (Supervises operation of other devices)
• Arithmetic and logic unit (ALU) (Performs
calculations)
– Secondary storage unit (Hard drives, floppy
What a computer program
is?
• For a computer to be able to perform
specific tasks (i.e. print what grade a
student got on an exam), it must be
given instructions to do the task.
• The set of instructions that tells the
computer to perform specific tasks is
known as a computer program
Levels of
Abstraction
• Human thought
• Pseudo-Natural Language (English,
Arabic)
• High Level Programming Language
(C, C++, Java, …)
• Machine Code
The Programmer’s
Algorithm
• An algorithm is a finite
sequence of instructions that
produces a solution to a problem.
• The programmer’s algorithm:
– Define the problem.
– Plan the problem solution.
– Code the program.
– Compile the program.
– Run the program.
– Test and debug the program.
Defining the
• TheProblem
problem must be defined in terms of:
– Input: Data to be processed.
– Output: The expected result.
• Look for nouns in the problem statement that suggest
output and input.
– and processing: The statements to achieve.
• Look for verbs to suggest processing steps.
input data output data
Keyboard Processing Screen
Input and Output
• Inputs
– Can come from many sources, such as
users, files, and other programs
– Can take on many forms, such as text,
graphics, and sound
• Outputs
– Can also take on many forms, such as
numbers, text, graphics, sounds, or
commands to other programs
Example
Area and Perimeter
1 of a
rectangle
• Input
– Length
– width
• Processing
– Area = length*width
– Perimeter = 2*( length +
width)
• Output
– Area
– Perimeter
Example
Sum and 2
Average of 5
numbers
• Input
– five number x1, x2, x3,
x4, x5
• Processing
– Sum = x1+x2+x3+x4+x5
– Average = Sum/5
• Output
– Sum
– Average
Example
Area and3Perimeter of a
circle
• Input
– Radius
– PI
• Processing
– Area = PI * Radius *
Radius
– Perimeter = 2 * PI *
Radius
• Output
– Area
– Perimeter
Planning the Solution
• When planning, algorithms are
used to outline the solution steps
using Englishlike statements,
called pseudocode.
Coding the
• Program
Coding is writing the program in a formal
language called Programming Language.
• Programming Language : A set of rules, symbols and
special words used to write statements.
• The program is written by translating the
algorithm steps into a programming
language statements.
• The written program is called Source code
and it is saved in a file with “.java” extension.
Algorithm
Codin Pseudocode
Translating
g
Progra Source
m Code (The
“.java”)
Why Coding in
Languages
Programming
• We write computer programs (i.e. a set
of instructions) in programming
languages such as C, C++, and Java.
• We use these programming
languages because they are
easily understood by humans
• But then how does the computer
understand the instructions that we
write?
Compiling Computer
Programs
• Computers do not understand
programs written in programming
languages such as C++ and Java
• Programs must first be converted
into machine code that the
computer can run
• A Software that translates a
programming language statements
into machine codeSource
Program is called a
code
compiler Compilin Translating
g
Machine code Machine
Code
Programming Language
Compiler
• A compiler is a software that:
– Checks the correctness of the source
code according to the language
rules.
• Syntax errors are raised if some rules
were violated.
– Translates the source code into a
machine code if no errors were
found.
Platform
dependent
• Because diff erent platforms ,or
Compiling
hardware architectures alongwith
the operating systems (Windows,
Macs, Unix), require diff erent
machine code, you must compile
most programs separately for
each platform.