Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 Problem Solving On A Computer 2.1 Problem Solving Steps Solving a problem on a computer requires steps similar to those followed when solving.

Similar presentations


Presentation on theme: "Chapter 2 Problem Solving On A Computer 2.1 Problem Solving Steps Solving a problem on a computer requires steps similar to those followed when solving."— Presentation transcript:

1 Chapter 2 Problem Solving On A Computer 2.1 Problem Solving Steps Solving a problem on a computer requires steps similar to those followed when solving the problem manually. The engineer must still formulate a correct solution to the problem, acquire the necessary data for the solution, and assess the validity of the results. The basic steps involved in solving a programming problem are the following:

2 1. Problem definition 2. Problem analysis 3. Algorithm design 4. Program development 5. Program verification 6. Documentation 7. Maintenance and modification 2.2 Algorithms This consists of series of step-by-step instructions for the solution of the problem. The design of a good algorithm is an important factor in program development.

3 Example Average of Three Number Problem statement: Write an algorithm to read in three numbers and to compute and print the average. Solution: The steps to solve the problem are as follows: 1. Input the data items into the variables a, b, and c. 2. Compute the sum of a, b, and c and save the result in the variable sum. 3. Divide sum by 3 and save the result in the variable average. 4. Print the values of a, b, c and average.

4 2.3 Flowcharts For complex problem step-by-step English descriptions are inadequate for describing algorithms. Two common methods for describing algorithms are flowcharts and pseudocode. A clowchart is a pictorial description of an algorithm. The flowchart outlines the structure and logic of the algorithm and the sequence of a set operations to be followed in solving the problem. A flowchart is composed of a set of standard symbols, each of which is unique in shape and represents a particular type of operation.

5 Symbol Name Flowlines Terminal In/Out Process Decision

6 2.4 Pseudocode Pseudocode consists of a series of statement and instructions that, when followed, will solve the problem. Pseudocode uses a mix of English, mathematical notation, and a set of special words to describe the operations of the algorithm. Some of the more commonly used keywords are Begin, End, Read, Print, If, Else, Elseif, While, Do, Endwhile and Enddo. Example Largest of Three Numbers Problem statement: Write the pseudocode and flowchart representation of the algorithm for computing the largest of three numbers, a, b and c.

7 Solution: The pseudocode representation is given as BEGIN READ a,b,c xmax = a IF xmax < b THEN xmax = b ENDIF IF xmax < c THEN xmax = c ENDIF PRINT a,b,c, xmax END

8 Homework: Write the flowchart to solve the problem of the largest of three numbers ( Due date is going to be the next time) 2.5 Top Down Design 2.6 Modular Design 2.7 Structured Programming 2.8 Debugging Techniques 2.9 Variables and Data Types : Please read this topic at home on page number(p74 - p79)

9 Any Questions


Download ppt "Chapter 2 Problem Solving On A Computer 2.1 Problem Solving Steps Solving a problem on a computer requires steps similar to those followed when solving."

Similar presentations


Ads by Google