CS1102 Lab 11

This week's work

Inside your public_html folder, last week you created a new folder called cs1102. Inside your new cs1102 folder, create another folder (a subdirectory), called lab11 (all lowercase). Do this week's work inside this lab11 folder.

Again there's nothing to submit this week but please do the exercises anyway.

Old Macdonald's Farm

Write a PHP script called farm.php. (Use template.php from last week to start you off.)

  1. Create an associative array, with four entries in it. The keys in the array should be various farmyard animals. The values in the array should be the corresponding noises that these animals make. In my example, dogs go woof, pigs go oink, wombats go snaffle, and dead cows go off. Use your imagination to invent your own animals and the noises they make! (If you have no imagination, put your hand up.)
  2. Now, using a loop, output the following lines of a (shortened) version of the musically magnificient Old Macdonald's Farm. I want the output to be a nested list, as shown.

Run the program in the same way that you did last week.

Validate the XHTML that your script outputs. You have not finished this exercise until it validates!

Just an average Guy

These are the marks that Guy got in his Christmas class tests: CS1100 75; CS1101 64; CS1102 100; CS1105 3; MA1003 3.

In your lab11 folder, write a PHP script called guy.php, as follows.

  1. Create an associative array to hold Guy's class test results.
  2. Then output a table, where the first column contains module codes, and the second column contains corresponding class test results.
  3. In the last two rows of the table, output the mean and standard deviation of Guy's marks. (Don't compute them manually. Get your script to compute them!)

In case you don't know, the mean is the sum of Guy's marks divided by the number of marks. And the standard deviation involves (a) calculating the difference between each mark and the mean, (b) squaring each difference, (c) summing up all these squared differences, (d) dividing this total by the number of marks, and finally (e) taking the square root. (PHP has a function called sqrt for this last step.) Ask for help with means and standard deviations, if you need it.

(Check your script: Guy's mean is 49, and his standard deviation to two decimal places is 39.33.)

Validate the XHTML that your script outputs. You have not finished this exercise until it validates!

There is no need to write a stylesheet to prettify the table.

Exploding a URL

In your lab11 folder, write a PHP script called explode.php, as follows.

  1. Store a simple URL in variable $myURL like so:
  2. Use strpos and substr to extract the following:
  3. Echo the three parts to the output.

PHP has a built-in function (parse_url) for doing all this properly! Obviously, you should not use it in this exercise.