Pseudocode

advertisement
PLAN THE
SOLUTION
1
Plan the Solution
• Outline the Solution
– Major processing steps involved
– Major subtasks
– Major control structures
– Major variables and record structures
– Mainline logic
• Develop the outline into an algorithm
• Test the algorithm for correctness
2
Structured Programming
• Top Down Design & Development
• Modularity
• Control structures
– sequence
– selection or IF-THEN-ELSE
– repetition or looping
3
Design/Plan the solution
• Algorithm – a step by step procedure for
solving a problem
• Programs - implementations of algorithms
– Set of instructions
• flowcharts
• pseudocode
– test solution for correctness - trace
4
Pseudocode
• structured concise English statements
used to state operations
• language independent,no standard
• use words and phrases that are in line
with basic computer operations
5
Pseudocode
1. Write statements in simple English
2. Write each instruction on a separate
line.
3. Use keywords and indentation for
control structures.
4. Write instructions from top to bottom,
with only one entry and one exit.
5. Groups of statements may be formed
into modules.
6
Pseudocode
1. Input - receiving information
• keywords - Read, Get, Input
• Read - receive information from a record on a
file
• Get - receive information from the keyboard.
Read studentName
Get systemDate
Read num1,num2
Get taxCode
• use one verb followed by one or more nouns
7
Pseudocode
2. Output
– putting information out
• Put, Output,Display - screen
• Print - printer
• Write - file
–
–
–
–
–
Print smaller.
Print "Program Completed"
Write customer_record to file
Output totalTax
Display "End of Data"
8
Output continued
• Labels
– Display "label"
• statement inside quotes is printed as it appears
– Display "x"
• Yields
// if x = 5
x
– Display x
• yields
5
– Display "X = " and x
• yields:
X=5
9
Pseudocode
3. Arithmetic
• use name of the operation or algebraic symbol
• add,subtract,multiply, divide, exponentiation
• + - * / **
• x = algebraic expression
–
–
–
–
count = count + 1
netPay = hourlyPayRate * hoursWorked
salesTax = cost * 0.10
totalPrice = price + salesTax
10
Pseudocode
4. Assignment - place information into a storage
location
• Initialize, Set - give variable initial value
• Save,Store - save info for later
• =
//preferred
y = 3 note: does not mean equality
– could involve calculation:
– area = length * width
11
Download