Thursday, October 30, 2014

Practice Algorithms

Here are a few problems for you to work out in preparation for your test.  Remember that Test 3 is on conditional constructs, focusing on While Loops.
  1. Calculate and output the lowest test grade entered of a series of grades.
  2. From a group of students, output the number of students who would like to participate in Crazy Day.
  3. From a group of teachers, determine which teacher has the most classes.  Output the teachers' name.
  4. A survey is being done to see who wins the next student council elections.  So far, three students are the candidates for Student Council President.  (John, Jason, Jacob)  Write an algorithm that will ask a group of students who they vote for, and that will determine and state who got the most votes and who got the least votes of the three candidates. 
Of the algorithms, question 4 is the most challenging.

Test 3 Dates

4A   Cycle 7 Day 7
4B   Cycle 7 Day 5
4C   Cycle 7 Day 7
4D   Cycle 7 Day 6

Monday, October 13, 2014

SBA NOTICE


Click on the page above entitled SBA 2014-2015 Paper One Instructions.  Although the instructions are here, your SBA Paper One complete instructions, including mark scheme, was sent to your Edmodo account.  This page was created for SBA related questions and discussions as you are completing the task. Please refrain from posting SBA related questions on regular blog posts.

Saturday, October 11, 2014

Test 2 Notes

LOOPS

Loops are repetition statements, more formally explained as a series of instructions that is repeated.
There are three types of loops that are used in programming:

  1. For Loop - repeating a series of instructions for a specified number of times
  2. While Loop - repeating a series of instructions while the condition is true
  3. Repeat Until Loop - repeating a series of instructions until the condition is true
For Loop (Also known as the 'do-loop') is considered a counter controlled loop.

Syntax for the For Loop


For <variable> = <begin> to <end> step <increment> do
       <steps to be repeated>
end for

When applying the syntax practically, the command 'do' is not used, and the command 'end for' is changed to 'next'

Terminology

Snippet - a small section of a code
Loop variable - the variable used within the loop statement
Loop Block - the repetition statements starting with the command For and ending with the command Next
Increment - representing the value by which the loop variable increases
Iteration - repetition

Example of a Counter Control Algorithm

Write an algorithm that calculates and outputs the average of 15 numbers. If the average exceeds 20, calculate and output the square of the average; otherwise, output the words "Low average".

SOLUTION:

  1. total = 0
  2. for numbers = 1 to 15 do
  3.     print "enter a number"
  4.     input num
  5.     let total = total + num
  6. next
  7. average = total / 15
  8. print "the average of fifteen numbers is", average
  9. if average > 20 then
  10.    square = average * average
  11.    print "the square of the average is", square
  12. else
  13.    print "low average"
  14. end if
  15. input key

Line is is identified as - initializing a variable
Lines 2 to 6 - the loop block
Lines 9 to 14 - the conditional block
Lines 3 to 5  - the steps to be repeated
Line 6 - terminating the loop block

Logic:  Repeat asking the user to enter a number for fifteen times.  Within the loop, keep a tally of all the numbers being entered.  After the loop, calculate and output the average.  After the calculation of the average, determine if the average exceeded 20.  If it did, calculate and output the square of the average.  (The square of any number is the number multiplied by itself)  If it did not exceed 20, then the value if false is to output a statement saying low average.

PRACTICE ALGORITHMS  

1. Calculate and output the total cost of 5 items.  If each item entered costs more than $20,00 output a statement saying that the item qualifies for a discount.  Count and output the number of items that cost more than $20.00

2. Tickets to a movie costs as follows:  Adults $15.00  Minors $10.00
Calculate and output the total cost for a group of ten people that has both adults and minors.  (Solve this problem as a for loop with conditional statements AND NOT as a simple algorithm)

3. You IT Teacher wants to know how many students in your class feels that they will earn an "A" on this upcoming test.  Write an algorithm that solves and displays how many students from your class says yes.


TABLES


In computer programming, tables are the basic concept of columns and rows with column headings.  Using the For Loop, we can create conversion tables.  To do so, we follow these easy steps:
  1. Display column headings
  2. Write the for statement indicating the range
  3. Perform the calculation(s)
  4. Display the results of the calculations by outputting the variable names.
Example:  Print the conversion table from pounds to kilograms.  The table ranges from 1 lb to 15 lb.  (1 lb = 0.45 kg)


Step 1 - Display column headings              Print "Pounds","Kilograms"
Step 2 -Write the for statement                   For lb = 1 to 15
Step 3 - Perform calculation                              kg = lb * 0.45
Step 4 - Display variables                                  print lb,kg
Step 5 - Terminate loop                               Next
Step 6 - Terminate algorithm                       Input key


Now you try one:    
Print a conversion table that shows 3% and 5% of numbers ranging from 100 to 500 in steps of 10.

Friday, October 10, 2014

Test 2 Notification

Please note that Test 2 is scheduled as follows:

4A     -Day 7 - Wednesday, October 15, 2014
4B     -Day 7 - Wednesday, October 15, 2014
4C     -Day 7 - Wednesday, October 15, 2014
4D     -Day 1 - Thursday, October 16, 2014

Test 2 - Theory Test on Loops focusing on the For Loop

Thursday, October 9, 2014

Counter Controlled 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)
While Loop
Repeat Until Loop

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.

  1. total = 0
  2. For x = 1 to 10
  3.      Print "Enter a number"
  4.      Input num
  5.      total = total +1
  6. Next
  7. Print "The sum of ten numbers entered is", total
  8. 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.  Ask the user to enter the number of students in the class, store it in the variable Class; that variable becomes your terminating value.