กระบวนการแก้ปัญหาด้วย คอมพิวเตอร์ 3 พฤษภาคม 2547 13:00-17:00.

Slides:



Advertisements
Similar presentations
CS101: Introduction to Computer programming
Advertisements

Chapter 2: Problem Solving
Chapter 2: Problem Solving
ITEC113 Algorithms and Programming Techniques
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Programming Fundamentals (750113) Ch1. Problem Solving
Chapter 1 Program Design
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
Chapter 3 Planning Your Solution
PRE-PROGRAMMING PHASE
ALGORITHMS AND FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
1 L07SoftwareDevelopmentMethod.pptCMSC 104, Version 8/06 Software Development Method Topics l Software Development Life Cycle Reading l Section 1.4 – 1.5.
System Implementation System Implementation - Mr. Ahmad Al-Ghoul System Analysis and Design.
The University of Texas – Pan American
Chapter 2: Problem Solving
CSEB114: PRINCIPLE OF PROGRAMMING Chapter 2: Problem Solving.
Chapter 2: Problem Solving
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Developing a Program.
U NDERSTANDING P ROBLEMS AND HOW TO S OLVE THEM BY USING C OMPUTERS.
หลักการโปรแกรม เพื่อแก้ปัญหาโดยใช้คอมพิวเตอร์
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
Designing and Debugging Batch and Interactive COBOL Programs Chapter 5.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Slide 1 Software Development 1. Requirement Specification 2. Analysis 3. Algorithm Design 4. Implementation 5. Testing 6. Documentation.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
CMSC 1041 Algorithms II Software Development Life-Cycle.
Module 4 Part 1 Introduction To Software Development : Systems Analysis & Design Introduction To Software Development : Systems Analysis & Design.
PROGRAMMING PAPER 2 AS Algorithms.
ITEC113 Algorithms and Programming Techniques
CMSC 104: Peter Olsen, Fall 99Lecture 9:1 Algorithms III Representing Algorithms with pseudo-code.
1 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
Principles of Programming - NI July Chapter 2: Problem Solving In this chapter you will learn about: Introduction to Problem Solving Software development.
1 Program Planning and Design Important stages before actual program is written.
 In this chapter you will learn about:  Introduction to Problem Solving  Software development method (SDM)  Specification of needs  Problem analysis.
CSEB114: Principle of programming
The Hashemite University Computer Engineering Department
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Programming Fundamentals Introduction to Problem Solving  Programming is a problem solving activity. When you write a program, you are actually writing.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
Problem Solving Algorithms. PSPD Using C Design Slide 2 of 40 Topic & Structure of the lesson In this chapter you will learn about: Problem Solving Algorithm.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Introduction to Problem Solving Programming is a problem solving activity. When you write a program, you are actually writing an instruction for the computer.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
 Problem Analysis  Coding  Debugging  Testing.
Algorithms IV Top-Down Design.
Algorithms II Software Development Life-Cycle.
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
Algorithms and Flowcharts
Introduction To Flowcharting
Designing and Debugging Batch and Interactive COBOL Programs
Unit# 9: Computer Program Development
Introduction to Problem Solving
Problem Solving Techniques
Chapter 2- Visual Basic Schneider
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 2- Visual Basic Schneider
Understanding Problems and how to Solve them by using Computers
Programming Fundamentals (750113) Ch1. Problem Solving
Boolean Expressions to Make Comparisons
Programming Fundamentals (750113) Ch1. Problem Solving
Basic Concepts of Algorithm
Presentation transcript:

กระบวนการแก้ปัญหาด้วย คอมพิวเตอร์ 3 พฤษภาคม :00-17:00

THE SOFTWARE DEVELOPMENT METHOD Requirements Specification Analysis Design Implementation Testing and verification Documentation Reference: Yuksel Uckan, “Problem Solving Using C”, McGRAW-HILL, 2 nd edition, 1999

กรณีศึกษา (case study) Suppose our phone rings today, and we have an offer from QuikTak, a local federal income tax preparation service, to “Develop a computer program to compute income tax rate schedules for the tax year 1998.” The price is right, and we accept the job. However, we realize that the problem as stated is not clear.

REQUIREMENTS SPECIFICATION One of the most important steps in problem solving is requirements specification; that is, understanding exactly what the problem is, what is needed to solve it, what the solution should provide, and if there are constraints and special conditions.

REQUIREMENTS SPECIFICATION After interviewing the manager of QuikTax, we come up with the following requirements specification for our problem: A texpayer can determine his or her federal income tax by using the tax tables if the tax table income is less than or equal to $50,000. However, if taxable income exceeds this amount, the taxpayer must use the tax rate schudules. Tax rate schedules depend on filing status, which can be single, married filing jointly, married filing separately, and head of household.

