1 / 63

Overview problem Solving & Computer Programming

Overview problem Solving & Computer Programming. What is Computer??. A programmable electronic device that can.. Store Retrieve Process DATA.

gblack
Télécharger la présentation

Overview problem Solving & Computer Programming

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. Overviewproblem Solving & Computer Programming

  2. What is Computer??

  3. A programmable electronic device that can.. • Store • Retrieve • Process DATA

  4. A computer is a device that accepts information / data by input, manipulates it for some result based on a program / sequence of instructions on how the data is to be processed, generate result as output and store in their storage as needed.

  5. DATA????? • Computers manipulate data • When you write a program for a computer, you specify the properties of the data and the operations that can be applied to it. • Data is information in a form the computer can use-for example, numbers and letters.

  6. Data comes in many different forms: • letters • Words • integer numbers • real numbers • Dates • times • coordinates on a map, and so on….

  7. We can conclude that.. • any kind of information can be represented as data, or as a combination of data and operations on it. • Each kind of data in the computer is said to have a specific data type . For example • if we say that two data items are of type Integer, we know that they are represented in memory and we can apply arithmetic operations to them.

  8. Key Points • computer -A programmable device that can store, retrieve, and process data • Data -Information in a form a computer can use. • Information- Any knowledge that can be communicated. • Data type- The specification of how the information is represented in the computer as data and the set of operations that can be applied to it.

  9. Computer program: Data type specification and a set of instructions for carrying out operations that are used by a computer to solve a problem. • Computer programming:The process of specifying the data types and the operations for a computer to apply on data in order to solve a problem. • How do we write a Program????

  10. Do you think that a computer is a intelligent machine??

  11. A computer is not intelligent. • It cannot analyze a problem and come up with a solution. • A human (the programmer) must do it. • The Programmer must 1.analyze the problem 2.develop the instructions for solving the problem 3.And then have the computer to carry out the instructions.

  12. What’s the advantage of using a computer if it cannot solve problems??? • Once we have written a solution for the computer, the computer can repeat the solution very quickly and consistently, again and again. • The computer frees people from repetitive and boring tasks.

  13. To write a program for a computer to follow, we must go through a two-phase process: • Problem Solving • Implementation

  14. Problem-Solving Phase • Analysis and Specification: Understand (define) the problem and what the solution must do. • General Solution (Algorithm): Specify the required data types and the logical sequences of steps that solve the problem. • Verify: Follow the steps exactly to see if the solution really does solve the problem.

  15. Implementation Phase • Concrete Solution (Program). Translate the algorithm (the general solution) into a programming language. • Test: Have the computer follow the instructions. Then manually check the results. If you find errors, analyze the program and the algorithm to determine the source of the errors, and then make corrections.

  16. Once a program has been written, it enters into third phase: maintenance. • Use: Use the program. • Maintain: Modify the program to meet changing requirements.

  17. Analysis and specification General solution(algorithm) Concrete solution (program) Verify Test Maintenance phase

  18. Algorithm • The programmer begins the programming process by analyzing the problem, breaking it into manageable pieces, and developing a general solution for each piece called an algorithm. • An algorithm is a written or verbal description of a logical sequence of actions applied to objects. • Examples: Recipes, instructions, and directions are all examples of algorithms that are not programs.

  19. When you start your car, you follow a step-by-step procedure. The algorithm might look something like this: • Insert the key. • Make sure the transmission is in Neutral. • Turn the key to the start position. • If the engine starts within six seconds, release the key to the ignition position. • If the engine doesn’t start in six seconds, release the key wait ten seconds, and repeat Steps 3 through 5 but not more than five times. • If the car doesn’t start, call the mechanic.

  20. Without the phrase “but not more than five times” in Step 5, you could be trying to start the car forever. Why???? Because…. • if something is wrong with the car, repeating Steps 3 t0 5 over and over will not start it. • Infinite loop • No termination for your Algorithm. • Your Algorithm should terminate at some point.

  21. So we can define Algorithm as follows • Algorithm :Sequence of Instructions for solving a problem in a finite amount of time using a finite amount of data.

  22. Now…. Let’s move to a Software Industry….

  23. Program Development Steps • Defining or Analyzing the problem • Design (Algorithm) • Coding • Documenting the program • Compiling and Running the Program • Testing and Debugging • Maintenance

  24. Analyzing or Defining the Problem • The problem is defined by doing a preliminary investigation. Defining a problem helps us to understand the problem clear. It is also known as Program Analysis.

  25. Tasks in defining a problem: • Specifying the input requirements • Specifying the output requirements • Specifying the processing requirements

  26. Specifying the input requirements • Determine the inputs required and source of the data. The input specification is obtained by answering the following questions: • What specific values will be provided as input to the program? • What format will the values be? • For each input item, what is the valid range of values that it may assume?

  27. Specifying the output requirements • Describe in detail the output that will be produced. The output specification is obtained by answering the following questions: • What values will be produced? • What is the format of these values? • What specific annotation, headings, or titles are required in the report? • What is the amount of output that will be produced?

  28. Specifying the Processing Requirements • Determine the processing requirements for converting the input data to output. The processing requirement specification is obtained by answering the following questions: • What is the method (technique) required in producing the desired output? • What calculations are needed? • What are the validation checks that need to be applied to the input data?

  29. Data validation • In computer science, data validation is the process of ensuring that a program operates on clean, correct and useful data. •  It uses "validation rules" that check for correctness, meaningfulness, and security of data that are input to the system. • The simplest data validation verifies that the characters provided come from a valid set. For example, telephone numbers should include the digits and possibly the characters +, -, (, and )(plus, minus, and parentheses). A more sophisticated data validation rule would check to see the user had entered a valid country code, i.e., that the number of digits entered matched the convention for the country or area specified.

  30. Data type checks: Checks the data type of the input and give an error message if the input data does not match with the chosen data type, e.g., In an input box accepting numeric data, if the letter 'O' was typed instead of the number zero, an error message would appear. • Format or picture check: Checks that the data is in a specified format (template), e.g., dates have to be in the format DD/MM/YYYY. • Logic check: Checks that an input does not yield a logical error, e.g., an input value should not be 0 when it will divide some other number somewhere in a program. • Range check: Checksthat the data lie within a specified range of values, e.g., the month of a person's date of birth should lie between 1 and 12.

  31. Incorrect data validation can lead to data corruption or a security vulnerability. Data validation checks that data are valid, sensible, reasonable, and secure before they are processed.

  32. Design • A design is the path from the problem to a solution in code. A well designed program is more likely to be: • Easier to read and understand later • Less of bugs and errors • Easier to extend to add new features

  33. Modular Design • Once the problem is defined clearly, several design methodologies can be applied. An important approach is….. Top-Down programming design…. • It is a structured design technique which breaks up the problem into a set of sub-problems called Modules.

  34. Guidelines: • A problem is divided it into smaller logical sub-problems, called Modules • Each module should be independent and should have a single task to do. • Each module can have only one entry point and one exit point, so that the logic flow of the program is easy to follow. • When the program is executed, it must be able to move from one module to the next in sequence, until the last module is executed. • Each module should be of manageable size, in order to make the design and testing easier

  35. Top-down design has the following advantages: • Breaking up the problem into parts helps us to clarify what is to be done. • At each step of refinement, the new parts become more focused and, therefore, easier to design • Modules may be reused. • Breaking the problem into parts allows more than one person to work on the solution simultaneously.

  36. Algorithm (Developing a Solution technique) An algorithm must be: • Definite • Finite • Precise and Effective • Implementation independent

  37. Definite??? • Clearly stated or decided • Not doubtful • True or real • unambiguous

  38. Precise and Effective • Exactness and accuracy of solution. • Every aspect must be in detail or careful about the details of the solution. • Effective: Successful in producing a desired result or intended result.

  39. Implementation independent • whatever it is that an Algorithm is doing, it must do the same thing on whatever the hardware used to execute the algorithm. • Same thing with Programming language.

  40. Example: Find the factorial of a given number • Input: Positive valued integer number • Output: Factorial of that number • Process: Solution technique which transforms input into output. Factorial of a number can be calculated by the formula n! = 1*2*3*4….*n

  41. Algorithm for finding factorial of a given number • Step 1: Start • Step 2: Initialize factorial to be 1, i to be 1 • Step 3: Input a number n • Step 4: Check whether the number is 0. If so report factorial is 1 and goto step 9 • Step 5: Repeat step 6 through step 7 n times • Step 6: Calculate factorial = factorial * i • Step 7: Increment i by 1 • Step 8: Report the calculated factorial value • Step 9: Stop

  42. Pseudo Code • Pseudo code is an informal high-level description of an algorithm that uses the structural conventions of programming languages, but omits language-specific syntax. • It is an outline of a program written in English or the user's natural language.

  43. Example : Pseudo Code for finding factorial of a given number • Step 1: START • Step 2: DECLARE the variables n, fact, i • Step 2: SET variable fact =1 and i =1 • Step 3: READ the number n • Step 4: IF n = 0 then • Step 4.1: PRINT factorial = 1 • Step 4.2: GOTO Step 9 • Step 5: WHILE the condition i<=n is true, repeat Step 6 through Step 7 • Step 6: COMPUTE fact = fact * i • Step 7: INCREMENT i by 1 • Step 8: PRINT the factorial value • Step 9: STOP

  44. Flowchart • Flowchart is a diagrammatic representation of an algorithm. It uses different symbols to represent the sequence of operations, required to solve a problem. It serves as a outline or a logical diagram of the solution to a problem.

  45. Symbols • Represents Start, End

  46. Represents input, output data

  47. Represents Process(actions ,calculations)

  48. Represents Decision making

  49. Represents Pre-defined Process

  50. Represents off page connector which are used to indicate that the flow chart continues on another page. Page numbers are usually placed inside for easy reference

More Related