CSci 1101 Problem set 2. Due Thursday, February 22 at 10pm

Testing and submitting your programs.

Question 1

You are given the following file with HTML and PHP code:


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Author: Elena Machkasova elenam@morris.umn.edu
Last modified: 9/24/06
-->
<?php
$color1 = "#FFA500"; // orange
$color2 = "#8B0000"; // dark red
?>
<html>
<head>
<title>
Alternating colors example
</title>

</head>
<body>
<ol>
<li>List element</li>
<li>Another list element</li>
<li>And another one</li>

<li>Finally, the last one</li>
</ol>
</body>
</html>
  1. Copy-paste this code into a PHP file.
  2. Add PHP code so that the text color of the list elements alternates between the two colors specified in the variables $color1 and $color2. Make sure that you are using the color variables, not the colors themselves. Upload your file into your public_html on rynite (or, better yet, its subfolder). Test your program. Correct mistakes if any.
  3. Change the values of the two variables $color1 and $color2 to any other colors. Do not change anything else in the program. Upload the changed file and make sure that the list elements are now of the new colors.

Question 2

Your task is to write a PHP program that displays results of voting for two candidates as color bars of two different colors. The names of the candidates and the number of votes for each candidate are set as variables in the beginning of the program (in order to use the testing script, the number of votes should be passed to the program as an input, via $_GET['input1'] and $_GET['input2']).

The code shows a sample of displaying a color bar followed by the name of a candidate as a table. The width of the color bar, the name of the candidate, and the votes are all fixed in the example. You need to change the program so that all of these settings depend on the variables (for instance, if the number of votes changes from 15 to 20 in $votes1, the width of the color bar is automatically set to 100px). You also need to add another table to display the votes for the other person.

Format the page any way you like. Add a header to explain what the page is about.
Note the padding property for <td> in the embedded style sheet. Feel free to change it if you prefer a different format.

Make sure to check your page for several different names and numbers of votes.


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Author: Elena Machkasova elenam@morris.umn.edu
Last modified: 2/9/06
-->
<?php
$name1 = "Bart Simpson";
$name2 = "Lisa Simpson";
$votes1 = 15;
$votes2 = 12;
?>
<html>

<head>
<title>
Voting results
</title>
<style type="text/css">
td {padding: 3px}
</style>
</head>
<body>
<table>

<tr>
<td style="background: blue; height: 20px; width: 75px;" />
<td>
Bart Simpson 15
</td>
</tr>
</table>
</body>
</html>

Question 3

In the voting program in the previous question print out the name of the winner. If it's a tie, print out both names and a message saying that they got equal number of votes.

Question 4

Recall the program hours.php that prints a greeting based on the time of the day (the lecture examples are posted here). Change the program so that, instead of printing the greeting, it prints out the time in the standard am/pm format. For instance, if the input is 13, the program should print 1pm. If the input is less than 0 or greater than 23, the program should print "Invalid time".

Testing and submitting your code


This page is a part of CSci 1101 course web site.