0% found this document useful (0 votes)
13 views23 pages

PF Lec02 Development&Design of Programs 26-01-2023

Uploaded by

Ahmed Bilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views23 pages

PF Lec02 Development&Design of Programs 26-01-2023

Uploaded by

Ahmed Bilal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Programming

Fundamentals
Lecture 2
Computer Components, Languages?

Since 1946 all computers have


had 5 components!!!

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

• Extremely large or small numbers can be written in exponential


or scientific notation for ease.
Example:
1. Avogadro’s number, used in chemistry :
602,214,179,000,000,000,000,000

2. Universal gravitational constant used in aerospace :


0.0000000000667428.

3
Exponential and Scientific Notations

• Write 602,214,179,000,000,000,000,000 in both notations ?


• Write 0.0000000000667428. in both notations ?

4
Automobile vs Computers

• Who controls an automobile ?


Driver controls it.

• 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

• Begins with a statement of a


problem or a specific request for a
program, which is referred to as a
program requirement.
• Four steps :
Step 1: Analyze the Problem
Step 2: Develop a Solution
(Use / Design an algorithm)
Step 3: Code the Solution
(Write the Program)
Step 4: Test and Correct the
Program 6
• 1. Determine and understand the
output items the program must
produce.
1. Analyze • 2. Determine the input items.
the Problem
• Together, these two items are
referred to as the problem’s
input/output (I/O).
• Only after determining a problem’s,
I/O can you select specific steps for
transforming inputs into outputs.

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)

• This step consists of writing a C++ program that


corresponds to the solution developed in Step 2.

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.

• Computer terminology, a program error is


called a bug

• Debugging is the process of finding and


resolving bugs within computer programs,
software, or systems

10
Coding an Algorithm

Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 11
Algorithm

An algorithm (step by step instructions) can be represented by:

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

Display the sum


• Flow Chart:

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

Q) A program must calculate the sum of all whole numbers from


1 through 100?
• Can you think of a solution to the problem ?

• Hint: Use formula:

n = number of terms to be added (100)


a = first number to be added (1)
b = last number to be added (100)
Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 17
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.

• Set n equal to 100


• Set a = 1
• Set b equal to 100
• Calculate sum = n(a + b)/2
• Print the sum

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

Flowchart Diagrams with


certain symbols
Display the sum

19

Copyright © 2013 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. End 19
EXAMPLE #03

• Give an algorithm for determining the average of three numbers.

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

You might also like