1 / 25

What is a Problem?

What is a Problem?. A problem is a circumstance for which we need to develop a solution to get to some goal or provide the means to some end. Types of Problems. Informal Problems

Télécharger la présentation

What is a Problem?

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What is a Problem? • A problem is a circumstance for which we need to develop a solution to get to some goal or provide the means to some end. Pamela Brauda

  2. Types of Problems • Informal Problems • we do NOT necessarily find solutions by precisely specifying the initial conditions, the desired results, or the actions (process) by which we achieve the desired results Pamela Brauda

  3. Types of Problems • Formal Problems – the kind that can be solved by writing a program for a computer • Problems of synthesis: have specific initial conditions and specific plans of actions (processes), but specify only the general form of the result {Trip: Jax, drive, West Coast} • Problems of analysis: the initial conditions and results are known, but not a specific plan of action (process) {Trip: Jax, L.A.} Pamela Brauda

  4. Types of Problems • ***All problems solved with the aid of computers are problems of synthesis • ***The programmer transforms the problem from one of analysis to one of synthesis Pamela Brauda

  5. Solving a Problem • 1. Understand the problem • 2. Devise a plan – major steps to accomplish our goal • Divide the problem into segments • Design a solution • Consider alternatives and refine solution Pamela Brauda

  6. Solving a Problem • 3. Carry out the plan (implement)4. Look back • Did you really solve the problem? If not, return to Step 1 Pamela Brauda

  7. 7 Steps in Program Development • Define the problem • Use a Defining Diagram • Inputs • Outputs • Processing steps to produce the required output Pamela Brauda

  8. 7 Steps in Program Development • Outline the solution • Break the problem up into smaller steps • Major processing steps involved • Major subtasks • Major control structures (e.g. repetition loops) • Major variables and record structures • Mainline Logic • Use a hierarchy or structure chart Pamela Brauda

  9. 7 Steps in Program Development • Develop the outline into an algorithm • An algorithm is a set of precise steps that describe exactly the tasks to be performed and the order in which they are to be carried out • Think ‘recipe for making French toast as given to a robot cook’ • Pseudocode is how we represent algorithms Pamela Brauda

  10. 7 Steps in Program Development • Test the algorithm for correctness • Desk checking to identify logic errors • Walk through each step of the algorithm • Keep track of all major variables • Use sample data that tests boundary conditions Pamela Brauda

  11. 7 Steps in Program Development • Code the algorithm into a specific programming language • NEVER approach the keyboard without a plan • Code-as-you-go results in wasted time and effort Pamela Brauda

  12. 7 Steps in Program Development • Run the program with test data • Syntax errors show up at compile time • Typos, punctuation, grammar • Logic errors appear at run time • 2 + 3 = 6??? • Sometimes undetected if testing isn’t thorough Pamela Brauda

  13. 7 Steps in Program Development • Document and maintain the program • External documentation • Hierarchy or structure charts, pseudocode, test data and sample results • Internal documentation • ‘Flower Boxes’ at the beginning of each module or function • Inline comments describing the variables and what should be happening • Sample program following COBOL Standards Pamela Brauda

  14. Structured Programming • Top-down Development • Start out with a general solution • Break down the solution into more detailed steps (modules) • Step-wise refinement – moving from general to specific Pamela Brauda

  15. Structured Programming • Modular Design • Group similar tasks together • Reading a file, checking for end of file, verifying the item read is valid • Printing page headings or totals • Enables several people to work as a team, with each person working on a separate function • Input/Output • Sorting, Updating • Calculating Pamela Brauda

  16. Structured Programming • The Structure Theorem • Eliminated the GOTO statement • All programs can be written with 3 basic control structures • Sequence • Selection, or IF-THEN-ELSE • Repetition, or DO-WHILE Pamela Brauda

  17. Calculator Turn on Press 1st number Press ‘+’ Press 2nd number Press ‘=‘ Computer Input 1st number Input 2nd number Add Print result (sum) Algorithm to add two numbers Pamela Brauda

  18. Pseudocode • Structured English used to express an algorithm • Use indentation for logical flow • One instruction per line • Six basic algorithm structures – roughly matching the six basic computer operations Pamela Brauda

  19. Pseudocode • Getting data into the computer • Read student name {from a file} • Get system date {from the system} • Read number_1, number_2 {file} • Get tax_code {from the keyboard} Pamela Brauda

  20. Pseudocode • Getting results from the computer • Print ‘Program Completed’ {printer} • Write customer record to file {disk} • Display ‘End of Data’ {screen} Pamela Brauda

  21. Pseudocode • Doing the math • Add number to total • total = total + number • Compute C = (F – 32) * 5/9 • Symbols okay to use: +, -, *, /, (, ) Pamela Brauda

  22. Pseudocode • Assigning a value to a variable • Set Count to 0 • Initialize Totals to zero • Total = cost + tax Pamela Brauda

  23. Pseudocode • Comparing two variables • If-Then-Else • IF Student is part-time THEN • Add 1 to part-time count • ELSE • Add 1 to full-time count • ENDIF Pamela Brauda

  24. Pseudocode • Repeat a group of actions: DO-WHILE, FOR Loop, DO Loop • WHILE student_total < 50 DO • Read student record • Print student name, address to report • Add 1 to student_total • ENDWHILE Pamela Brauda

  25. Developing an algorithm • Define the problem Pamela Brauda

More Related