CMSY-203: Introduction to PHP
Fall 2011: Janak Rajani
HOWARD COMMUNITY COLLEGE
Name and Type of Assignment: Assignment-1, take-home programming assignment
% of the Course Final Grade: 10%
Due Date: October 5, 2011 (Wednesday)
Purpose: This is a programming assignment that students will do at-home. Students can use
textbook or any other reference material. The idea is to get good hands on programming
experience in PHP using the programming constructs taught in the class.
Write PHP code for the following problem statements. For each numeric entry make sure that the
data entry contains numbers only. (Hint: use is_numeric function).
1. You can determine whether a year is leap year by testing if it is divisible by 4. However, years that are
also divisible by 100 are not leap years, unless they are also divisible by 400, in which case they are leap
years. Write a script that allows a user to enter a year and then determines whether the year entered is a
leap year. Use a PHP document and an HTML document containing a form with a single text box to enter
the year. Print a message to the user stating whether the year they entered is a standard year or a leap
year. Save the documents as LeapYear.php and LeapYear.html, respectively. (2 points)
2. The combined length of any two sides of a triangle must be greater than the length of the third side for the
segments to form a triangle. For example, 6, 8, and 12 can form a triangle because the sum of any two of
the three segments is greater than the third segment. However, 25, 5, and 15 cannot form a triangle
because the sum of segments 5 and 15 are not greater than the length of segment 25. Using this logic,
write a script that allows a user to enter three integers, one for each side of a triangle. Test whether the
three sides form a triangle. Use a PHP document and an HTML document containing a form with three
text boxes to gather the segment lengths from the user. Print a message to the user that states whether
their segments can form a triangle. Save the documents as Triangle.php and Triangle.html,
respectively. (2 points)
3. Write a script that allows a user to enter a number between 1 and 999. Determine whether the number is
a prime number and display your results with a print() statement. A prime number is a number that can
only be divided by itself or by one. Examples of prime numbers include 1, 3, 5, 13, and 17. Use a PHP
document and an HTML document containing a form with a single text box in which users can enter a
number. You need to use a looping statement to test all division possibilities. Save the document as
PrimeNumber.php and PrimeNumber.html, respectively. (2 points)
4. Create a script that calculates an employee’s weekly gross salary, based on the number of hours worked
and an hourly wage that you choose. Use a PHP document and an HTML document containing a form
with two text boxes – one for the number of the house worked and the other for the hourly wage.
Compute any hours over 40 as time-and-a-half. Use the appropriate decision structure to create the
program. Save the documents as PayCheck.php and PayCheck.html, respectively. (2 points)
5. Write a script that allows users to enter a number of cents into a text box. Use a PHP document and an
HTML document containing a form with a single text box to enter the number of cents. Determine how
many dollars the cents make up and print the number of dollars and remaining cents. Save the
documents as CentsToDollars.php and CentsToDollars.html, respectively. (2 points)