Chapter 2 Problem Solving Techniques - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

Chapter 2 Problem Solving Techniques

Description:

Title: Chapter 2 Problem Solving Techniques Author: Gary Last modified by: user Created Date: 3/6/2002 11:59:23 AM Document presentation format: – PowerPoint PPT presentation

Number of Views:396
Avg rating:3.0/5.0
Slides: 28
Provided by: gary213
Category:

less

Transcript and Presenter's Notes

Title: Chapter 2 Problem Solving Techniques


1
Chapter 2Problem Solving Techniques
2
  • 2.1 INTRODUCTION
  • 2.2 PROBLEM SOLVING
  • 2.3 USING COMPUTERS IN PROBLEM SOLVING THE
    SOFTWARE DEVELOPMENT METHOD

3
  • consists of the following steps
  • 1. Requirements specification
  • 2. Analysis
  • 3. Design
  • 4. Implementation
  • 5. Testing and verification
  • 6. Documentation
  • divide and conquer split the problem into
    several simpler subproblems, solve each
    individually, and then combine these solutions.

4
  • 2.4 REQUIREMENTS SPECIFICATION
  • understanding exactly what the problem is, what
    is needed to solve it, what the solution should
    provide.
  • 2.5 ANALYSIS
  • identify the following
  • 1. Inputs to the problem
  • 2. Outputs expected from the solution
  • 3. Any special constraints or conditions
  • 4. Formulas or equations to be used

5
  • 2.6 DESIGN AND REPRESENTATION OF ALGORITHMS
  • An algorithm is a sequence of a finite number of
    steps arranged in a specific logical order,
    which, when executed, produce the solution for a
    problem.
  • An algorithm is a procedure that takes a set of
    values as input and transforms them into a set of
    values as output
  • In practice we expect algorithms to be efficient.

6
  • Pseudocoding
  • The main purpose of a pseudocode language is to
    define the procedural logic of an algorithm
  • requirements
  • 1. Have a limited vocabulary
  • 2. Be easy to learn
  • 3. Produce simple, English-link narrative
    notation
  • 4. Be capable of describing all algorithms

7
  • The Sequence Control Structure
  • is a series of steps or statements that are
    executed in the order in which they are written
    in an algorithm
  • read taxable income
  • read filing status
  • compute income tax
  • print income tax
  • Figure 2.1 A sequence control structure

8
  • The Selection Control Structure
  • define two courses of action, depending on the
    outcome of a condition.
  • if condition
  • then-part
  • else
  • else-part
  • end_if
  • the else-part may be missing.

9
  • A nested selection structure contains other
    if/else structures in its then-part or else-part.
  • if status is equal to 1
  • print single
  • else if status is equal to 2
  • print Married filing jointly
  • end_if

10
  • if status is equal to 1
  • print Single
  • end_if
  • if status is equal to 2
  • print Married filing jointly
  • end_if

11
  • The Repetition Control Structure
  • specifies a block of one of one or more
    statements that are repeatedly executed until a
    condition is satisfied.
  • while condition
  • loop-body
  • end_while
  • loop-body is a single statement or a block of
    statements

12
  • Print Enter taxable income should be greater
    than or equal to 50,000.00 read income
  • while income is less than 50000.00
  • begin
  • print Enter taxable income should be
    greater than or equal to 50,000.00
  • read income
  • end
  • end_while

13
  • Conventions for Pseudocoding
  • Each pseudocode statement includes keywords
  • Each pseudocode statement should be written on a
    separate line.
  • Statements in a sequence structure can be grouped
    into a block
  • For the selection control structure, use an
    if/else statement.
  • For the repetition control structure, use the
    while statement
  • All words in a pseudocode statement must be
    unambiguous and as easy as possible for
    nonprogrammers to understand.

14
  • Structure chart, as in figure 2.6. This chart
    indicates that the original problem is solved if
    the four subproblems at the lover level of
    hierarchy are solved from left to right.

15
  • set correctStatusInput to no
  • print FILING STATUS MENU
  • print Single ----1
  • print Married filing jointly ----2
  • print Married filing separately ----3
  • print Head of household ----4
  • while correctStatusInput is equal to no
  • begin
  • print Enter filing status should be between
    1 and 4
  • read filingStatus
  • if filingStatus is greater than 0
  • if filingStatus is less than 5
  • set correctstatusInput to yes
  • end_if
  • end_if
  • end
  • end_while
  • Figure 2.7 Final refinement of read and verify
    filing status

16
  • if filingStatus is 1
  • compute tam 11158.50 0.31 (income
    49300.00)
  • else if filingStatus is 2
  • if income is less than or equal to 82,150
  • compute tax 5100.00 0.28 (income
    34000.00)
  • else
  • compute tax 18582.00 0.31 (income
    82150.00)
  • end_if
  • else if filingStatus is 3
  • compute tax 9291.00 0.31 (income
    41075.00)
  • else if status is 4
  • if income is less than or equal to 70450.00
  • compute tax 4095.00 0.28 (income
    27300.00)
  • else
  • compute tax 16177.00 0.31 (income
    70450.00)
  • end_if
  • end_if
  • Figure 2.8 Final refinement of compute tax
    (continued)

17
  • print income
  • if filingStatus is equal to 1
  • print Single
  • else if filingStatus is equal to 2
  • print Married filing jointly
  • else if filingStatus is equal to 3
  • print married filing separately
  • else if filingStatus is equal to 4
  • print Head of household
  • end_if
  • print tax
  • Figure 2.9 Final refinement of print income,
    filing status, and tax

18
  • Algorithm design technique
  • Use the divide-and-conquer strategy to split the
    original problem into a series of subproblems.
  • Consider each subproblem separately and further
    split them into subproblems, until no further
    refinement is possible. Stop the process when you
    have a pseudocode that can be directly translated
    into a C program.
  • Combine all final refinements

19
  • Flowcharting
  • alternative to pseudocoding
  • flowchart is a graph consisting of geometrical
    shapes
  • the geometrical shapes in a flowchart represent
    the types of statements in an algorithm. The
    details of statements are written inside the
    shapes. The flow lines show the order in which
    the statements of an algorithm are executed. Two
    geometrical shapes used in flowcharting are the
    rectangle, which represents processes such as
    computations, assignments, and initializations,
    and the diamond-shaped box, which stands for the
    keyword if in pseudocode, with the if condition
    written inside the box.

20
(No Transcript)
21
(No Transcript)
22
(No Transcript)
23
(No Transcript)
24
(No Transcript)
25
  • 2.7 IMPLEMENTATION
  • translate each step of the algorithm into a
    statement in that particular language
  • Programming Errors
  • debugging
  • three types of programming errors
  • 1. design errors occur during the
    analysis,design, and implementation phases.
  • 2. Syntax error detected by the compiler
    during the compilation process.
  • 3. Run-time errors detected by the computer
    while your program is being executed. Divide a
    number by zero.

26
  • 2.8 TESTING AND VERIFICATION
  • A program must be tested using a sufficiently
    large sample of care fully designed test data
    sets such that every logical path in the program
    is traversed at least once.

27
  • 2.9 PROGRAM DOCUMENTATION
  • 1. A concise requirements specification
  • 2. Descriptions of problem inputs, expected
    outputs, constraints, and applicable formula.
  • 3. A pseudocode or flowchart for its algorithm
  • 4. A source program listing
  • 5. A hard copy of a sample test run of the
    program
  • 6. A users guide explaining to nonprogrammer
    users how the program should be used (optional)
Write a Comment
User Comments (0)
About PowerShow.com