Martha's CIS 52 LAB Assignments

Lab One - due 10/24/09

  1. Create a Web page that contains a "here document" block. 
  2. Write a script that declares and assigns five different variables.   Populate them with values of different data types and use the gettype ( ) function to print each type to the browser. 
  3. Write a script that declares and assigns floating-point variables for the interest rate you are paying on your car, credit card, mortgage, student loan, or some other type of loan.  Create floating-point variables for at least three types of loans.  If you do not have any type of loan with an interest rate, look in your local newspaper or on the Internet for current interest rates for morgages and autos.  Use echo ( ) statements to print each variable, along with a description of the loan, and the gettype ( ) function to make sure each variable is of the double data type. 
  4. Write an HTML form (see NOTE below -- end of this page on PHP Forms and User Input) that prompts the user to enter a value.  In PHP, write a script that uses conditional operator to determine whether a variable contain a number and whether the number is even.  You need to use the is_numeric ( ) function and the conditional operator.  For floating-point numbers, you need to use the round ( ) function to convert the value to the nearest whole number.   Code this program using only conditional operator.
  5. Use the while( ) loop to write a script that prints a list of the Celsius equivalents of zero degrees Fahrenheit through 100 degrees Fahrenheit.  To convert Fahrenheit to Celsuis, subtract 32 from the Fahrenheit temperature, and then multiply the remainder by .55.  To convert Celsius to Fahrenheit, multiply the Celsius temperature by 1.8, and then add 32. You may use any increment of temperature.
  6. Modify Problem #5 to use for( ) loop.
  7. Write an HTML form that prompts the user for his or her grade on three different tests. Grades range from 0 to 100. Write a PHP program that tests that the user typed in a numeric grade (see is_numeric()). Average the three grades using the following scale. Use the if/elseif conditional construct to determine the student's letter grade.
  8. Click here for problem 8. Reference:  http://www.w3schools.com/php/func_math_rand.asp
  9. Create a form that asks a user to select a destination from a list of radio buttons. The choices are: San Francisco, New York, London, Paris, Honolulu, and Tokyo. Write a PHP script that uses a switch statement to evaluate each of the cities, and based on the city selected by the user, sends back a message such as, "Welcome to San Francisco. Be sure to bring your heart and a jacket!" or "Bonjour, let's take a stroll on the left bank!". For Problem 9:  Please have two files:  one HTML and one PHP.
  10. Ask the user how many Euros he or she spent in Germany? Write a function to convert the Euros to U.S. dollars based on today's exchange rate.
  11. reate a function called converter() that will take two arguments. The first argument will be upper, lower, or title. The second argument will be a string. The function should display the string in all uppercase, all lowercase, or as a title (that is, where the first letter in each word is uppercase as in, "Having Fun With Dick and Jane"). The function will be called like this:
     print converter("title", $string); Click Here to see the output.

**************************************************************

Lab Two - due 11/14/09

 1.  Create a string of names consisting of "John, Jerry, Ann, Sanji, Wen, Paul, Louise, Peter".

  1. Create a single dimensional array out of the string.
  2. Get the total number of values in the array
  3. Search for a specific value in the array.  You can determine what that value is.
  4. Sort the array by keys in descending order
  5. After sorting the array in (d), continue to sort the array by value in ascending order
  6. After sorting the array in (e), continue to sort the array in reverse order.
  7. Remove the first element from the array.
  8. Add "Willie" and "Daniel" to the end of the array.
  9. Replace "Paul" with "Andre".
  10. Add "Alisha" to the beginning of the array.
  11. Output the minimum and maximum value of the array
  12. Generate an output that returns the current element key and value and moves the internal pointer forward.
  13. Randomly retrieve a value from the array
  14. Create another array of names.  Choose names of your choice.
  15. Merge both of your arrays together and display them in sorted order.

