Check back for summer activities
Information Technology - 3rd Form
Tuesday, June 30, 2015
Sunday, May 17, 2015
Introduction to Loops - For Loop
There are several methods used for repetition within structured algorithms; the first that we will be learning is Loops.
The three types of Loops that we will be covering are:
For Loop (also known as Do Loop or Counter Controlled Loop)
While Loop
Repeat Until Loop
The For loop is used to repeat code for a specified number of times. It falls under the control structure of repetition control structure.
First we take a look at the For Loop. This is used when the number of repetition is known. The syntax is as follows:
Example:
Problem Statement: Calculate and output the sum of ten numbers.
Line 1 is an example of initializing a variable. That means that we are giving it a starting value.
Line 2 indicates that we will repeat lines 3-5 for ten times.
Line 3 is an output statement hosting a prompt.
Line 4 is an input statement whereby the value entered will be stored in the variable num.
Line 5 allows a tally to be kept each time a number is entered.
Line 6 terminates the loop. The syntax states End For, however, the compiler uses the command Next.
Line 7 displays the total of the ten numbers with a suitable label.
Line 8 terminates the algorithm
Now, you try one: Calculate and output the average current GPA of the students in your class based on their first, second and third form GPA. Ask the user to enter the number of students in the class, store it in the variable Class; that variable becomes your terminating value.
The three types of Loops that we will be covering are:
For Loop (also known as Do Loop or Counter Controlled Loop)
While Loop
Repeat Until Loop
The For loop is used to repeat code for a specified number of times. It falls under the control structure of repetition control structure.
First we take a look at the For Loop. This is used when the number of repetition is known. The syntax is as follows:
Example:
Problem Statement: Calculate and output the sum of ten numbers.
- total = 0
- For x = 1 to 10
- Print "Enter a number"
- Input num
- total = total +1
- Next
- Print "The sum of ten numbers entered is", total
- Input key
Line 1 is an example of initializing a variable. That means that we are giving it a starting value.
Line 2 indicates that we will repeat lines 3-5 for ten times.
Line 3 is an output statement hosting a prompt.
Line 4 is an input statement whereby the value entered will be stored in the variable num.
Line 5 allows a tally to be kept each time a number is entered.
Line 6 terminates the loop. The syntax states End For, however, the compiler uses the command Next.
Line 7 displays the total of the ten numbers with a suitable label.
Line 8 terminates the algorithm
Now, you try one: Calculate and output the average current GPA of the students in your class based on their first, second and third form GPA. Ask the user to enter the number of students in the class, store it in the variable Class; that variable becomes your terminating value.
Sunday, February 22, 2015
Conditional Algorithm
Conditional algorithms have selection statements in them. Their control structure is known as Selection Control Structure.
The first illustration is that of the if-then construct.
The second illustration is that of the if-then-else construct.
Examples:
1. If grade is 70 or more, output Pass.
2. If grade is 70 or more, output Pass; otherwise output Fail.
Example Problem:
Write an algorithm that determines and outputs if the average of a student allows him to pass or fail; the passing mark is 70.
Solution #1: if-then construct
Print "Enter the average of a student"
input avg
if avg >= 70 then
print "Pass"
end if
input key
Solution #2: if-then-else construct
Print "Enter the average of a student"
input avg
if avg >= 70 then
print "Pass"
else
print "Fail"
end if
input key
Now you try one:
Write an algorithm that prompts the user to enter the name and cost of two items. The algorithm should calculate and output the total cost. If the total exceeds $25.00 then offer a discount of 10%; otherwise a discount of 5%; show the new total after discount.
The first illustration is that of the if-then construct.
The second illustration is that of the if-then-else construct.
Examples:
1. If grade is 70 or more, output Pass.
2. If grade is 70 or more, output Pass; otherwise output Fail.
Example Problem:
Write an algorithm that determines and outputs if the average of a student allows him to pass or fail; the passing mark is 70.
Solution #1: if-then construct
Print "Enter the average of a student"
input avg
if avg >= 70 then
print "Pass"
end if
input key
Solution #2: if-then-else construct
Print "Enter the average of a student"
input avg
if avg >= 70 then
print "Pass"
else
print "Fail"
end if
input key
Now you try one:
Write an algorithm that prompts the user to enter the name and cost of two items. The algorithm should calculate and output the total cost. If the total exceeds $25.00 then offer a discount of 10%; otherwise a discount of 5%; show the new total after discount.
Algorithms
There are four types of algorithms: Simple, Conditional, Loops and Arrays
Simple Algorithms - basic calculations
Conditional Algorithms - selection statements
Algorithms are series of instructions that rigorously defines the solution to a problem.
The attributes of an algorithm are:
Simple Algorithms - basic calculations
Conditional Algorithms - selection statements
Algorithms are series of instructions that rigorously defines the solution to a problem.
The attributes of an algorithm are:
- Must be precise
- Must be ambiguous
- Must be finite
- Must be done in a logical order
Example of given problem:
Write an algorithm that prompts the user to enter two grades, and shows the average of the two grades.
Indicators that it is a simple algorithm: basic calculation of entering data, performing calculation, and outputting results.
Solution:
Print "Enter a grade"
Input grade1
Print "Enter another grade"
Input grade2
Let total = grade1 + grade2
Let avg = total / 2
Print "The average of two grades is", avg
Input key
Sunday, February 8, 2015
Problem Solving Phase
Click on the link below for a short video about the five steps in the problem solving phase along with an important message.
Intro to Programming by Ms Young
Intro to Programming by Ms Young
Subscribe to:
Posts (Atom)