0% found this document useful (0 votes)
2 views

lecture01_ProgPrin (2)

This document is a lecture on the principles of programming, covering topics such as computer systems, programming logic, and the program development cycle. It introduces key concepts including pseudocode, flowcharts, programming languages, and the steps involved in coding and maintaining programs. The lecture also discusses different types of software and programming models, emphasizing the importance of understanding user needs and planning logic.

Uploaded by

ahmed4esmail2000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

lecture01_ProgPrin (2)

This document is a lecture on the principles of programming, covering topics such as computer systems, programming logic, and the program development cycle. It introduces key concepts including pseudocode, flowcharts, programming languages, and the steps involved in coding and maintaining programs. The lecture also discusses different types of software and programming models, emphasizing the importance of understanding user needs and planning logic.

Uploaded by

ahmed4esmail2000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

MENOUFIA UNIVERSITY

FACULTY OF COMPUTERS AND INFORMATION


‫جامعة المنوفية‬

First Year (First Semester)


CS Dept.,
p , (CS131)
( )

PRINCIPLES OF PROGRAMMING

LECTURE ONE

Dr. Hamdy M. Mousa


Computers and Programming
Computers
p & Programming
g g
• In this lecture, you will learn about:
– Computer systems
– Simple
p p program
g logic
g
– The steps involved in the program
development cycle
y
– Pseudocode statements and flowchart symbols
– Using
g a sentinel value to end a p
program
g
– Programming and user environments
– The evolution of programming models
Computers
p & Programming
g g
• Every computer system is composed of multiple
pieces of hardware and software.
software
• Hardware is the equipment, or the physical
devices.
devices
– For example, keyboards, mice, speakers,
• Software is computer instructions that tell the
hardware what to do.
– Software is p
programs,
g , which are instruction sets written
by programmers.
• For example, businesses use word-processing and accounting
programs and games
games.
• you can write your own programs.
Computers
p

“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

• The process of compiling a high-level language program


into machine language can take a considerable amount
of computer time.
• Interpreter programs were developed to execute high-
level language programs directly
directly, although much more
slowly.
UNDERSTANDING PROGRAMMING PROCESS

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

• Heart of programming process


• Programmer
P
– Plans program steps
– Decides steps to include and order
• Leads from available input to desired output
– Plans the solution: logic tools
• Flowcharts and pseudocode
• Both
B th use E
English-like
li h lik code
d
– Language syntax not a concern
3. Coding the Program

• Write class definitions


– Descriptions data in each class
– Operations performed with data in each class
• Object-oriented languages
–CC++,, C#, Java, Visual Basic, COBOL
– Similarity
• All ccreate
ea e objec
objectss and
a d establishing
es ab s g communication
co u ca o
3. Coding the Program (cont’d.)

• Program object and logic needed to work


with
ith th
the objects
bj t
– Executed using any number of languages
• Syntax (correct spelling and punctuation )
– Concern once language chosen

• Experienced programmers
– Combine planning and program coding in
one
o e sstep
ep
4. Translating the Program Code

• Many programming languages


• Computer knows one language
– Its machine language consisting of many 1s and 0s
• Translator programs (compilers or interpreters)
– Change English-like high-level programming into low-
level machine language
• Executable program
• Syntax error
– Issues when translator cannot translate the code
– Must be corrected to allow compilation to complete
• Debugging is the process of finding and
correcting
ti program errors.
5. Testing the Program

• Syntax error free program


– Not necessarily free of logical errors
– Must test for logical errors
• Requires entering of sample data
– Select test data carefullyy
– Error discovery may require changes
• To program logic
• To actual object design
• Process resembles syntax error correction cycle
6. Putting the Program into Production

• Program adequately tested


– Ready for organizational use
• Putting program into production
– Time to implement
• Can be short or long
• Depends on program nature, size and user needs
– Factors
• Training, data format changes, new platform causing
users to make choices in unanticipated
combinations
7. Maintaining the Program

• 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.

• A computer program is simply an algorithm for


a computer that is written in a programming
language.

• The programmers often use one of two tools:


• pseudocode (pronounced sue-doe-code) or
• flowcharts
– to p
plan the logic
g for p
programming
g gpproblem
solution.
Some symbols used in flowcharts

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

5 Flow direction lines


5-
indicate the flow of the program.
Arrowheads are drawn where flow direction lines join and
where flow direction lines meet other symbols.
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

9- Predefined process symbol


9
is used to represent a predefined process when
the flowcharts that define the process are not
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.

• Pseudo is a prefix that means FALSE, and to


code
d a program means to t putt it in
i a programming
i
language, pseudocode simply means false code
• Pseudocode
Pse docode for a partic
particular
lar program is often
similar in appearance to the final coded program.
• The chief difference is that pseudocode does not
follow syntax rules of a programming language.
Example
Example

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“

you declare a variable and do not initialize it,,


• if y
the variable contains an unknown value until it
is assigned a value.
– A variable’s unknown value commonly is called garbage.
Variable names
• Different languages put different limits on the length of
variable names,,
– although in general, the length of identifiers in newer languages is
virtually unlimited.
• Some rules of variable names:
– Variable names must be one word. The name can contain letters,
digits, hyphens, underscores, or any other characters you choose,
with the exception of spaces
spaces. i.e
i e r,
r rate and interestRate is a legal
variable name, as are. interest rate is not allowed because of the
space.
– Variable names must start with a letter.
letter Some programming
languages allow variable names to start with a non-alphabetic
character such as an underscore.
– It is preferred
preferred, Variable names should have some appropriate
meaning. This is not a formal rule of any programming language.

You might also like