REQUIREMENTS SPECIFICATION The following table summarizes the tax rates for the year Taxable Income Filing StatusOverBut Not OverTax Single49,300-11, % of amount over 49,300 Married filing jointly34,00082,150 5, % of amount over 34,000 82,150-18, % of amount over 82,150 Married filing separately41,075- 9, % of amount over 41,075 Head of household27,30070,450 4, % of amount over 27,300 70,450-16, % of amount over 70,450

REQUIREMENTS SPECIFICATION We would like to develop a program to do the following: 1.Prompt the user to interactively enter a taxable income amount and read it. Taxable income should not be less than $50,000. If it is, the user should be prompted to reenter a correct value. 2.Display a filing status menu that looks like the following:

REQUIREMENTS SPECIFICATION FILLING STATUS MENU: Single Married filing jointly Married filing separately Head of household

REQUIREMENTS SPECIFICATION 3. Prompt the user to enter a filing status code and read it. If the value entered less than 1 or greater than 4, the user should be prompted again to type a correct value. 4. Compute tax using the formula that corresponds to the filing status and the taxable income. 5. Output the results including taxable income, filing status, and the computed tax as follows:

REQUIREMENTS SPECIFICATION RESULTS OF COMPUTATIONS: Taxable income: Filing Status : Married filing jointly Tax :

ANALYSIS In the analysis phase we should identify the following: 1.Inputs to the problem, their form, and the input media to be used 2.Outputs expected from the solution, their form, and the output media to be used 3.Any special constraints or conditions 4.Formulas or equations to be used

ANALYSIS Input: Consists of taxable income and filing status. All inputs will be interactive, and we will use the keyboard for them. Output: Two types of output are expected from this program: the filing status menu, as shown in the requirements specification, and the final output, which consists of taxable income, filing status, and the computed income tax. Constraints: The program should not accept a taxable income value less than $50, Also, the filing status code should be 1,2,3, or 4. If the user enters any other value, the program should prompt the user to enter a value that is in the correct range. Formulas: The tax rate schedule formulas are those given in the requirements specification.

DESIGN The next step is to design a method of solution for the problem. A method of solution is a series of steps to be performed in a specific logical order. difficult step problem solution as a computer program solution in algorithm form

DESIGN 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.

DESIGN An algorithm must satisfy some requirements: 1.Unambiguousness: It must not be ambiguous. 2.Correctness: It must be correct and must solve the problem for which it is designed. 3.Finiteness: It must execute its steps and terminate in finite time. An algorithm that never terminates is unacceptable.

DESIGN Several techniques have been developed expressly for the representation of algorithms. We will discuss two of them in this chapter: pseudocoding and flowcharting.

DESIGN Pseudocoding A pseudocode language is a semiformal, English-like language with a limited vocabulary that can be used to design and describe algorithms.

DESIGN The Sequence Control Structure 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.

DESIGN Example read taxable income read filing status compute income tax print income tax OR begin read taxable income read filing status compute income tax print income tax end

DESIGN The Selection Control Structure The selection control structure defines two courses of action, depending on the outcome of a condition. A condition is an expression that, when evaluated, computes to either true or false.if condition then-partthen_part elseend_if else-part end_if

DESIGN Example If income is less than or equal to 82,150 begin compute tax = x(income ) print “Tax rate is 28%.” end else begin compute tax = x(income ) print “Tax rate is 31%.” end end_if print tax

DESIGN A nested selection structure is a basic selection structure that contains other if-end_if structures in its then_part or else_part. Example If status is equal to 1 print “Single” else if status is equal to 2 print “Married filing jointly” else if status is equal to 3 print “Married filing separately” else if status is equal to 4 print “Head of household” else print “Error in status code” end_if

DESIGN The Repetition Control Structure The repetition control structure specifies a block of one or more statements that are repeatedly executed until a condition is satisfied. while condition loop-body end_while

DESIGN Example print “Enter taxable income” read income while income is less than begin print “Enter taxable income” read income end end_while

DESIGN Divide and Conquer We can split the problem into several simpler subproblems or modules, solve each individually, and then combine these solutions into one that corresponds to the solution of the original problem. This strategy is called divide and conquer.

DESIGN We can graphically show the relationship between the original problem and its four subproblems using a diagram called a structure chart.

DESIGN compute income tax from tax schedules read and verify income read and verify filing status compute tax print income, filing status and tax This chart indicates that the original problem is solved if the four subproblems at the lower level of hierarchy are solved from left to right. To arrive at this chart, we started from top, which is the original problem, and proceeded down to the subproblems, which are its refinements; hence the term top-down stepwise refinement.

DESIGN Top-Down Stepwise Refinement of Algorithms Using Pseusocode read and verify income read and verify filing status compute tax print income, filing status, and tax

DESIGN read and verify income print “Enter taxable income” read income while income is less than begin print “Enter taxable income;>=50000” read income end end_while

DESIGN read and verify filing status print “FILING STATUS MENU:” print “Single ” print “Married filing jointly ” print “Married filing separately ” print “Head of household ” read filingStatus while filingStatus is not 1 or 2 or 3 or 4 begin print “Enter filing status; between 1-4” read filingStatus end end_while

