2 Semester 1439-1440 H
2 Semester 1439-1440 H
2 Semester 1439-1440 H
CSC 202
BASIC OF COMPUTER PROGRAMMING AND
ALGORITHMS
Done By: Rehab Aljaloud
CHAPTER 1
INTRODUCTION
2st Semester 1439-1440 H
What Is a Computer?
2
Computer
Executes statements (computations/logical decisions)
Hardware :Physical devices of computer system
Software: Programs that run on computers
Central Processing Unit
Control Unit
Arithmetic/Logic Unit
Operating System
Utility software
Application software is computer software
designed to help the user to perform singular or
multiple related specific tasks.
Word processor
Spreadsheet
Web browser
Basic Computer Operations
9
Process data
Store data,
information
and instructions.
What a computer program is?
10
A set of
Symbols (punctuation),
Special words or keywords (vocabulary),
And rules (grammar)
used to construct a program.
Evolution of Programming
12
Languages
Languages differ in
Size (or complexity)
Readability
Expressivity (or writability)
"Level"
closeness to instructions for the CPU
Types of Programming
13
Language
There are three types of programming language:
–Machine language(Low-level language)
–Assembly language(Low-level language)
–High-level language
•Low level languages are closer to the language
used by a computer, while high-level languages are
closer to human languages.
Machine Language
14
Binary-coded instructions
Address Contents
Only languages understood
2034 10010110
by computers. 2035 11101010
Used directly by the CPU 2036 00010010
Lowest level language 2037 10101010
Every program step is ultimately 2038 10010110
Machine Language
169 1 160 0 153 0 128 153 0 129 153 130 153 0 131
200 208 241 96
High level language
MUL X,10
ADD X,Y
Mnemonic Instruction STO Z,20
ADD 10010011 SUB X,Z
Click icon to add picture
source
program.
Saved in File
ClassName.ja
va
An Overview Of Computer Languages
21
Easier to use
More powerful
The Code life Cycle!!
22
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 1
Area and Perimeter of a rectangle
26
Input
Length
width
Processing
Area = length*width
Perimeter = 2*( length + width)
Output
Area
Perimeter
Example 2
Sum and Average of 5 numbers
Page 27
Input
five number X1, X2, X3, X4, X5
Processing
Sum = X1+X2+X3+X4+X5
Average = Sum/5
Output
Sum
Average
Example 3
Area and Perimeter of a circle
Page 28
Input
Radius
PI
Processing
Area = PI * Radius * Radius
Perimeter = 2 * PI * Radius
Output
Area
Perimeter
2-Planning the Solution
29
start
1. Start the program
2. Read the first number and save in
the variable ( N1 ) Read N1
3. Read the second number and save in
the variable ( N2 ) Read N2
4. Sum the both numbers and save the
result in the variable ( Sum )
Sum = N1 + N2 Sum = N1 + N2
5. Print the variable ( Sum )
6. End the program Print Sum
End
3-Coding the Program
31
Coding Translating
Compiling Translating
Before running..
links the object code with the code for the missing functions to produce
an executable image (with no missing pieces) , this is called link
phase .
the computer, under the control of its CPU, executes the program
one instruction at a time
6-Testing and Debugging the Program
36
Testing
Be sure that the output of the program conforms with the input.
There are two types of errors:
Logical Errors: The program run but provides wrong output.
Runtime errors: The program stop running suddenly when asking the
OS executing a non accepted statement (divide by zero, etc).
Debugging
Find, Understand and correct the error
37