32
How Computers Solve Problems • Computers also use Algorithms to solve problems, and change data into information • Computers can only perform one simple step at a time • Complex “Human” Algorithms must be broken down into simple step-by- step instructions BEFORE they can be translated into computer code

Final Flowchart

Embed Size (px)

Citation preview

Page 1: Final Flowchart

How Computers Solve Problems

• Computers also use Algorithms to solve problems, and change data into information

• Computers can only perform one simple step at a time

• Complex “Human” Algorithms must be broken down into simple step-by-step instructions BEFORE they can be translated into computer code

Page 2: Final Flowchart

Algorithm

• It is the set of instructions to solve any problem. These are the steps followed after one another.

• These steps for solving a problem, to process some input for obtaining the desired result or output is called ALGORITHM

Page 3: Final Flowchart

Characteristics

• It should have input• Steps that are included in the algorithm should

be executable by the computer.• Each step must be finite and small and

unambiguous• Every step of algorithm should yield some

result.• Should be written in a very simple language• Algorithm validation

Page 4: Final Flowchart

Algorithm :Temperature Conversion

1. Read the numerical value of C

2. Calculate F using formula

F=9/5C+32

3. Write numerical value of C

4. Terminate the process

Page 5: Final Flowchart

Algorithm: Average of two numbers

1. Input: Two numbers

2. Add the two numbers

3. Divide the result by 2

4. Return the result by step 2

5. End

Page 6: Final Flowchart

Algorithm: Change a numeric grade to a letter grade.

Input: One number

1. if (the number is between 90 and 100, inclusive)then– 1.1 Set the grade to “A”

– End if

2. if (the number is between 80 and 89, inclusive)then– 2.1 Set the grade to “B”

– End if

Page 7: Final Flowchart

3.if (the number is between 70 and 79, inclusive)then– 3.1 Set the grade to “C”– End if

4. if (the number is between 60 and 69, inclusive)then– 4.1 Set the grade to “D”– End if

5. If (the number is less than 60)then– 5.1 Set the grade to “F”– End if

6. Return the grade– End

Page 8: Final Flowchart

FindLargestInput: 1000 positive integers

1. Set Largest to 02. Set Counter to 03. while (Counter less than 1000)

3.1 if (the integer is greater than Largest) then 3.1.1 Set Largest to the value of the integer

End if 3.2 Increment CounterEnd while

4. Return LargestEnd

Algorithm:Algorithm: Find largest of 1000 numbersFind largest of 1000 numbers

Page 9: Final Flowchart

FactorialInput: A positive integer num

1. Set FactN to 12. Set i to 13. while (i is less than or equal to num)

3.1 Set FactN to FactN x I 3.2 Increment iEnd while

4. Return FactNEnd

Algorithm :Algorithm : Iterative factorialIterative factorial

Page 10: Final Flowchart

1. Start 2. Read the roll number and marks of 1 student. This is the

highest marks found so far as marks of only one student has been read

3. Is there any more student in the class4. If yes, then go to step 5 .If not ,then goto step 85. Read next roll number and its marks .Compare the marks of

this next roll number with the highest marks find so far6. If marks read in step 5 is greater than the highest marks found

so far , then erase the previously noted highest marks , and replace it by the marks read in step 5 .Also replace the roll number, if marks of step 5 are less than the highest marks, then do nothing.

7. Repeat the step 3 through 5 till all the roll numbers of class have been entered.

8. Print the roll number of the student with the highest marks and percentage of the student.

9. Stop

Page 11: Final Flowchart

7. Repeat the step 3 through 5 till all the roll numbers of class have been entered.

8. Print the roll number of the student with the highest marks and percentage of the student.

9. Stop

Page 12: Final Flowchart

Problem Solving

• Problem Solving is the ability to understand what you have, what you want, and creating a set of instructions to change what you have into what you want

• Good Problem Solving Skills are based on knowledge, experience and logic

• Good Programmers NEVER make assumptions

Page 13: Final Flowchart

Flowcharts and Pseudo Code

• A “Standard” way of describing an algorithm must exist if we expect our solution to be understood by others easily

• There are two standards in programming:– FLOWCHARTS– PSEUDOCODE– ACTUAL CODE

Page 14: Final Flowchart

Flowcharts

• A Flowchart is a Visual Representation of an algorithm

• A Flowchart uses easy-to-understand symbols to represent actions on data and the flow of data

• Flowcharts aid in breaking down a problem into simple steps

Page 15: Final Flowchart

Advantages

• Each symbol denotes the instruction• Pictorial representation it becomes easy to understand

and explain the problem.• It gives clear picture of flow of data in any program• It helps the programmer to determine the type of

logic control to be used in the program• It is easy to detect the error with the help of flow

chart• It serves as a guiding document for program writing

or coding

Page 16: Final Flowchart

Limitations

• Time consuming and laborious too especially for complex problems

• Redrawing is even more difficult and time consuming.

• Difficult to include new step in the existing flowchart

• If an algorithm has complex branches and loops , flowchart become very difficult to draw.

Page 17: Final Flowchart

Pseudo Code

• “Pseudo” means “pretend” or “false”

• Pseudo Code is pretend or false computer code; generic English-like terms that are somewhat like computer code

• Pseudo Code is not as standardized as flowcharts, and does not facilitate the breaking down of problems as well as a flowchart does

Page 18: Final Flowchart

Tips on Writing Good Pseudo Code• Use indention for improved clarity

• Do not put “code” in pseudo code – make your pseudo code language independent

• Don’t write pseudo code for yourself – write it in an unambiguous fashion so that anyone with a reasonable knowledge can understand and implement it

• Be consistent

• Prefer formulas over English language descriptions

Page 19: Final Flowchart

The Three Computer Programming Constructs

• Any problem, regardless of how complex, can be broken down into three basic CONSTRUCTS

– SEQUENCE

– SELECTION

– ITERATION

Page 20: Final Flowchart

THREE CONSTRUCTSTHREE CONSTRUCTSTHREE CONSTRUCTSTHREE CONSTRUCTS

Page 21: Final Flowchart

Three constructs

Page 22: Final Flowchart

Flowcharts for three constructs

Page 23: Final Flowchart

Pseudocode for three constructs

Page 24: Final Flowchart

Start or stop

Process

Input or output

Connector

Decision

Flow line

Off-page connector

Flowchart Elements

Page 25: Final Flowchart

Flowchart and the selection control structure

Page 26: Final Flowchart

Simple IF statement

Account_balance <

$300?

Service_charge = $5 Service_charge = $2

T F

Page 27: Final Flowchart

Null ELSE statement

x<0

X= -x

T

F

Page 28: Final Flowchart

Combined IF statement

Student = P/T ANDGender =

F ?

Increment Female_part_time_count

T

F

Page 29: Final Flowchart

Nested IF statement

IncrementCounter_A

Record

Code =`A‘ ?

IncrementCounter_B

IncrementCounter_C

IncrementError_counter

Record

Code =`A‘ ?

Record

Code =`A‘ ?

T

T

T

F

F

F

Page 30: Final Flowchart

Case Structure

CaseOf

variable

Statement_a Statement_b Statement_c Statement_d

Value 1 Value 2 Value 3 Value 4

Page 31: Final Flowchart

Summation

More numbers

Page 32: Final Flowchart

Product