Variables are “containers” for values that can be used by a program. Variables can contain numbers or text. Variables are given names so that they can be referred to in the programming code.
Sunday, July 31, 2011
Monday, July 25, 2011
Selection and Repetition
Solving a problem often involves making a decision between two or more options. In an algorithm this process of making a decision is called selection.
Examples:
Moving through a set of traffic lights.
1) Drive towards traffic lights
2) Determine whether the traffic light is red, yellow or green
3a) If red, got to 4)
3b) If yellow, go to 5)
3c) If green, go to 6)
4) slow to a stop, then go to 2)
5) continue driving slowly
6) continue driving at constant speed
Deciding whether to take an umbrella to school.
1) Check whether it is going to rain
2a) If yes, go to 3)
2b) If No, go to 4)
3) Bring umbrella to school
4) Don't bring umbrella to school
Giving a student an A, B or C on their test.
1) Determine whether student has achieved 90-100%, 70-89% or 50-69%
2a) If 90-100%, go to 3)
2b) If 70-89%, go to 4)
2c) If 50-69%, go to 5)
3) Give student A
4) Give student B
5) Give student C
Often an algorithm will often require you to repeat a task in order to solve a problem; when this is done in an algorithm the structure is called repetition.
Examples:
Adding the correct amount of cordial to water to make a drink.
1) Attempt to pour 1 part cordial into a glass
2) Attempt to pour 3 part water into the glass
3) Stir (optional)
4) Taste beverage
5) Determine whether drink is too sweet, too bland or just right
6a) If too sweet, go to 7)
6b) If too bland, go to 8)
6c) If just right, go to 9)
7) Pour more water, then go to 4)
8) Pour more cordial, then go to 4)
9) Drink it
Filling a bucket with water
1) Put bucket underneath a tap/ put a hose in bucket
2) Turn on tap
3) Check whether bucket is full
4a) If yes, go to 5)
4b) If no, go to 6)
5) Turn off tap
6) Continue filling bucket with water, then go to 3)
Blowing up a balloon
1) Blow into ballooon
2) Determine whether ballooon has enough air
3a) If yes, go to 4)
3b) If no, go to 5)
4) Tie balloon
5) Continue blowing into balloon, then go to 2)
Examples:
Moving through a set of traffic lights.
1) Drive towards traffic lights
2) Determine whether the traffic light is red, yellow or green
3a) If red, got to 4)
3b) If yellow, go to 5)
3c) If green, go to 6)
4) slow to a stop, then go to 2)
5) continue driving slowly
6) continue driving at constant speed
Deciding whether to take an umbrella to school.
1) Check whether it is going to rain
2a) If yes, go to 3)
2b) If No, go to 4)
3) Bring umbrella to school
4) Don't bring umbrella to school
Giving a student an A, B or C on their test.
1) Determine whether student has achieved 90-100%, 70-89% or 50-69%
2a) If 90-100%, go to 3)
2b) If 70-89%, go to 4)
2c) If 50-69%, go to 5)
3) Give student A
4) Give student B
5) Give student C
Often an algorithm will often require you to repeat a task in order to solve a problem; when this is done in an algorithm the structure is called repetition.
Examples:
Adding the correct amount of cordial to water to make a drink.
1) Attempt to pour 1 part cordial into a glass
2) Attempt to pour 3 part water into the glass
3) Stir (optional)
4) Taste beverage
5) Determine whether drink is too sweet, too bland or just right
6a) If too sweet, go to 7)
6b) If too bland, go to 8)
6c) If just right, go to 9)
7) Pour more water, then go to 4)
8) Pour more cordial, then go to 4)
9) Drink it
Filling a bucket with water
1) Put bucket underneath a tap/ put a hose in bucket
2) Turn on tap
3) Check whether bucket is full
4a) If yes, go to 5)
4b) If no, go to 6)
5) Turn off tap
6) Continue filling bucket with water, then go to 3)
Blowing up a balloon
1) Blow into ballooon
2) Determine whether ballooon has enough air
3a) If yes, go to 4)
3b) If no, go to 5)
4) Tie balloon
5) Continue blowing into balloon, then go to 2)
Thursday, July 21, 2011
Algorithms
What is an Algorithm?
An unambiguous set of steps, which when performed correctly by a processor, will result in a process being carried out in a finite time.
Example of an algorithm explaining how to make a cup of coffee:
1. boil the water
2. place coffee in the cup,
3. place sugar in the cup,
4. add the boiling water,
5. add milk,
6. stir.
An unambiguous set of steps, which when performed correctly by a processor, will result in a process being carried out in a finite time.
Example of an algorithm explaining how to make a cup of coffee:
1. boil the water
2. place coffee in the cup,
3. place sugar in the cup,
4. add the boiling water,
5. add milk,
6. stir.
For this particular algorithm, actually for all algorithms, steps are written in logical order: sequential order (in the sequence you would complete the step). This is absolutely essential as say for example this sequence is jumbled, and step "6" is done before step "2," then you are stirring nothing but air.
Other examples of algorithms:
Making toast:
1. get bread
2. place slices of bread in toaster
3. turn on toaster
4. wait for bread to toast
5. get bread from toaster
Calling a friend on the phone:
1. look up friend's phone number
2. pick up phone
3. dial the phone number
4. wait for friend to answer
5. talk to friend
Tuesday, July 19, 2011
Flowcharts - Symbols and Logic
What is a flowchart?
A flowchart is a means of visually presenting the flow of data through an information processing systems, the operations performed within the system and the sequence in which they are performed.
Basic flowchart symbols:
Rules:
A flowchart is a means of visually presenting the flow of data through an information processing systems, the operations performed within the system and the sequence in which they are performed.
Basic flowchart symbols:
- The usual direction of the flow of a procedure or system is from left to right or top to bottom.
- Only one flow line should come out from a process symbol.
- Only one flow line should enter a decision symbol, but two or three flow lines, one for each possible answer, should leave the decision symbol.
- Only one flow line is used in conjunction with terminal symbol
Example of a flowchart for a coin toss where heads means Mary pays for the pizza and Tales means Bill pays.
Subscribe to:
Posts (Atom)