Programming - PowerPoint PPT Presentation

1 / 47
About This Presentation
Title:

Programming

Description:

Sequence of instructions that highlight the steps to execute ... Programmers were admonish to always flowchart their logic rather than carry it in their heads ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 48
Provided by: notesU
Category:

less

Transcript and Presenter's Notes

Title: Programming


1
CHAPTER 1
  • Programming
  • Problems Solving

2
Objectives
  • Define the meaning of programming and program
    correctly
  • List step by step process in program development

3
What is computer programming?
  • Process to plan the sequence of instructions that
    will be execute by the computer
  • Task / events
  • Planning
  • Scheduling
  • Execution
  • To handle specific task / events

4
What is computer program?
  • Sequence of instructions that highlight the steps
    to execute by the computer
  • Use programming language
  • Computer should understand the instruction given
    by the programmer

5
What is Problem Solving?
  • Process of transforming the description of a
    problem into a solution of that problem by using
    our knowledge of the problem domain and by
    relying on our ability to select and use
    appropriate problem-solving strategies,
    techniques and tools.
  • - page 21, Problem Solving Using C, Yuksel Uckan

6
Problem specifics analysis
  • Requirement specification eliminated
    ambiguities in the problem statement.
  • Analysis identified problem inputs, outputs
    collected information about the inputs.
  • Design developed a series of steps with a
    logical order which, when applied, would produce
    the output of the problem
  • Implementation Using tools.
  • Testing verification check the output to
    verify the correctness of the method.

7
Problem solving approach
  • Engineering Science Engineering Science
    method.
  • Bussiness-oriented systems approach
  • Computer programs software development
    method/software life-cycle

8
Software development methods
  • Requirement specification
  • Analysis
  • Design
  • ------------------------------
  • Implementation
  • Testing Verification
  • Documentation

Problem solving phase
Implementation phase
9
Requirement Specification
  • Understanding what the problem is?
  • What is needed to solve it?
  • What is solution should provide?
  • Constraints special conditions.
  • Defining problem depends on degree of
    familiarity with the problem domain. What would
    you do if you dont?

10
Analysis
  • Inputs to the problem, their form input media
    to be used
  • Outputs expected from the solution, their form
    output media to be used
  • Any special constraints or conditions
  • Formulas or equations to be used

11
Design
  • Method of solution what is define by design?
  • Also called as algorithm a sequence of a finite
    number of steps arranged in a specific logical
    order, which, when executed, produce the solution
    for a problem.

12
A quick history of algorithm
  • Introduce by a Persian mathematician named Abu
    Jafar Mohammed Ibnu Musa Al-Khawarizmi
  • Al-khawarizmi
  • A set of procedure that explain the way to solve
    a problem

13
Why study algorithms?
  • Describes the steps needed to perform a
    computation
  • Important for writing efficient code
  • Code that execute faster which uses less memory
  • A finite number of steps for solving a particular
    problem within a certain time frame.
  • A finite step by step problem solving technique

14
Characteristics of a good algorithm
  • Simple, clear concise readable
  • Solvable, terminates after a finite number of
    instructions
  • Correct, efficient robust
  • Accomplishes at least one task or produces at
    least one output

15
Algorithm representation
  • Pseudocode
  • A semiformal, Englishlike language with a
    limited vocabulary can be used to design
    describe algorithm.
  • Flowchart
  • A graph consisting of geometrical shapes that are
    connected by flow lines.

16
Guidelines to develop the pseudocode
  • Each step has not more than 2 action
  • Each steps is execute in-order
  • The word End is used to show the end of process
  • Selection / conditional structure (optional)
  • Repetition / loop structure (optional)
  • Use arithmetic symbol

17
  • Variable name can be declare to identify the
    appropriate its data type represent / hold
    value
  • Examples of data types Integer, floating-point,
    character, etc.
  • Initial value for variable (optional)
  • Logical operator (if required)
  • lt, lt, gt, gt, !,

18
  • Word must be clear meaningful
  • Use the word Read / Input / Get for data input to
    algorithm
  • Use the word Print / Write / Output to mention
    the output from algorithm

19
Flowchart
  • Flowcharts were formerly used to describe each
    processing path in a program (the main program
    and various subroutines that could be branched
    to)
  • Programmers were admonish to always flowchart
    their logic rather than carry it in their heads
  • Use of simple geometric symbols to represent the
    beginning or end of a program (an oval), a
    process (a rectangle), a decision (a diamond), or
    an I/O process (a parallelogram). These symbols
    are defined in ANSI x 3.5 and ISO 1028

20
Symbols use in flowchart
Begin / End
Activity Flow
21
Related websites
  • Further information
  • http//users.erofs.com/zenithco/khawaris.html
  • Download tools (free)
  • http//www.smartdraw.com

22
Guidelines to develop the flowchart
  • Identify the correct symbol
  • according to their function
  • Get a correct formula
  • Use the appropriate data
  • Test your flowchart
  • Trace each symbol compare with the expected
    output

