CHAPTER 2 & 3: Pseudocode and Developing and Algorithm
Objectives Introduce common words & meaningful names Define basic control structures in Structure Theorem Develop an algorithm
Computer Operations Receive information Output information Perform Arithmetic Assign a value Compare variables Repeat actions
Receive information Read and Get Read: receive input from a record on a file Get: receive input from keyboard Example: Read studentName Get systemDate
Output Information Print, Write, Put, Output, Display Examples: Print: output to printer Write: written to a file Put, Output or Display: output to screen Examples: Write customer name to master file Display ‘Total Number’
Arithmetic Add, Subtract, Multiply, Compute etc Examples: Add number to total Total= Total + number Compute C = (F-32)*5/9 Order of operations is very important
Assign a value 3 instances of assigning a value: Initialize: Initialise or Set Result of processing: ‘=‘ or ‘’ Store a value: Save or Store Examples: Initialise total_price to zero total_price= cost_price + sales_tax
Compare Compare 2 variables & select one of the two alternative actions. IF, THEN, ELSE Example: IF student_status is part_time THEN add 1 to part_time_count ELSE add 1 to full_time_count ENDIF
Repeat actions Sequence of processing that need to be repeated DOWHILE, ENDDO Example: DOWHILE student_count <5 Read Student record Print student name, address to report add 1 to student_total ENDDO
Meaningful names Name should describe the type of data in the variable More than one word, use: Camel casing Underscore
Structure Theorem Any computer program can be written using 3 basic control structures: Sequence Selection Repetition
Sequence Straightforward execution of one step after another Example: Statement 1 Statement 2 Statement 3 Receive, output, arithmetic & assign values
Selection Presentation of a condition and choice between 2 actions, depending on TRUE or FALSE Example: IF condition 1 is true THEN statement(s) in true case ELSE statement(s) in false case ENDIF
Repetition Presentation of a set of instructions to be performed repeatedly as long as the condition is true. Example: DOWHILE condition 1 is true statement block ENDDO