PF Lec02 Development&Design of Programs 26-01-2023
PF Lec02 Development&Design of Programs 26-01-2023
Fundamentals
Lecture 2
Computer Components, Languages?
Computer Keyboard,
Processor
Mouse
Memory Devices
Disk
Control Input
(where (where
(“brain”) programs,
programs,
data data
Datapath live when live when
(“brawn”) Output not running)
running)
Display,
6th Component: Printer
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 2
System Bus
Exponential and Scientific Notations
3
Exponential and Scientific Notations
4
Automobile vs Computers
• In a computer ??
• More formally, a computer program is a self-contained set of
instructions used to operate a computer to produce a specific result.
• Another term for a program or set of programs is software
5
Development and Design of Program
7
2. Develop a
Solution
• In this step, you select the exact
set of steps, called an “algorithm”,
to be used to solve the problem.
ALGORITHM
• Step-by-step sequence of
instructions
• Describes how the data is to be
processed to produce the desired
outputs
• “What method will you use to
solve this problem?”
8
3. Code the Solution (Write the Program)
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 9
4. Test and Correct the
Program
• The purpose of testing is to verify that a
program works correctly and fulfills its
requirements.
10
Coding an Algorithm
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 11
Algorithm
1. Pseudocode
2. Formula
3. Flow Chart
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 12
Flow Chart
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or
display. 13
Example #01
Give an algorithm to find the sum of two numbers entered by the user.
1. Formula
2. Pseudocode
3. Flow Chart
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 14
Example #01
Start
• Pseudo Code:
a) Input two numbers. Input two
b) Add the two numbers. numbers
c) Display the sum.
Add the two numbers
• Formula: sum=a+b
End
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 15
Example #01
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 16
Example#02
• You can’t tell a computer to add the numbers from 1 through 100.
• Instead, you must give the computer a detailed, step-by-step set of
instructions that collectively form an algorithm.
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 18
HOW TO WRITE ALGORITHM ?
Pseudocode
• English-like phrases are used to describe the steps
• e.g.
• Set n equal to 100
• Set a = 1 Start
• Set b equal to 100
• Calculate sum = n(a + b)/2
Set n=100, a=1 and
• Print the sum
b=100
Formula mathematical
equations
sum=n(a+b)/2
19
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. End 19
EXAMPLE #03
1. Formula
2. Pseudocode
3. Flow Chart
20
Example #03
Start
• Pseudo Code:
a) Input three numbers. Input three
b) Find the average of numbers
three numbers.
c) Display the average. Find the average of
three numbers
• Formula: sum=(a+b+c)/3
Display the
average
• Flow Chart:
End
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 21
Example #03
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 22
Decision block
in the flow
chart
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or
display. 23