23
Example
  • Problem Add 2 numbers
  • Steps
  • Begin
  • Read number 1
  • Read number 2
  • Add number 1 number 2
  • End

Read number 1
Read number 2
24
Selection Structure
  • Single selection
  • Bi-selection
  • Multi-selection

25
Single selection
  • Test for one condition only
  • Choose either true or false
  • There are an alternate flow if the condition is
    true
  • Syntax
  • Step a
  • If ltcondition truegt
  • Begin
  • Step 1
  • Step 2
  • . . . . . .
  • Step n
  • End
  • Step n 1

26
Example
Problem Compare 2 values. If number 1 is
greater than number 2, print message Number 1
Flowchart
  • Pseudocode
  • Begin
  • Read no1
  • Read no2
  • If (no1 gt no2 )
  • 4.1 Print Number 1
  • End

Read no1
Read no2
True
If no1 gt no2
Print Number1
False
27
Bi-selection
  • Choose either true or false
  • 2 different alternate flow for both condition
  • Syntax

If ltcondition truegt Begin Step 1 . . . . Step
n End If ltcondition falsegt Begin Step 1 . . .
. Step n End
28
Example
Problem Compare 2 values. If number 1 is
greater than number 2, print message Number 1
else print message Number 2
  • Pseudocode
  • Begin
  • Read no1
  • Read no2
  • If (no1 gt no2 )
  • 4.1 Print Number 1
  • Else
  • 5.1 Print Number 2
  • End

29
Example Flowchart
Read no1
Read no2
If no1 gt no2
True
False
Print Number 1
Print Number 2
30
Multi-selection
  • There are several alternative flow regarding to
    the satisfied condition

Problem Compare 2 values. If number 1 is greater
then number 2, print message Number 1. If
number 2 is greater than number 1, print message
Number 2, otherwise print message Equal.
31
Example Pseudocode
  • Begin
  • Read no1
  • Read no2
  • If (no1 gt no2 )
  • 4.1 Print Number 1
  • Else If (no2 gt no1 )
  • 5.1 Print Number 2
  • Else
  • 6.1 Print Equal
  • 7. End

32
Example Flowchart
Read no1
Read no2
True
Print Number 1
If no1 gt no2
False
True
Print Number 2
If no2 gt no2
False
33
Repetition Structure
  • For
  • While
  • Do-while

34
FOR Loop
  • 3 components
  • Initial value for counter
  • Condition to repeat the loop
  • Update the counter
  • The counter can be increase / decrease
  • Condition might be TRUE or FALSE
  • Must test the condition first
  • Condition result might be TRUE or FALSE
  • If the condition is TRUE, alternate flow will be
    execute

35
General Syntax
  • FOR (counter initial value test counter
    update counter)
  • BEGIN
  • Statement 1
  • Statement 2
  • . . .
  • Statement n
  • END

Test C
FALSE
TRUE
36
Example problem
  • Print a multiplication table for 1 to 10 by
    number 2

37
Solution Pseudocode
  • Begin
  • Let TOTAL 0
  • For (C1 Clt11 increase value C by 1)
  • 3.1 Begin
  • 3.2 TOTAL TOTAL 2
  • 3.3 Print TOTAL
  • 3.4 End
  • End

Alternate flow
38
Solution Flowchart
True
False
39
WHILE loop
  • Must test the condition first
  • Condition result might be TRUE or FALSE
  • If the condition is TRUE, alternate flow will be
    execute
  • If the condition is FALSE, skip the alternate
    flow
  • If the condition is FALSE at the first test,
    alternate flow will not be execute anymore

40
General syntax
  • WHILE ltcondition TRUEgt
  • Begin
  • Statement 1
  • Statement 2
  • . . .
  • Statement n
  • End

TRUE
Condition
FALSE
41
Example problem
  • Do the summation for the input number until user
    key-in 999. Print total

42
Pseudocode
  • Begin
  • TOTAL 0
  • INPUT 0
  • WHILE (INPUT ! 999)
  • 2.1 Begin
  • 2.2 Read INPUT
  • 2.3 TOTAL TOTAL INPUT
  • 2.4 End
  • Print TOTAL
  • End

Alternate flow
43
Flowchart
44
DO WHILE Loop
  • Condition test at the end of loop
  • The loop will be repeated if the condition is
    TRUE
  • The alternate flow will be executed at least once

45
General syntax
  • Begin
  • Statement 1
  • Statement 2
  • . . .
  • Statement n
  • End
  • WHILE ltcondition TRUEgt

Condition
TRUE
FALSE
46
Pseudocode
  • Begin
  • TOTAL 0
  • 2.1 Begin
  • 2.2 Read INPUT
  • 2.3 TOTAL TOTAL INPUT
  • 2.4 End
  • 2.5 WHILE (INPUT ! 999)
  • Print TOTAL
  • End

Alternate flow
47
Flowchart
Write a Comment
User Comments (0)
About PowerShow.com