2.  Create a multidimensional array of movies organized by genre.  This should take the form of an associative array with genres as keys, such as Musical, Action, Adventure, and so forth.  Each of the array’s elements should be an array containing movie names, such as Passion of Christ, Star Wars, Chariots of Fire, and so on.  When your arrays are created, loop through them, printing the name of each genre and its associated movie(s).  Sort your array.
3.  Create a feedback form that accepts a user’s full name in one textbox (indicate a message that the user must enter his/her first name first, then last name), state abbreviation where he/she lives (such as CA, NY, etc.), an email address, and the month, day and year of his/her birthday.  Use case conversion functions to capitalize the first letter of each name the user submits.  Check that the user’s email address contains the @ symbol and print a warning otherwise.  If the user did not input a state abbreviation, assign a default value of “CA.”  Generate an error message if user did not input full name, email address or birthday.  
4. Create a Song Organizer script that stores songs in a text file.  Print a summary that includes the number of lines in the file and the file's size.  Append another song in the text file.  Include functionality that allows users to view the song lists and prevents the same song name from being entered twice.  Also, include code that sorts the songs by name and randomizes the song list with the shuffle( ) function.  
5.  Create a PHP script which takes two parameters: (1) the number of years and (2) the amount of money to be put on a savings account.  Include a function that   calculates the amount that will have been reached after a given number of years. Print the amount with no more than two decimals.  Come up with your own interest rate.
6. Remove the last two chunks of values from the following array:  $array = array("Zero"=>"PHP", "One"=>"Perl", "Two"=>"Java"); 
Output the removed chunks, which are [One] => Perl and [Two] => Java, and the remaining chunk, which is     [Zero] => PHP 
7.  Given the following array: $date = array('01', '01', '2006'); $keys = array('php', 'string', 'function'); Generate an output such as:
A formated date: 01/01/2006
A keyword list: php, string, function
8.  Create an array with a sequence of integers or characters.  Do not use a loop. Please check:  http://www.w3schools.com/PHP/func_array_range.asp
9.  Given the following array: $array = array("Zero"=>"PHP", "One"=>"Perl", "Two"=>"Java"); Generate an output such as: This script will print: Padded: ---,---,PHP,Perl,Java,>>,>>,>>  
10.  Pass an array of numbers into a function and output the average number in the array of numbers.
11.  Demonstrate how to return an array of random numbers from a function.
12.  Demonstrate how to define an array argument as a reference type.
13.  Demonstrate how an array is passed through an argument by value
14. Create a text file and read the entire file into a single string.
15. Create a text file and read the file one character at a time
16. Create a text file with multiple lines and read those lines into an array.
17.  Create a text file with multiple lines, and read those lines one line at a time.

**************************************************************

Lab Three - due 11/30/09

1.   Create a demographics database with a table that contains the following fields:  country, primary language, and population.  Enter records for at least 10 countries.  You can find demographic information for various countries in many places on the Internet. Write queries that return the following:
a.  A list of all records sorted by country name
b.  The country with the highest population
c.  The country with the lowest population
d.  Countries that share a common language, such as French

2.  Create a database for a used car dealership that includes a table for inventory.  Include the following fields in the inventory table:  make, model, price and mpg (miles per gallon).  Enter at least 10 records into the table.  Write queries that return the following:
a.  All records
b.  Make, model, and price, sorted by make and model
c.  The make and model of the car that gets the best miles per gallon
d.  The make and model of the car that gets the worst miles per gallon.
e.  The make and model of the highest and lowest priced cars

3.  Create a Web page to be used for storing software development bug reports in a MySQL database.  Include fields such as product name and version, type of hardware, operating system, frequency of occurrence, and proposed solutions.  Include links on the main page that allows you to create a new bug report and update on existing bug report.

4.  Create a Web page that stores airline surveys in a MySQL database.  Include fields for date and time of the flight, flight number, and so on.  Also, include groups of radio buttons that allow the user to rate the airline on the following criteria:
a.  Friendliness of customer staff
b.  Space for luggage storage
c.  Comfort of seating
d.  Cleanliness of aircraft
e.  Noise level of aircraft

The radio buttons for each question should consist of the following options:  No Opinion, Poor, Fair, Good, or Excellent.  Store all the records in a MySQL table.  Include a View Past Survey Results button on the main survey page that displays a list of past survey results.