Omar Carrillo



Problem 1

Problem 2

Problem 3

Problem 4

Problem 5

Problem 6

Problem 7

Problem 8

Homework 2

  1. Without using a PHP program to evaluate them, determine whether each of these expressions is true or false:

    a) 100.00 – 100
    b) "zero"
    c) "false"
    d) 0 + "true"
    e) 0.000
    f) "0.0"
    g) strcmp("false","False")

  2. Without running it through the PHP interpreter, figure out what this program prints.

    $age = 12;
    $shoe_size = 13;
    if ($age > $shoe_size) {
    print "Message 1.";
    } elseif (($shoe_size++) && ($age > 20)) {
    print "Message 2.";
    } else {
    print "Message 3.";
    print "Age: $age. Shoe Size: $shoe_size";

  3. Use while( ) to print out a table of Fahrenheit and Celsius temperature equivalents from -50 degrees F to 50 degrees F in 5-degree increments. On the Fahrenheit temperature scale, water freezes at 32 degrees and boils at 212 degrees. On the Celsius scale, water freezes at 0 degrees and boils at 100 degrees. So, to convert from Fahrenheit to Celsius, you subtract 32 from the temperature, multiply by 5, and divide by 9. To convert from Celsius to Fahrenheit, you multiply by 9, divide by 5, and then add 32.

  4. Modify your answer to Exercise 3 to use for( ) instead of while( ).

  5. According to the U.S. Census Bureau, the 10 largest American cities (by population) in 2000 were as follows:

    New York, NY (8,008,278 people)
    Los Angeles, CA (3,694,820)
    Chicago, IL (2,896,016)
    Houston, TX (1,953,631)
    Philadelphia, PA (1,517,550)
    Phoenix, AZ (1,321,045)
    San Diego, CA (1,223,400)
    Dallas, TX (1,188,580)
    San Antonio, TX (1,144,646)
    Detroit, MI (951,270)

    Define an array (or arrays) that holds this information about locations and population. Print a table of locations and population information that includes the total population in all 10 cities.

  6. Modify your solution to the previous exercise so that the rows in result table are ordered by population. Then modify your solution so that the rows are ordered by city name.

  7. Modify your solution to the first exercise so that the table also contains rows that hold state population totals for each state represented in the list of cities.

  8. For each of the following kinds of information, state how you would store it in an array and then give sample code that creates such an array with a few elements. For example, for the first item, you might say, "An associative array whose key is the student's name and whose value is an associative array of grade and ID number," as in the following:

    $students = array('James D. McCawley' => array('grade' => 'A+', 'id' => 271231), 'Buwei Yang Chao' => array('grade' => 'A', 'id' => 818211));

    The grades and ID numbers of students in a class.
    How many of each item in a store inventory is in stock.
    School lunches for a week ---the different parts of each meal (entree, side dish, drink, etc.) and the cost for each day.
    The names of people in your family.
    The names, ages, and relationship to you of people in your family.
CS 479 - PHP Programming - Summer 2009 - NMSU