Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

2 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

3 กรณีศึกษา (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.

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

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

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

7 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:

8 REQUIREMENTS SPECIFICATION FILLING STATUS MENU: Single ---- 1 Married filing jointly ---- 2 Married filing separately ---- 3 Head of household ---- 4

9 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:

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

11 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

12 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,000.00. 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.

13 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

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

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

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

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

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

19 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

20 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

21 DESIGN Example If income is less than or equal to 82,150 begin compute tax = 5100.00+0.28x(income-34000.00) print “Tax rate is 28%.” end else begin compute tax = 18582.00+0.31x(income-82150.00) print “Tax rate is 31%.” end end_if print tax

22 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

23 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

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

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

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

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

28 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

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

30 DESIGN read and verify filing status print “FILING STATUS MENU:” print “Single ---- 1” print “Married filing jointly ---- 2” print “Married filing separately ---- 3” print “Head of household ---- 4” 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

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

32 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

33 DESIGN 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: 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

34 DESIGN compute tax if filingStatus is 1 compute tax = 11158.50+0.31x(income-49300.00) else if filingStatus is 2 if income is less than or equal to 82150 compute tax = 5100.00+0.28x(income-340000.00) else compute tax = 18582.00+0.31x(income-82150.00) end_if else if filingStatus is 3 compute tax = 9291.00+0.31x(income-41075.00) else if filingStatus is 4 if income is less than or equal to 70450.00 compute tax = 4095.00+0.28x(income-27300.00) else compute tax = 16177.00+0.31x(income-70450.00) end_if

35 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

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

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

38 DESIGN 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: 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

39 DESIGN if filingStatus is 1 compute tax = 11158.50+0.31x(income-49300.00) else if filingStatus is 2 if income is less than or equal to 82150 compute tax = 5100.00+0.28x(income-340000.00) else compute tax = 18582.00+0.31x(income-82150.00) end_if else if filingStatus is 3 compute tax = 9291.00+0.31x(income-41075.00) else if filingStatus is 4 if income is less than or equal to 70450.00 compute tax = 4095.00+0.28x(income-27300.00) else compute tax = 16177.00+0.31x(income-70450.00) end_if

40 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

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

42 DESIGN Sequence structure statement 1 statement 2 statement 3

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

44 DESIGN Repetition structure condition loop-body true false

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

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

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

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

49 TESTING AND VERIFICATION Example Test Data Set Income Filing StatusExplanation 49,000.00-Income must be greather than or equal to 50000 50,000.000Filing status must be greather than zero 50,000.005Filing status must be less than 5 50,000.001Testing the tax formula for filing status 1 82,150.002Testing the first tax formula for filling status 2 82,151.002Testing the second tax formula for filing status 2 50,000.003Testing the tax formula for filing status 3 70,450.004Testing the first tax formula for filing status 4 70,451.004Testing the second tax formula for filing status 4

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

51 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)


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

Similar presentations


Ads by Google