Assignment 3
-- Control structures, Functions
The information needed to complete this assignment is covered in Sklar chapters 3-6. I suggest that you have your copy of Sklar available as a reference while you work on your labs.
You may use the HTML from the samples for formatting. Name your scripts with the file names used in the examples. Your output should look like the samples.
- ForLoop.php -- Write a script that loops a number of times specified by the user.
- ForLoopTable.php --Row data is usually displayed in a table. Modify the previous exercise to write your script output to a table.
- ForLoopNested.php -- Let's add some columns to our table. Modify the previous exercise to write a table with multiple rows and columns. Write the row and column number in each cell.
- Tip: Modify the previous exercise by nesting a For Next "column" loop inside the existing "row" loop. The nested loop will produce the table columns.
- ValidInput.php -- It is important to validate all user entries so that invalid data does not cause our script to crash or misbehave. Modify this script to alert the user if they input a non-numeric input or a value greater than 10. Use the is_numeric
function to check for numeric data and a comparison operator to check that
the values are within the range 1 to 10 (inclusive).
- SalesCalc.php -- Write a script that computes the sales information shown in the example. Validate the form input data to make sure it is numeric. Do not show a warning with the page initially loads or the calculations until valid input has been received from the form. Tips:
- Use two nested if statements to validate the data. The first checks to see if anything has been entered and does not produce a warning if empty (for when the page initially load. The second checks the datatype and produces a warning if not numeric. The HTML table that displays the calculations is inside the code block for the if statements.
- Use the number_format() function to format the numeric output in a currency format. Google "php number_format" for documentation.
- FontPicker.php -- Modify the class example FunkyFont.php (source) to use five additional fonts. Steps:
- All the images are stored on Yorktown and may be referenced from their current location (no need to copy the images). The common portion of each path is:
"<img src='/sandvig/images/alphabet/"
- The images for each font is stored in a separate folder. Each font uses a slightly different naming convention. The naming convention for each font is (where x is the character desired) is shown in the table below. Look at the image tags in the sample to see a complete image path.
| Font |
Directory & File |
| Chunk Red |
chunk/red/x9.jpg |
| Deco Blue |
deco/blue/x1.gif |
| Animals |
animals/x4.gif |
| Elegant Red |
elegant/red/4x.gif |
| Funky |
funky/x3.jpg |
| Tape Punch |
punch/black/x7.gif |
- You can copy the HTML for the radio button list from the sample.
- Use a series of IF ELSEIF statements or a switch statement (documentation) to display the appropriate font.
- The readability of your code can be improved significantly by using a function to break out the code that selects & writes the image tags. For instance, the sample script uses a function fWriteChar($char, $font). It accepts a single character and the name of the font and writes the appropriate image tag.
- Replace spaces in the message with <br> tags.
- Optional: to line breaks in your HTML source code (for code beautification) include \n in your output.