lecture01_ProgPrin (2)
lecture01_ProgPrin (2)
PRINCIPLES OF PROGRAMMING
LECTURE ONE
“The Box”
CRT Display CD-ROM Drive
Floppy
Disk
i k
Drive
Keyboard
Mouse
SOFTWARE TYPES
• System Software
– Operating
p g systems
y
– Communications
– Device drivers and utilities
– Performance management
g
• Business Software
– General business
– Applications by business/interest area
– Desktop publishing
– Project management
– Image processing
• Development Software
– Programming languages
– Computer-assisted software engineering
– Web site development software
PROGRAMMING MODELS
• programmers to develop programs and
their procedures:
– Procedural pprogramming
g g focuses on the
procedures that programmers create.
• procedural programmers focus on the actions that
are carried.
i d
– Object-oriented programming focuses on
objects or “things
objects, things,” and describes their
features (also called attributes) and
behaviors.
PROGRAMMING LANGUAGE
• You write computer instructions in a computer
programming
p g g language
g g such as Visual Basic,, C++,, C#,,
or Java.
• Programmers write programs in different languages.
– S
Some programmers work l i l iin one language,
k exclusively l
• others know several and use the one that is best suited to the
task at hand.
• The instructions you write using a programming language
are called program code.
• Every programming language has rules governing its
word usage and punctuation.
– These rules are called the language’s syntax.
– Mistakes in a language’s usage are syntax errors.
COMPUTER LANGUAGES
• Computer languages may be divided into
three general types:
– Machine languages
– Assembly languages
– High-level languages
Programming steps:
1. Understand the problem.
2. Plan the logic.
3. Code the program.
4. Translate the p
program
g into machine
language.
5. Test the program.
p g
6. Put the program into production.
7. Maintain the program.
1. Understanding the Problem
• Programmer
– Write programs to satisfy
f others needs
– Provide services to users
• First understand
nderstand what
hat users
sers want
ant
• Well designed program
– Steps might involve a short meeting
• Poorly designed program
– Steps
St might
i ht take
t k many meeting
ti hours
h
• Thoroughly understanding problem
– A mostt difficult
diffi lt aspectt off programming
i
Envisioning the Objects
• Programmer
– Envisions objects needed
– Writes programming language instructions to
create objects
• Distinct steps
– Data modeling
• Identify all manipulated objects and relations
– Create class
• General object category
– Establish communication means
• Between objects, user
2. Planning the Logic
• Experienced programmers
– Combine planning and program coding in
one
o e sstep
ep
4. Translating the Program Code
• Maintenance
– Process of making required changes
• Reasons
– New legislated
– Input file format alterations
– End user requires additional information
• Not
o included
c uded in o
original
g a ououtput
pu spec
specifications
ca o s
The program development cycle
Algorithm
• An algorithm is a set of rules or instructions for
doing
g a task or solving
gap
problem.
1- Terminal symbol
indicates the beginning and the end of processing.
Some symbols used in flowcharts
2- I/O symbol
indicates that the computer is to obtain new
data or to record the results of computations
computations.
parallelogram
Some symbols used in flowcharts
3- Decision symbol
y
represents a branch in the flow of a program
diamond
Some symbols used in flowcharts
4- Process symbol
y
contains instructions that are not represented
by other symbols. i.e. it contains calculations,
storage of data
data.
rectangle
Some symbols used in flowcharts
6- comment or annotation
symbol is used to annotate other entries.
dashed line indicates the position of the
comment.
Some symbols used in flowcharts
7- connector
is used to join areas of a flowchart.
Some symbols used in flowcharts
8- Striped symbol
8
is used to represent a predefined process (or series of
operations) when the flowcharts that define the process
are included with the current set of flowcharts.
Some symbols used in flowcharts
10 Off-page
10- Off connector
t
is used to join areas of a flowchart when the points
joined occur on different pages
pages.
PSEUDOCODE
Pseudocode: (pronounced sue-doe-code) is
– an English
English-like
like representation
– used by programmers to plan the logical steps
for solving
gap
programming
g gpproblem.
Start
Read InputNumber
Result = InputNumber * 2
Print Result
Stop
Figure shows symbols and the flow direction lines
Repeating Instructions
start
input
p myNumber
y
set myAnswer = myNumber * 2
output myAnswer
input myNumber
set myAnswer = myNumber * 2
output myAnswer
input myNumber
set myAnswer = myNumber * 2
output
p myAnswer
y
….
…..
…..
Stop
Repeating Instructions
infinite loop
Using a Sentinel Value to End a Program
complex flowchart
Figure shows the Flowchart for what will happen to the values of X and Y
as the program runs
X Y
1 1
2 2
1 3
2 4
1
2
Figure shows the Flowchart for what will happen to the values of
X and Y as the program runs
X Y Y
1 1
2 2 2
2 3 3
1 3
2 3
2 4 4
Exercises
Exercises:
E i 1 Examine
E i the
th ffollowing
ll i flowchart,
fl h t fill in
i the
th table
t bl off values,
l and
d
answer the questions.
a. What numbers will be printed?
b. What
b at values
a ues will X a
andd Y have
a e when
e tthe
epprogram
og a e ends?
ds
Exercises
Exercises: 2- Examine the following flowchart, and fill in the table values.
What will the values of X, Y, and Z be when this program ends?
Computers, Memory, and
Input/Output
Computers can be viewed as consisting of three
types of components: input devices; output
devices; and the central processing unit, or
CPU.
Declaring and Using Variables
• All programming languages support two broad
data types;
– numeric describes data that consists of numbers
– string
g describes data that is nonnumeric.
• numeric constant is specific numeric value,
– such as 43, 12345800 within a program.
• string constant (literal string constant) is A specific text
value, or string of characters,
– such as “Amanda”
Amanda , “ 1000$
1000$”
• Variables are named memory locations whose contents can vary
or differ over time.
Variables
Declaration
• In most programming languages, before
you can use any variable, you must
include a declaration for it.
– A declaration is a statement that provides a
data type and an identifier for a variable.
• An identifier is a program component’s
name.
Variables
Declaration
• Optionally, initializing the variable
– Declaring a starting value. For example,
• num mySalary
• num yourSalary = 14.55
• string myName
• string
t i yourName
N = “Ahmed“
“Ah d“