Pseudocode

3,528 views

Published on

hello

Published in: Education, Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,528
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
130
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Pseudocode

  1. 1. How to write pseudocode There are six basic computer operations 1. A computer can receive information Read (information from a file) Get (information from the keyboard) 2. A computer can put out information Write (information to a file) Display (information to the screen) 3. A computer can perform arithmetic Use actual mathematical symbols or the words for the symbols Add number to total Total = total + number +, -, *, / Calculate, Compute also used 4. A computer can assign a value to a piece of data 3 cases To give data an initial value Initialize, Set To assign a value as a result of some processing ‘=’ * x = 5 + y To keep a piece of information for later use Save, Store 5. A computer can compare two piece of information and select one of two alternative actions IF condition THEN Some action ELSE Alternative action ENDIF 6. A computer can repeat a group of actions WHILE condition (is true) Some action ENDWHILE FOR a number of times Some action ENDFOR
  2. 2. The Structure Theorem (and the pseudocode we use to represent the control structures) It is possible to write any computer program by using only three basic control structures: sequence, selection, repetition. Sequence Execution of one step after another. This is represented as a sequence of pseudocode statements: Statement 1 Statement 2 Statement 3 Example: Read three numbers Add three numbers Display total of three numbers Selection Presentation of a condition and the choice between two actions, the choice depending on whether the condition is true or false. This construct represents the decision making abilities of the computer to compare two pieces of Information and select one of two alternative actions. In pseudocode, selection is represented by the keywords IF, THEN, ELSE and ENDIF IF condition p is true THEN Statement in true case ELSE Statement in false case ENDIF Example: IF student is part-time THEN Add one to part_time_count ELSE Add one to full_time_count ENDIF
  3. 3. A variation – We don’t need the ELSE structure – The null ELSE IF condition p is true THEN Statement in true case ENDIF Repetition Presentation of a set of instructions to be performed repeatedly, as long as a condition is true. WHILE condition p is true Statement(s) to execute ENDWHILE The condition is tested before any statements are executed. It is imperative that at lease one statement within the statement block alter the condition and eventually render it false, otherwise the logic may result in an endless loop. Example: Set student total to 0 WHILE student total < 50 Read student record Print student name and address Add 1 to student total ENDWHILE Note: The variable student total is initialized before the loop condition is executed The student total variable is incremented within the body of the loop so it will eventually stop. These are both Essential feature of the WHILE construct. How to write Pseudocode? I need to write pseudocode for a set of temperature readings in Fahrenheit, Kelvin, Celsius and centigrade. Below is what I came up with. Is this correct? 1. Get Fahrenheit Temperature 2. Read Fahrenheit Temperature 3. While (not EOF) a. Write c = ((F-32)/9)x5
  4. 4. b. Write cel = (F-30)/2 c. Write K = (F + 273) 4. Stop • 3 months ago

×