Designing solutions through programming - October 14 2016 Lesson Notes

From Computer Science Wiki

Class plan.png What are we going to learn today?[edit]

  1. Today in class we will start learning about collections and arrays. THESE ARE DIFFERENT.
  2. If using weapons as array examples offends you, please use this potion list as an alternative.
<?php


$player_inventory = array
    (
    "sword",
    "shield",
    "armour",
    "potion of healing",
    "amulet"
    );

echo "You are currently carrying:<br /> ";

for ($i=0; $i < count($player_inventory); $i++)

{

    echo $player_inventory[$i] . "<br />";

}

# here is where we add an item to our array: 


array_push($player_inventory, "magic ring", "wand");

# now let's look at the new inventory: 

echo "<br />This is the new inventory, after we have pushed the new items to the end of the array<br /> ";
for ($i=0; $i < count($player_inventory); $i++)

{

    echo $player_inventory[$i] . "<br />";

}


# now we will use common access methods: 

echo "<br />Below we see how common access methods work.<br /><br />";
echo "The index is CURRENTly pointing at:  " . current($player_inventory);
echo "<br />";
echo "The NEXT index (relative to the current index) is: " . next($player_inventory);
echo "<br />";
echo "The index is now CURRENTly pointing at: " . current($player_inventory);
echo "<br />";
echo "The previous index is: " . prev($player_inventory);
echo "<br />";
echo "The current index is: " . current($player_inventory);
echo "<br />";
echo "The last element in the list is " . end($player_inventory);
echo "<br />";
echo "The current element is: " . current($player_inventory);
echo "<br />";
echo "The first element in the list is: " . reset($player_inventory);
 
?>


Homework.png Homework[edit]

  1. Please review our page about collections and arrays


Target.png How am I being assessed today?[edit]

  1. You will be formatively assessed in class today

Ourstandards.png Standards we are covering today[edit]

Computer1.png As a computer scientist, you have:[edit]

  • Confidence in dealing with complexity
  • Persistence in working with difficult problems
  • Tolerance for ambiguity
  • The ability to deal with open-ended problems
  • The ability to communicate and work with others to achieve a common goal or solution

Credit.png Credits[edit]