Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Problem Solving Techniques

2 Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language and generate the instructions from the computer from that code. n The program description is called source code or C code. n Compiled program is called object code or machine code

3 Problem solving n Is the process of transforming the description of a problem into the solution of the problem by using our knowledge of the problem domain and relying on our ability to select and use appropriate problem-solving strategies, techniques, and tools.

4 Method for Problem Solving n Requirement Specification n Analysis n Design n Implementation n Testing and Verification n Documentation Also known as Software development methods or Software Life Cycle

5 Requirement Specification –Eliminated ambiguities in the problem statement –understanding exactly what the problem is –what needed to solve it –what are the solution should provide –any constraint or special conditions n how precisely you define the problem is depend on degree of familiarity on the problem.

6 Analysis n identified problem inputs, outputs and collected information about the inputs n Formulas or equations to be used. n If you can acquired a clear understanding of the problem and have a precise requirements specification usually will make analysis phase easy

7 Design n developed a series of steps with a logical order which, when applied would produce the output of the problem n using algorithms represented as flowchart or pseudocode

8 Implementation n Implementation of the algorithm in a programming language. n Translate algorithm into a statement of programming language n 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

9 Implementation - programming errors n There are three types of programming errors –design, syntax and run-time error n design errors occur during the analysis, design, and implementation phases –incorrect method, mistakes on translating algorithm & design erroneous data –difficult to detect

10 Syntax errors n Are violations of syntax rules, which define how the elements of a programming language must be written –occur during implementation phase –detected by compiler –error message display

11 Run-time errors n Are detected by the computer while your program is being executed. n Cause by instruction that require the computer to do something illegal such as attempting to store inappropriate data or divide a number by zero

12 What is a program ? n Is a set of instructions for a computer n receive data, carry out the instructions, and produce useful results

13 Algorithms n A clear and precise procedure for solving a given problem, and although the word algorithm evolved from the name of 8th century Arabian mathematician, the idea pre-dates him by over a millennia. In order to solve a problem on a computer, the corresponding algorithm must exist as a series of well-defined steps. A lot of research in computer science is involved with finding algorithms which : –solve new problems, –solve old problems more efficiently, or –produce approximate solutions to problems for which no known algorithm exists.

14 Algorithm Design n 4 steps must be carried out –understand the problem –get an idea of how an algorithmic procedure might solve the problem –formulate the algorithm and represent it as a program –evaluate the program for accuracy and for its potential as a tool for solving other problems.

15 Pseudocoding n Is a semiformal, English-like language with a limited vocabulary that can be used to design and describe algorithms n can be used for –designing algorithms –communicating algorithms as programs –implementing algorithms as programs –debugging logic errors in program –documenting programs for future maintenance and expansion purposes

16 Pseudocode n Have limited vocabulary n be easy to learn n produce simple, English -like narrative notation n be capable of describing all algorithms, regardless of their complexity

17 Coventions For Pseudocoding n Should includes keywords that describe operations and some appropriate, English-like descriptions of operands n each pseudocode should be written on a separate line. If a statement requires more than one line, the continuation lines should be indented n the statement that make up a sequence control should be start with compute, set or initialize n statements in a sequence structure can be grouped into a block by enclosing them between the keywords begin and end. Such statement should be indented. n Terminate each if statement with the keyword end_if

18 Coventions For Pseudocoding n For the repetition control structure, use the while statement and indent the loop-body. Terminate each while statement with the keyword end_while n All words in pseudocode statement must be as easy as possible for nonprogrammers to understand

19 Flowchart n Flowchart is simply a graphical method for representing the program’s flow, and is language independent; n Each box in a flowchart represents a particular type of instruction, action or data store, and arrows are drawn between the boxes to show hoe the program flow occurs between statements. Sometimes the arrows are labeled with text to show whether a decision was true or false.

20 Basic Control & Looping Concepts n If …then…else n while end n do ….while n for...next n loop …until

21 Examples of Problem Solving

22 Obtain 2 numbers from Keyboard, compute the sun of the numbers and display the results n Input the first number n Input the second number n Add the two numbers n Output the sum

23 Obtain two numbers from the keyboard, and determine and display which (if either) is the larger of the two numbers Input the first number from the keyboard Input the second number from the keyboard If the first number is greater than the second number print it Else if the second number is greater than the first number print it Else print a message starting that the numbers are equal End If

24 Obtain a series of +ve number from the keyboard, and determine and display the sum of the numbers. Assume that the user types the sentinel value -1 to indicate “end of data entry” do Input a value from the keyboard while value is < 0 and value not = -1 While the input value is not equal to -1 add the number to the running total do input the next number while value < 0 and not equal = -1 End While Print the sum

25 More examples…will continue on next lecture


Download ppt "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."

Similar presentations


Ads by Google