Assignments
Assignment 5
Due on Thursday, December 11
Problems (25 points each, total 100 points):
- Deitel p. 903, 22.4
- Write SQL queries for the books database (discussed in Section 22.3)
that perform each of the following tasks:
- Select all authors from the Authors table with the columns in the
order lastName, firstName and authorID.
- Select a specific author and list all books for that author. Include
the title, year and ISBN number. Order the information alphabetically
by title.
- Add a new author to the Authors table.
- Add a new title for an author (remember that the book must have an
entry in the AuthorISBN table).
- Deitel p. 955, 23.4
- Write a PHP regular expression pattern that matches a string that satisfies
the following description: The string must begin with the (uppercase) letter
A. Any three alphanumeric characters must follow. After
these, the letter B (uppercase or lowercase) must be repeated
one or more times, and the string must end with two digits.
- Deitel p. 955, 23.5
- Describe how input from an XHTML form is retrieved in a PHP program.
- Deitel p. 955, 23.8
- Write a PHP script that tests whether an e-mail address is input correctly.
Verify that the input begins with series of characters, followed by the
@ character, another series of characters, a period (.),
and a final series of characters. Test your program, using both valid
and invalid e-mail addresses.
Assignment 4
Due on Wednesday, November 26
Problems (25 points each, total 100 points):
- Deitel p. 514, 13.3
- Add an erase feature to the drawing program in Fig. 13.3. Try setting
the background color of the table cell over which the mouse moved to white
when the Alt key is pressed.
<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- Fig. 13.3: draw.html -->
<!-- A simple drawing program ->
<html xmlns = "http://www.w3.org/1999/xhtml"><head>
<title>Simple Drawing Program</title>
<style type = "text/css">
#canvas { width: 400px;
border: 1px solid #999999;
border-collapse: collapse}
td { width: 4px;
height: 4px }
th.key { font-family: arial, helvetica, sans-serif;
font-size: 12px;
border-bottom: 1px solid #999999 }
</style>
<script type = "text/javascript">
<!-
// initialization inserts cells into the table
function createCanvas ()
var side = 100;
var tbody document.getElementById ("tablebody");
for (var i = 0; i < side; i++) {
var row = document.createElement ("tr");
for (var j = 0; j < side; j++) {
var cell = document.createElement ("td");
cell.onmousemove = processMouseMove;
row.appendChild (cell);
}
tbody.appendChild (row);
}
}
// draws when mouse is moved by turning cells red or blue
function processMouseMove (event) {
// get IE event
if (! event) {event = window.event;}
// turn cell blue if Ctrl key is pressed
if (event.ctrlKey) {this.style.backgroundColor = "blue";}
// turn cell red if Shiftkey is pressed
if (event.shiftKey) {this.style.backgroundColor = "red";}
}
// -->
</script>
</head> <body onload = "createCanvas()">
<table id ="canvas" class="canvas"><tbody id="tablebody">
<tr><th class="key" colspan="1OO">Hold <tt>ctrl</tt>
to draw blue. Hold <tt>shift</tt> to draw red.</th></tr>
</tbody></table>
</body> </html>
- Deitel p. 514, 13.6
- Write a function that responds to a click anywhere on the page by displaying
an alert dialog. Display the event name if the user held Shift during the
mouse click. Display the element name that triggered the event if the user
held Ctrl during the mouse click.
- Deitel p. 587, 14.7
- (Nutrition Information XML Document) Create an XML document that marks
up the nutrition facts for a package of Grandma White's cookies. A package
of cookies has a serving size of 1 package and the following nutritional
value per serving: 260 calories, 100 fat calories, 11 grams of fat, 2 grams
of saturated fat, 5 milligrams of cholesterol, 210 milligrams of sodium,
36 grams of total carbohydrates, 2 grams of fiber, 15 grams of sugars and
5 grams of protein. Name this document nutrition.xml. Load the
XML document into Internet Explorer.
[Hint: Your markup should contain elements describing the product name,
serving size/amount, calories, sodium, cholesterol, proteins, etc. Mark
up each nutrition fact/ingredient listed above.]
- Deitel p. 587, 14.8
- (Nutrition Information XML Schema) Wtite an XML Schema document (nutrition.xsd)
specifying the structure of the XML document created in Exercise 14.7.
Assignment 3
Due on Thursday, October 30
Problems (20 points each, total 100 points):
- Deitel p. 486, 12.3 (Use an arbitrary web page, not necessarily Deitel's
self-advertising one:)
- Deitel p. 486, 12.5
- Deitel p. 486, 12.6
- You can use the Firebug debugger to explore the properties of the document
DOM element and to determine which of these properties have the type HTMLCollection.
E.g. anchors, forms,
images, links,
etc. Output the length of each of these collections separately. The form
of the output is up to your taste.
- Deitel p. 486, 12.7
- Define some identifiable elements (via the id
attribute) and several css classes. Let the user choose a class (e.g. through
a <select> element
with <option>
elements) and set the style class of the identifiable elements to class
the user choose.
- Deitel p. 486, 12.10
- Create a table with 4 rows and 4 columns, either as XHTML elements/tags
or using a JavaScript function (see the Chess
Board for a similar example). Make sure that the <img>
elements in the table cells can be easily identified, e.g. with their
row and column index. When the user clicks, a function should be called
that performs the necessary shifting of the tiles. I'd recommend to
pass the row and column as parameters. Create an array with the urls
of all images of the 15 tiles. (You can use these images.)
Shuffle the array. (The corresponding function is here.)
Assign the src
attribute of the <img>
elements using the shuffled urls leaving the last empty. Memorize the
empty place in global variable(s). So far, it should be quite straightforward.
- The shifting function is more complex even though it can be accomplished
in less than 10 lines of code (albeit algorithmically a bit demanding
ones): Eliminate wrong clicks. Then go from the empty place to the tile
clicked shifting the src attribute from the next <img>
element to the current one. This is quite similar to going through a
linked list or shifting the values in a (sub)array. (You can go the
other way, but it's a bit less straightforward...) A challenge: You
may think that you need to have two for-loops - one if the shift is
within a row and another if it's within a column, but it can be accomplished
with just one loop! Finally, don't forget to make the clicked <img>>
empty (set its src
property to "")
and remember the empty place. That's it!
Assignment 2
Due on Friday, October 17
Problems (20 points each, total 100 points):
- Deitel p. 357, 9.7
- Write a script that prompts the user for the radius of a circle, uses
a function circleArea()
to calculate the area of the circle, and prints the area of the circle.
- Deitel p. 359, 9.19
- Implement the following functions:
- a) Function celsius()
returns the Celsius equivalent of a Fahrenheit temperature, using the calculation
C = 5.0 / 9.0 * ( F - 32 );
- b) Function fahrenheit()
returns the Fahrenheit equivalent of a Celsius temperature, using the calculation
- c) Use these functions to write a script that enables the user to enter
either a Fahrenheit or a Celsius temperature and displays the Celsius or
Fahrenheit equivalent. Your XHTML document should contain two buttons-one
to initiate the conversion from Fahrenheit to Celsius and one to initiate
the conversion from Celsius to Fahrenheit.
- Deitel p. 360, 9.28 (includes 9.27)
- Write a program that will help an elementary-school student learn multiplication.
Use Math.random()
to produce two positive one-digit integers. It should then display a question
such as How much is 6 times 77?
The student then types the answer into a text field. Your program checks
the student's answer. If it is correct, display the string "Very
good!" and generate a new question. If the answer is wrong, display
the string "No. Please try again."
and let the student try the same question again repeatedly until the student
finally gets it right. A separate function should be used to generate each
new question. This function should be called once when the script begins
execution and each time the user answers the question correctly.
The use of computers in education is referred to as computer-assisted instruction
(CAI). One problem that develops in CAI environments is student fatigue.
This problem can be eliminated by varying the computer's dialogue to hold
the student's attention. Modify the above program to print one of a variety
of comments for each correct answer and each incorrect answer. The set of
responses for correct answers is as follows:
- Very good!
- Excellent!
- Nice work!
- Keep up the good work!
- The set of responses for incorrect answers is as follows:
- No. Please try again.
- Wrong. Try once more.
- Don't give up! No.
- Keep trying.
- Use random number generation to choose a number from 1 to 4 that will
be used to select an appropriate response to each answer. Use a swich
statement to issue the responses.
- Deitel p. 360, 9.31 (includes 9.30)
- Write a script that plays a "guess the number" game as follows: Your program
chooses the number to be guessed by selecting a random integer in the range
1 to 1000. The script displays the prompt Guess
a number between 1 and 1000 next to a text field. The player
types a first guess into the text field and clicks a button to submit the
guess to the script. If the player's guess is incorrect, your program should
display Too high. Try again.
or Too low. Try again.
- to help the player "zero in" on the correct answer -, and it should clear
the text field so the user can enter the next guess. When the user enters
the correct answer, display Congratulations.
You guessed the number! and clear the text field so the user
can play again. [Note: The guessing technique employed in this problem is
similar to a binary search, which we discuss in Chapter 10, JavaScript:
Arrays.]
Modify the above program to count the number of guesses the player makes.
If the number is 10 or fewer, display Either
you know the secret or you got lucky! If the player guesses the
number in 10 tries, display Ahah!
You know the secret! If the player makes more than 10 guesses,
display You should be able to
do better! Why should it take no more than 10 guesses? Well,
with each good guess, the player should be able to eliminate half of the
numbers. Now show why any number 1 to 1000 can be guessed in 10 or fewer
tries.
- Deitel p. 361, 9.35
Assignment 1
Due on Friday, September 19
See Assignments Policies for submission
guidelines.
Problem 1 (30+ points):
Describe the next great idea for a Web N.0 application that will earn you a
billion $s!
Requirements:
- The application should be feasible, i.e. it can be implemented with the
current technology, or with technology that is likely to become available
before the end of 2010.
- The application should not require more than 5 man-years, i.e. 10 good web
programmers/designers should be able to implement it in less than 6 months.
- You must be able to describe it on half a page.
Hint: Think of what were such great ideas in the (very recent) past:
- Sharing pictures, than videos (Flickr, YouTube)
- Social Networking (Facebook, LinkedIn)
- Encyclopedia (Wikis)
- Free Ads (Craiglist)
- Targeted Ads (AdSense/Google)
- Auctions (eBay)
- etc., etc.
(Most are pretty obvious ideas, and were even then when they were implemented,
don't you think so? And, yes some didn't make billions of $s, but they probably
would if the authors only wanted it!)
After you submit this assignment, the TA will collect all the submitted ideas
and publish them anonymously. Every one of you will then have 3 points to give
to ideas that you like most. (You can give all 3 to one idea, or give one point
to 3 ideas, or split your points between two ideas. You have to distribute all
of your 3 points and cannot give any points to your own idea.) The TA and I
can each allocate up to 15 points to each student's idea. We will publish the
results. (Of course anonymously.)
Problem 2 (30 points):
Look on the web for a web site of a well known entity (big computer company,
famous university, online shopping giant, major search engine, or even a presidential
candidate?) which uses XHTML and CSS in their web pages. Download the W3C validators
for XHTML and CSS and run a few (+- 10) of their pages through the validator.
How do they fare? Look for a web site with many errors. Write a short analysis
of the errors. The three students who find the most (sufficiently distinct)
errors will get up to 5 bonus points!
Problem 3 (10 points each, total 30 points):
- Deitel p. 158, 4.18
- Deitel p. 196, 5.8
- Deitel p. 196, 5.9