ME 142 Engineering Computation I Fundamentals of Procedural Computer Programming.

20
ME 142 Engineering Computation I Fundamentals of Procedural Computer Programming

Transcript of ME 142 Engineering Computation I Fundamentals of Procedural Computer Programming.

ME 142Engineering Computation I

Fundamentals of Procedural Computer Programming

Key Concepts

Algorithm Development

Flowcharting

Algorithm

What is an Algorithm?

Algorithm

A set of instructions for solving a problem A step-by-step procedure for obtaining a solution to

a given class of problems Example:

recipe

Algorithm

Most programs follow the following simplified algorithm: Input Process Output

Algorithm Example

Develop the algorithm to find the area of a rectangle: Input:

Enter length, width Process:

Multiply length times width to obtain areaArea = length * width

Output:Display area

Flowchart

What is a Flowchart?

Flowcharts

A flowchart is a pictorial representation of an algorithm. Steps of the algorithm are enclosed in boxes of

various shapes. The flow of control is indicated by lines

connecting the boxes. An arrow is placed on each line to indicate

direction of flow.

Standard Flowcharting Symbols

Terminator box. Used to show both the start and stop of an algorithm.

Operation box. Used for computations, assignment statements, definitions, etc.

Input/Output box. Used to indicate items to be read or written by the algorithm.

Standard Flowcharting Symbols

Decision box. Used to pose questions in determining which branch to follow for the next instruction.

Connector circle. Used to connect parts of the flowchart from page to page, etc.

Flowcharting ExampleArea of a Rectangle

Start

Enterlength, width

area =length * width

Displayarea Stop

Flowcharting Guidelines

Flowcharts are written to be a guide for writing actual code. The flowchart should have just enough detail for you to code from.

Think in terms of small, sequential operations What needs to be done What order, i.e., what must come first, etc

Start

Read x

I=1P=1

P=P*I

I=x?I=I+1

Display P Stop

No

Yes

What does the following flowchart do?

Example Flowchart

Flowchart a student’s possible response to getting up for class following a late night study session

Review Questions

I-Clicker QuestionAlgorithms

The statement, Area = length * width, is an example of which of the following components of an algorithm:

A. Input

B. Process

C. Output

D. None of the Above

I-Clicker QuestionFlowcharts

Which of the following flowchart symbols would be used to represent an IF statement in a program, where a decision must be made:

A B C D

Homework Help ‘n Hints