DESIGN or read and verify filing status while entered filingStatus is incorrect ask the user to enter a correct filing status value end_while Note! Implement this logic requires the use of a flag variable.

DESIGN set correctStatusInput to “no” print filing status menu while correctStatusInput is equal to “no” begin print “Enter filing status: between 1-4” read filingStatus if filingStatus is greater than 0 if filingStatus is less than 5 set correctStatusInput to “yes” end_if end end_while

DESIGN set correctStatusInput to “no” print “FILING STATUS MENU:” print “Single ” print “Married filing jointly ” print “Married filing separately ” print “Head of household ” while correctStatusInput is equal to “no” begin print “Enter filing status: between 1-4” read filingStatus if filingStatus is greater than 0 if filingStatus is less than 5 set correctStatusInput to “yes” end_if end end_while

DESIGN compute tax if filingStatus is 1 compute tax = x(income ) else if filingStatus is 2 if income is less than or equal to compute tax = x(income ) else compute tax = x(income ) end_if else if filingStatus is 3 compute tax = x(income ) else if filingStatus is 4 if income is less than or equal to compute tax = x(income ) else compute tax = x(income ) end_if

DESIGN print income, filing status, and tax 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

DESIGN สรุป pseudo code สำหรับปัญหาใน กรณีศึกษา

DESIGN print “Enter taxable income” read income while income is less than begin print “Enter taxable income;>=50000” read income end end_while

DESIGN set correctStatusInput to “no” print “FILING STATUS MENU:” print “Single ” print “Married filing jointly ” print “Married filing separately ” print “Head of household ” while correctStatusInput is equal to “no” begin print “Enter filing status: between 1-4” read filingStatus if filingStatus is greater than 0 if filingStatus is less than 5 set correctStatusInput to “yes” end_if end end_while

DESIGN if filingStatus is 1 compute tax = x(income ) else if filingStatus is 2 if income is less than or equal to compute tax = x(income ) else compute tax = x(income ) end_if else if filingStatus is 3 compute tax = x(income ) else if filingStatus is 4 if income is less than or equal to compute tax = x(income ) else compute tax = x(income ) end_if

DESIGN 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

DESIGN Flowcharting Flowcharting is another technique used in designing and representing algorithms. It is an alternative to pseudocoding; whereas a pseudocode description is verbal, a flowchart is graphical in nature. A flowchart is a graph consisting of geometrical shapes that are connected by flow lines.

DESIGN Sequence structure statement 1 statement 2 statement 3

DESIGN Selection structure condition else-partthen-part truefalse condition then-part true false

DESIGN Repetition structure condition loop-body true false

IMPLEMENTATION We translate each step of the algorithm into a statement in that particular language and end up with a computer program. A computer program is a sequence of a finite number of statements expressed in a programming language in a specific logical order that, when executed, produce the solution for a problem.

IMPLEMENTATION เราจะเรียนภาษา C ในวันถัดไป Programming Error 1.Design errors: เขียนผิด logic 2.Syntax errors: เขียนผิดไวยากรณ์ ของภาษา 3.Run-time errors: โปรแกรมหยุด ทำงาน เช่น หารด้วย 0 หรือ คำตอบไม่ถูกต้อง

TESTING AND VERIFICATION Program verification is the process of ensuring that a program meets user requirements. One of the techniques that can be used for program verification is program testing. Program testing is the process of executing a program to demonstrate its correctness.

TESTING AND VERIFICATION When you begin testing your program, you may come across some run-time errors. Naturally, you debug them and run your program again. However, even output that seems correct is not a guarantee that your program is completely correct. A program must be tested using a sufficiently large sample of carefully designed test data sets such that every logical path in the program is traversed at least once. You must continue to test your program until you are sure that all statements in it are functioning correctly.

TESTING AND VERIFICATION Example Test Data Set Income Filing StatusExplanation 49, Income must be greather than or equal to , Filing status must be greather than zero 50, Filing status must be less than 5 50, Testing the tax formula for filing status 1 82, Testing the first tax formula for filling status 2 82, Testing the second tax formula for filing status 2 50, Testing the tax formula for filing status 3 70, Testing the first tax formula for filing status 4 70, Testing the second tax formula for filing status 4

DOCUMENTATION Now that you have a working, tested program you are tempted to call it quits and look for new challenges. Please don’t! For several reasons, you are not done yet: 1.You are likely to return to this program sometime in the future to use it again, or you may want to use part of it in developing the solution for a similar problem. 2.If you have developed this program for a client’s use, he or she will need some information so that in your absence the program can be used. 3.If you are working for a company and have developed this program for the company’s software library, some other programmer may be assigned to maintain it or to make additions to it. 4.You may eventually discover some errors in the program, and you may be required to correct them.

DOCUMENTATION Documentation consists of these elements: 1. A concise requirements specification 2. Descriptions of problem inputs, expected outputs, constraints and application 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 user’s guide explaining to nonprogrammer users how the program should be used (optional)