Sie sind auf Seite 1von 37

Course Contents

2 Program Development

 Phases of Computer Program Development


 Problem Definition and Analysis
 Algorithms and Flowcharts
 Program Coding
 Program Execute and Testing

 Exercise

C Programming 25 Higher Technological Institute


Problem Definition and Analysis
o The problem which you write a program for should be
completely understood by gathering information
about it.
o This information is the program input.
o How information is processed to give the required
output.
oExample

𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 26 Higher Technological Institute
Problem Definition and Analysis
o The General Quadratic Equation

𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 27 Higher Technological Institute
Problem Definition and Analysis
o The General Quadratic Equation
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙=
𝟐𝒂

𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 28 Higher Technological Institute
Problem Definition and Analysis
o The General Quadratic Equation
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙=
𝟐𝒂
−𝒃 + 𝒃𝟐 − 𝟒𝒂𝒄 −𝒃 − 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏 = 𝒂𝒏𝒅 𝒙𝟐 =
𝟐𝒂 𝟐𝒂

𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 29 Higher Technological Institute
Problem Definition and Analysis
o The General Quadratic Equation Discriminator
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙=
𝟐𝒂
−𝒃 + 𝒃𝟐 − 𝟒𝒂𝒄 −𝒃 − 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏 = 𝒂𝒏𝒅 𝒙𝟐 =
𝟐𝒂 𝟐𝒂

𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 30 Higher Technological Institute
Problem Definition and Analysis
o The General Quadratic Equation Discriminator
−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙=
𝟐𝒂
−𝒃 + 𝒃𝟐 − 𝟒𝒂𝒄 −𝒃 − 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏 = 𝒂𝒏𝒅 𝒙𝟐 =
𝟐𝒂 𝟐𝒂
𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄
𝒊𝒇 𝑫 < 𝟎 𝒙𝟏 𝒂𝒏𝒅 𝒙𝟐 𝒂𝒓𝒆 𝑰𝒎𝒂𝒈𝒊𝒏𝒂𝒓𝒚
𝒊𝒇 𝑫 > 𝟎 𝒙𝟏 𝒂𝒏𝒅 𝒙𝟐 𝒄𝒂𝒏 𝒃𝒆 𝑪𝒂𝒍𝒄𝒖𝒍𝒂𝒕𝒆𝒅

𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 31 Higher Technological Institute
Problem Definition and Analysis
o How information is processed to give the required
output ?

𝒂 , 𝒃 𝒂𝒏𝒅 𝒄 𝒂𝒓𝒆 𝑮𝒊𝒗𝒆𝒏 = 𝑰𝒏𝒑𝒖𝒕𝒔


𝟐
𝑫 = 𝒃 − 𝟒𝒂𝒄 Question D >0 ?
−𝒃+ 𝒃𝟐 −𝟒𝒂𝒄 −𝒃− 𝒃𝟐 −𝟒𝒂𝒄
YES 𝒙𝟏 = 𝒂𝒏𝒅 𝒙𝟐 =
𝟐𝒂 𝟐𝒂
NO 𝒙𝟏 𝒂𝒏𝒅 𝒙𝟐 𝒂𝒓𝒆 𝑰𝒎𝒂𝒈𝒊𝒏𝒂𝒓𝒚

𝒂𝒙 𝟐 + 𝒃𝒙 + 𝒄 = 𝟎
C Programming 32 Higher Technological Institute
Algorithms and Flowcharts

C Programming 33 Higher Technological Institute


2.2 Flow Charts
 A flow chart is a diagrammatic representation for
solving the problem. The symbols used in flow chart
Opal start , stop ‫ﺑﺩﺍﻳﺔ ﻭﻧﻬﺎﻳﺔ ﺍﻟﺑﺭﻧﺎﻣﺞ‬
Parallelogram input , output ‫ﻁﺑﺎﻋﺔ – ﺇﺧﺭﺍﺝ ﺃﻭ ﺍﺩﺧﺎﻝ ﺑﻳﺎﻧﺎﺕ‬
Rectangle Processing program instruction ‫ﺇﺟﺭﺍء ﻋﻣﻠﻳﺔ ﺣﺳﺎﺑﻳﺔ‬

Diamond Decision ‫ﺇﺗﺧﺎﺫ ﻗﺭﺍﺭ‬

Flow direction

Preparation… loop ‫ﻳﺳﺗﺧﺩﻡ ﻋﻧﺩ ﺍﻟﻠﺟﻭء ﺇﻟﻰ ﻋﻣﻝ‬


