Operators: Difference between revisions
Mr. MacKenty (talk | contribs) |
Mr. MacKenty (talk | contribs) |
||
Line 50: | Line 50: | ||
[[:media:Approved notation for developing pseudocode.pdf | Click here to view a file describing operators. This is the approved notation sheet from the IB.]] | [[:media:Approved notation for developing pseudocode.pdf | Click here to view a file describing operators. This is the approved notation sheet from the IB.]] | ||
Below is a graphic that is taken from the above PDF file to help you understand how the IB wants operators to look. | |||
[[File:Ib operators.png]] | [[File:Ib operators.png]] |
Revision as of 16:32, 19 September 2016
Operators are very important. The way the IB wants you to use operators is different than the way you will use them in real life.
Arrays are a fundamental data structure, and they are extremely useful. We use arrays to hold values of the same type at contiguous memory locations. In particular, the use of arrays allows us to create "groups" or "clusters" of variables without needing to give a unique variable name to each, but still allowing us to individually index into the elements of the array. If you haven't started counting from zero yet, now is the time, because in C, arrays are zero-indexed which means the first element of a k-element array is located at array index 0 and the last element is located at array index k-1. In case you're wondering, that's the primary reason we count from 0 in CS50 (and in computer science more broadly!)[2]
In an array we are usually concerned about 2 things, the position of a piece of data and the actual data.
An example of a simple array in PHP can be found below:
<?php
# this file is used to teach the VERY BASICS of arrays in PHP
$pizza_toppings = array (
"extra cheese"
"onions"
"pepperoni"
"ham"
"pineapple"
"chicken"
"arugula"
"pesto"
);
# This creates a very simple array with 8 items.
?>
A video[edit]
This video references the C programming language and scratch, but the ideas about operators are excellent. In the case of conditionals, PHP and C share similar syntax (but not exact).
The way the IB wants you to use operators[edit]
Please know all code submitted to the IB (with the exception of object oriented programming) is in pseudocode. The way we write operators in pseudocode is different than the way we might write them in the real world.
Click here to view a file describing operators. This is the approved notation sheet from the IB.
Below is a graphic that is taken from the above PDF file to help you understand how the IB wants operators to look.
Standards[edit]
- Construct algorithms using pre- defined sub-programmes, one- dimensional arrays and/or collections.