Computer Science - Term one half one- ALgorithims
For next loops
A for loop is for something that has to happen for a fixed number of time for is repeat next is like do the next (e.g next count) e.g repeat FOR x(x could be anything e.g count) =1 to 10 (start to end if you have given a value to a variable can be 1 to variable) FOR x = 1 to 10 write code NEXT FOR students FOR count = 1 to students INPUT grade NEXT count Basically, you do the code inside the for loop each time for the count e.g 1-students (e.g 30) it will input grade 30 times and the next is to say after done the input grade next count again until to for loop is over
Start and end box shape
A rounded edge rectangle
Read over the sheet on who to do basic tasks (e.g Finding the Max) to check you know how to do all
Go do!
How to do a total
How to total something 1. Set the total to 0 2. Input a new value 3. Add new value to total 4. Output outside the loop total←0 FOR count = 1 to 5 INPUT newValue totaltotal+newValue NEXT count PRINT total
Else if normal
IF test (a condition (a=12)) THEN true action (i.e what happens if its true e.g PRINT a) ELSE false action (i.e what happens if its false e.g PRINT b) ENDIF
Else if two
IF test (a condition (a=12)) THEN true action (i.e what happens if its true e.g PRINT a) ELSEIF test2 THEN true action2 ELSE false action (i.e what happens if its false e.g PRINT b) ENDIF
If normal
IF test (a condition (a=12)) THEN true action (i.e what happens if its true e.g PRINT a) ENDIF
How to input data
INPUT
Practice Practice Practice
Like maths, theory is nothing!
How to tell if a number are BOTH pos/neg in an algorithm
Must input a,b before IF a mod 2 (divided by 2) = b mod 2 PRINT postive because all positive numbers can divide into 2 so there should be nothing left over if they are both positive to work out just one just do IF a mod 2 ← 0 then its positive if not its negative
n-1 decisions are needed to distinguish between
N statements e.g 2 decions are needed to distinguish between 3 statements
While loop loops
While condition (e.g a ← b) Write code (condition of while if true (can also puts if's in there)) Loop (to end it)
A process box shape (e.g stating something)
e..g x = x+1 or fill the sink rectangle
testing
e.g - for use in if's (if (testing) a ← b) a = 12 (does a =12) a<>12 Is the value of a not 12 a>= Is a greater than or equal to 12 a>=12 is a less than or equal to 12
Decison/query box
e.g is X>5 Diamond
Input/output box
e.g print X parallelogram
How to make multiple selections flow charts
first question has yes to end the other has no to the next question. Remember to go through EVERY clause not condense them into one - practice question 10
Repeat until loops
Repeat Write code Until Condition (e.g a ← b)
Repetion description
Repeatedly does something until you ask it to stop
Assignment
Saying something now = something instead of a = b its a←b (a now = b)
When declaring variables what to remember !
The variable value goes OUTSIDE the loop
Repetition in Flow charts
There is a yes or no lopp and they loop back to wither the begging of the loop or the end
Selection define
This means picking an option (e.g if this equals this SELECT this)
How to do key terms
UpperCase, bold all words capitalised bold.
How to do variables
lowerCase, noSpaces - no spaces -capital letter to indicate new word but not at begging
N decions are needed to distinguish between
n+1 statement e.g 2 decions are needed to distinguish between 3 statements
How to do 10 - 1 when you can't go backwards
num←10 (make num = 10) START FOR LOOP For x = 0-9 PRINT num-x (so its 10-0 = 10 then 10-1 = 9) NEXT END
Selection if Flow charts
question asked is placed inside a decision diamond and that the two flow lines contains arrow heads to show where to go (unlike usual) PRACTICE