Put the work for this lab into a new folder
public_html\cs1109\lab10.
Take a copy of the following files:
statistics.html: This is a form
that allows a user to enter five numbers. Do not
edit this file.
statistics.phps: Save this file
as statistics.php. This PHP script takes the five numbers from the user
and stores them in an array.
Your task is to complete statistics.php so that it outputs the sample mean
(i.e. average) of the five numbers and their sample standard deviation.
You must do this with foreach-loops, so that your solution
will work for any length of array.
The sample standard deviation is the square root of the square of the sum of the differences between each of the numbers and the mean divided by how many numbers there are less one. The Web has many pages explaining how to compute the sample standard deviation, including:
(If you take your explanation of standard deviation from some other Web page, be aware that I want the sample standard deviation, where we divide by one less than the size of the sample, not the population standard deviation, where we would divide by the size of the sample.)
In your progam, don't worry about users who leave one or more of the textfelds empty or who enter nonsense into the textfields.
In your program, apart from sqrt, do not use any built-in functions, such as
count, array_sum, etc. If in doubt, ask me.
Take a copy of dates.html. Do not
edit this form. It allows a user to enter two dates. Assume that the user does enter
the dates correctly. In other words, ignore the possibility that s/he enters, e.g.,
29 February 2011 or 12 Bananas 2014.
Write dates.php. The program outputs the word before if the first date
comes before the second; it outputs same if the first date is equal to
the first; or it outputs after if the first date comes after the second.
In your program, do not use any built-in functions. If in doubt, ask me.
Hint: Use an array of months.
Deadline for Parts 1 & 2 of Lab 10: 1pm, Tuesday 10th January.
If you have named your files and folders correctly, your work will be collected automatically at that time by my software.
Remember that challenge exercises are always optional. They do not form part of your year's work and they are not worth any marks. They are designed for those students who finish the main exercise quickly and easily, and wish to explore further.
I expect that your solution to part 1 uses a sequence of two foreach-loops.
That's fine. Leave it like that.
But it's a bit inefficient. If you're good at maths, or good at finding things on
the Web, you should be able come up with a program that uses just one
foreach-loop.
Here's the form again:
statistics_challenge.html.
Put your PHP into a file called
statistics_challenge.php.
Leave them both in your lab10 folder, and I will take a look at them.
Remember that challenge exercises are always optional. They do not form part of your year's work and they are not worth any marks. They are designed for those students who finish the main exercise quickly and easily, and wish to explore further.
RPS-15 is a variation on Rock-Paper-Scissors, but with fifteen different weapons, instead of three. This image shows you the weapons and their relationships to each other (i.e. which beats which). (The original image comes from the Web site of David C. Lovelace, where you will also find that he has also worked out RPS-25 and RPS-101 — yes, with 25 and 101 weapons!)
In a file called rps15.html, create a form (based on rsp.html
from lab sheet 9) but with 15 radio buttons. And in a file called rps15.php, write
the program that plays the 15-weapon version of the game. Work on it in stages as follows:
Leave both files in your lab10 folder, and I will take a look at them.