ICS 3U Thursday, September 9
Sept. 9 - Agenda Hand in Instruction Writing Programmer’s Toolkit Orginal image Rough instructions with feedback (hopefully) from other person Good copy (on top) – stapled with name and colour clearly indicated Programmer’s Toolkit Pseudocode Pseudocode Practice
Programmer’s Toolkit Programming languages are used to design logic and write algorithms. All languages have the same core set of capabilities, although the specific syntax may vary. Example: to output words to the monitor print “Hello” Visual Basic cout << “Hello”; C++ writeln (‘hello’); Pascal The core set of capabilities common to All programming languages is called the Programmer’s Tooklit.
Programmer’s Toolkit Input Statements – capture user input to the program (usually from the keyboard or mouse) Output Statements – output information to an output device (usually the monitor) Storage – storing data / information in variables Math Calculations Selection Statements (if statement, case statement) – making a decision Repetition Statements (loops) – repeating a block of statements **Modularity – the ability to create re-usable blocks of code
Pseudocode Pseudo = Fake Pseudocode = Fake Code Pseudocode is used to plan the logic of a program. Taking a problem, and using the tools from the Programmer’s Toolkit, you can write a series of instructions for a problem. Pseudocode is a mixture of English and code so you do not have to worry about syntax, just the clarity of the explanation / logic.
Pseudocode Example Smallest of Two Numbers Ask the user to input a number (output) Store the number in num1 (input, storage) Store the number in num2 (input, storage) If num1 < num2 then (selection) Output “num1 is the smallest” Else, if num1 > num2 then (selection) Output “num2 is the smallest” (output) Otherwise Output “the numbers are equal” (output)
Pseudocode Guidelines Write a step by step method to solve the problem Use tools from the Programmer’s Toolkit Identify mathematical calculations Hi-lite variables (bold, underline) Include algorithmic explanations (translate into comments) Indent (tab in) statements that are part of a loop of conditional statement
Pseudocode Practice Write pseudocode for the following problems: Average 3 numbers inputted from the user. Sorting a list of 3 numbers in ascending order. (assume each number is different). Enrichments: Calculate median, mode. Sort 10 numbers, sort an unknown number of numbrs, sort with some numbers equal.