Connector … ‫ﻹﻛﻣﺎﻝ ﺍﻟﺑﺭﻧﺎﻣﺞ ﻓﻰ ﺻﻔﺣﺔ ﺍﺧﺭﻯ‬
Flowcharts

𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄

−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂

C Programming 35 Higher Technological Institute


Flowcharts

𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄

−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂

C Programming 36 Higher Technological Institute


Flowcharts

𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄

−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂

C Programming 37 Higher Technological Institute


Flowcharts

𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄

YES NO

−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂

C Programming 38 Higher Technological Institute


Flowcharts

𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄

YES NO

−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂

C Programming 39 Higher Technological Institute


Flowcharts

𝑫 = 𝒃𝟐 − 𝟒𝒂𝒄

YES NO

−𝒃 ± 𝒃𝟐 − 𝟒𝒂𝒄
𝒙𝟏,𝟐 =
𝟐𝒂

C Programming 40 Higher Technological Institute


Flowcharts Examples
Example 1
Draw a flow chart to
read two numbers and
compare between both
if they are equal or not.

C Programming 41 Higher Technological Institute


Flowcharts Examples
Example 1
Draw a flow chart to
read two numbers and
compare between both
if they are equal or not.

C Programming 42 Higher Technological Institute


Example 2.1
Draw a flow chart to compare between two numbers if they
are equal or not. (if equal print Yes … if not equal print No).
Flowcharts Examples
Example 2
Draw a flow chart to generate
a table of squares and cubes
of integers from 1 to 9.

C Programming 43 Higher Technological Institute


Flowcharts Examples
Example 2
Draw a flow chart to generate
a table of squares and cubes
of integers from 1 to 9.

C Programming 44 Higher Technological Institute


Example 2.2
Draw a flow chart to show that if multiplication of two numbers
is odd or even (if even print EVEN … if odd print ODD)
Flowcharts Examples
Example 3
Draw a flow chart to
determine the minimum
value of three input
numbers.

C Programming 45 Higher Technological Institute


Flowcharts Examples
Example 3
Draw a flow chart to
determine the minimum
value of three input
numbers.

C Programming 46 Higher Technological Institute


Example 2.3
Draw a flow chart to determine the minimum value of 3 input
numbers.
Example 2.4
Draw a flow chart to determine the maximum value of 3 input
numbers.
Flowcharts Examples
Example 4
It is desired to compute income Tax for a given
income as per the following table:
Income Amount of tax ‫روبيه‬

Up to Rs 35000 Nil
From Rs 35001 20% of income
To Rs 60000 in Excess of Rs 35000
From Rs 60001 Rs 5000 + 30% of income in
To Rs 120000 Excess of Rs 60000
Rs 23000+ 40% of income in
More than Rs 120000
Excess of Rs 120000

C Programming 51 Higher Technological Institute


Flowcharts Examples

C Programming 52 Higher Technological Institute


Example 2.5: solution
Flowcharts Examples
Example 5
Draw a flowchart of Program
that Calculate and Display
The Factorial of n

C Programming 55 Higher Technological Institute


Flowcharts Examples
Example 5
Draw a flowchart of Program
that Calculate and Display
The Factorial of n
𝒏! = 𝒏 × 𝒏 − 𝟏 × 𝒏 − 𝟐 … × 𝟑 × 𝟐 × 𝟏

C Programming 56 Higher Technological Institute


Flowcharts Examples
Example 5
Draw a flowchart of Program
that Calculate and Display
The Factorial of n

𝒏! = 𝒏 × 𝒏 − 𝟏 × 𝒏 − 𝟐 … × 𝟑 × 𝟐 × 𝟏
C Programming 57 Higher Technological Institute
Example 2.8
Draw flow chart to compute the factorial:
n! = n*(n-1)*(n-2)* … * 3 * 2 * 1
Example 2.7
Draw flow chart to compute the factorial:
10! = 10*9*8* … * 3 * 2 * 1
Example .6
Draw flow chart to generate square roots of the series:
1, 4, 9, 16, 25, 36, 49, 64, 81, 100
Algorithms

C Programming 60 Higher Technological Institute


Program Coding
o In this phase, the algorithm ( or Flowchart ) is
transferred into program using codes of one of
programming language.
o Machine Language ( Binary Code ).

o Assembly Language.

o High Level Language.

C Programming 61 Higher Technological Institute