Assigned Th 6/19/2008, due Fr 6/27 at 9pm. 50 points.
http://www.cs.nyu.edu/courses/summer08/G22.3033-002/
Homeworks are due on Fridays at 9pm. This deadline will be strictly enforced.
Email your answers to Robert Soulé robert.soule@gmail.com. Please put your solutions to VBA programming problems in a powerpoint presentation. For all other questions (including programming problems in other languages), just send a simple text file, such as what you get when using Emacs, Vi, Notepad, or the "save as text only" feature in Word.
Please make sure that your code works with the compilers and tools installed at CIWW. Specifically, please test:
doowop1
(see http://www.cims.nyu.edu/systems/resources/computeservers/).
(4+4+4 = 12 points) Consider the following PHP code.
<?php
class Vector {
var $x = 0;
var $y = 0;
function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
}
function __get($propName) {
if ($propName == 'length')
return sqrt($this->x * $this->x + $this->y * $this->y);
}
function __set($propName, $value) {
if ($propName == 'length') {
$oldLen = sqrt($this->x * $this->x + $this->y * $this->y);
$this->x *= $value / $oldLen;
$this->y *= $value / $oldLen;
}
}
}
$v = new Vector(2,3);
printf("|%.2f, %.2f| = %.2f<br/>\n", $v->x, $v->y, $v->length);
$v->length = 5;
printf("|%.2f, %.2f| = %.2f<br/>\n", $v->x, $v->y, $v->length);
?>
(4+4+4 = 12 points) Consider the following PHP code.
<?php
class Vector {
var $x = 0;
var $y = 0;
function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
}
function length() {
return sqrt($this->x * $this->x + $this->y * $this->y);
}
}
$a = array(new Vector(0,4), new Vector(-3,4), new Vector(2,3));
function cmp_vector($a, $b) {
$aa = $a->length(); $bb = $b->length();
return $aa < $bb ? -1 : $aa == $bb ? 0 : 1;
}
usort($a, "cmp_vector");
foreach ($a as $i => $v)
printf("%2d => (%d, %d)<br/>\n", $i, $v->x, $v->y);
?>
(5+5+5 = 15 points)
http://www.cs.nyu.edu/~your_cims_id/hw05-3a.html
For example, if your_cims_id is hirzel, then the URL would
be:
.htaccess file to create a password protected HTML page
that can be viewed from any web browser using the following URL:
http://www.cs.nyu.edu/~your_cims_id/php/hw05-3b.html
For example, with your_cims_id as hirzel, you get the
following URL, which requires you to enter the user name student
and the password P_8sh_P:
http://www.cs.nyu.edu/~hirzel/php/hw05-3b.html
Please create a user name grader. Please indicate the URL and the
password for grader in your submission, so that Robert Soulé
can access your web page.
.htaccess file,
create a PHP script hw05-3c.php with the following code:
<html><body>
<?php
if(!empty($_GET['who'])) { echo "Hi, {$_GET['who']}.";}
?>
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method=get>
Who shall be greeted: <input type="text" name="who" />
</form>
</body></html>
(See also http://www.cs.nyu.edu/~hirzel/php/hw05-3c.phps).
Test it and make sure it works. For example, for your_cims_id
hirzel, user name student, and password P_8sh_P,
this URL runs the script for you:
(11 points) Write a PHP script that converts cooking quantities, units,
and ingredients to metric units. For data input, use a form that
provides three text fields, one each for Quantity, Unit, and
Ingredient. When the user enters values for all three and clicks the
submit button, your script should print the converted result at the top
of the web page. Your script should be a self-processing page, in other
words, use the same page for input and output. For example, if the user
enters the values 3, cup, and flour in the three
input fields and clicks the Submit button, your script should
return a page that looks like this:
Your PHP script should offer the same kinds of conversions as the Perl example from the lecture slides. Please copy-and-paste the source code of your script into your homework submission. In addition, please put the script online at the following URL (replacing your_cims_id by your CIMS id):
http://www.cs.nyu.edu/~your_cims_id/php/hw05-4.php