DB-Intro-PHP-HW.docx CSCI 3343 Initials ______Page | 11

If this lab is an Individual assignment, you must do all coded programs on your own. You may ask others for help on the language syntax, but you must organize and present your own logical solution to the problem. No lab is complete until the student submits the signed pledge form associated with that lab. I realize that no coded programs will be graded until I turn in the sign & pledge form associated with that program; any late penalties will continue to compound until the pledge form is submitted.

If this lab is a team assignment, both team members may share logic as they program side by side on their own computers. Each person must type all of his/her own code as part of the learning process. Team assignments are never to be “You do this portion and I’ll do that portion” or “You do this lab and I’ll do the next lab”.

Some of the lab assignments will have short answer questions. These short answer questions will be spot checked and graded for completion, but not checked for accuracy. I encourage you to get into a study group to help each other prepare for exams, quizzes, etc. Once these labs are graded and returned, I encourage you to compare answers with another class member, in your study group, who has also had the lab graded and returned.

I/We realize that the penalty for turning in work that is not my own, or assisting others in doing so, can range from an "F" in the class to dismissal from Trinity University. I realize that it is a violation of academic integrity to share any portion of this lab with any person (outside my 3343 team & professor)!

Print Name ______Time Required = ______.____ Hrs.

Signature ______(pledged)

Print Name ______Time Required = ______.____ Hrs.

Signature ______(pledged)

______{Initial/Pledge} I have Web Pages working on my server.

______{Initial/Pledge} I have PHP working on my server.

DB Introduction To PHP
Individual/Team Assignment

35 Points

I am Providing A Word Document: If you would rather cut and paste code into this document, as opposed to hand writing it,
you may do so. Please submit a printed a copy of your completed lab.
Slides & Text

1] ______PHP is now an acronym for _?_.

2] ______PHP was created by _?_ in 1995. Not on exam.

3] ______PHP is a server-side S_?_ language designed for web development but also used as a general-purpose programming language

4] ______PHP is a middleM_?_ ware language that can be used with both the Apache Web Server and The Internet Information Server.

5] ______List at least two middleware languages.

6] ______{T/F} PHP is much slower than Perl and CGI alternatives.

7] ______{T/F} PHP is open source.

8] ______PHP tag sets begin with _?_ and end with _?_.

9] ______{T/F} There can be only one PHP tag set in a single document.

10] ______The extension on all php files ia _?_.

11] ______Write the php code to assign Dr.Tom Hicks to the variable Name.

12] ______PHP uses _?_ {static/dynamic} variable typing.

13] ______?_ ie the special PHP datatype for an unititalized variable.

14] ______Write the php code to place your name in a comment.

15] ______PHP variable x contains some value. Write a single line of PHP code which will display the contents of x in the following format:
x = whatever

16] ______PHP statements end with a(n) _?_.

17] ______PHP uses two different ways to display output. One is print and the other is _?_.

18] ______PHP uses two different ways to display output. One is echo and the other is _?_.

19] ______The PHP symbol for concatenation is _?_.

20] ______Write a line of code which will display the following in the second biggest and boldest code. Use your name.

21] Write a block of PHP code which will fill variables A with 1, B with 0, and C with -4.

22-28] Write the complete code for PHP function, called Quadratic, which could be inserted in the code below
<H2> Quadratic2 - Author : Dr. Tom Hicks </H2>
<?PHP

-?- FUNCTION Quadratic
$R2 = 0;
Quadratic (2, 4, -6, $R1, $R2);
print ("A = 2 <BR>");
print ("B = 4 <BR>");
print ("C = -6 <P>");
print ("R1 = " . $R1 . "<BR>");
print ("R2 = " . $R2 . "<BR>");
?>

to render:


29] ______{T/F} Suppose that, after rendering the code above, we were to display the source code through the web server; we would be able to see the code in function Quadratic.

30] ______Write the output from the following code.
$Type = gettype(15.75);
print ($Type);

31] ______Write the output from the following code.
$Type = gettype(true);
print ($Type);

32] ______Write the output from the following code.
$X = 5;
$X += 3;
$X /= 4;
print "X = " . $X . "<BR>";

33] ______Write the output from the following code.
$X *= 17;

$X %= 5;
print "X = " . $X . "<BR>";

34-38] Write the complete code for function FirstPrime which could be inserted in the block of PHP code below. This function is to explicitly return a string à the string will contain "0" if there is no prime. This function will return "INVALID - No must be greater than 0" if the number is greater than 20. This function will return "INVALID - No must be less than 50" if the number is greater than 20. Otherwise, this function is to explicitly return a string containing the lowest prime number of $No Less Than Or Equal To No. You must solve this with if-then-else.

<H2> FirstPrime - Author : Dr. Tom Hicks </H2>

<?PHP

-?- FUNCTION FirstPrime

print "First Prime <= 15 = " . FirstPrime(15) . "<BR>";

print "First Prime <= 11 = " . FirstPrime(11) . "<BR>";

print "First Prime <= 25 = " . FirstPrime(25) . "<BR>";

print "First Prime <= -1 = " . FirstPrime(-1) . "<BR>";

?>


Rendered would be:


39-40] Write a block of PHP code which will display the first 40 numbers in the sequence 1, 2, 3, 4. … à ten to a line. You must use a posttest loop. Include one blank between numbers.

41-42] Write a block of PHP code which will display 100 random numbers in the range 1-9 à ten to a line. You must use a posttest loop. Include one blank between numbers. Begin with the block of code:

srand(3343);

$pos = 1;

43-44] Write a block of PHP code which will display 100 random numbers in the range 10-25 à ten to a line. You must use a posttest loop. Include one blank between numbers. Begin with the block of code:

srand(3343);

$pos = 1;

45-46] Write a block of PHP code which will display the first 30 numbers in the sequence -2. 1, 4, 7, ... à eight to a line You must use a posttest loop. Include one blank between numbers. Begin with the block of code:

srand(3343);

$pos = 1;

47-48] Write a block of PHP code which will display the first 30 numbers in the sequence 4, 9, 14, 19, ... You must use a posttest loop. Include one blank between numbers.

49-50] Look up the PHP command to set the seed of the random number generator à srand à in the space below, describe what srand does,

______

______

______

______

51-54] Write the complete code for function RandNo which is passed integers Low & High. Explicitly return a random number in the range Low <= X <= High. Do not use srand. Return "INVALID” if Low > High. When executing the block of code:

srand(3343);

for ($Pos = 1; $Pos <= 100; $Pos ++)

{

print RandNo (5,10) . " ";

if ($Pos % 10 == 0)

print "<BR>";

}

print "<P>" . RandNo (7,3) . "<P>";

you should get the output :

55-56] Write a block of PHP code which will display the first 40 numbers in the sequence 1, 2, 3, 4. … à ten to a line. You must use a posttest loop. Include one blank between numbers.

57-58] Write a block of PHP code which will display 100 random numbers in the range 1-9 à ten to a line. You must use a pretest loop. Include one blank between numbers. Use function RandNo. Begin with the block of code:

srand(3343);

$pos = 1;

59-60] Write a block of PHP code which will display 100 random numbers in the range 10-25 à ten to a line. You must use a pretest loop. Include one blank between numbers. Begin with the block of code:

srand(3343);

$pos = 1;

61-62] Write a block of PHP code which will display the first 30 numbers in the sequence -2. 1, 4, 7, ... à eight to a line You must use a pretest loop. Include one blank between numbers.

63-64] Write a block of PHP code which will display the first 30 numbers in the sequence 4, 9, 14, 19, ... You must use a pretest loop. Include one blank between numbers.

65-66] Write a block of PHP code which will display the first 40 numbers in the sequence 1, 2, 3, 4. … à ten to a line. You must use a fixed repetition loop. Include one blank between numbers.

67-68] Write a block of PHP code which will display 100 random numbers in the range 1-9 à ten to a line. You must use a fixed repetition loop. Include one blank between numbers. Use function RandNo. Begin with the block of code:

srand(3343);

$pos = 1;

69-70] Write a block of PHP code which will display 100 random numbers in the range 10-25 à ten to a line. You must use a fixed repetition loop. Include one blank between numbers. Begin with the block of code:

srand(3343);

$pos = 1;

71-72] Write a block of PHP code which will display the first 30 numbers in the sequence -2. 1, 4, 7, ... à eight to a line You must use a fixed repetition loop. Include one blank between numbers.

73-74] Write a block of PHP code which will display the first 30 numbers in the sequence 4, 9, 14, 19, ... You must use a fixed repetition loop. Include one blank between numbers.

75] ______Write one line of PHP code to create an array, called Faculty, and fill it with Hicks, Myers, Massingill, Lewis.

76] ______Write a block of PHP code which will display the number of elements in array Faculty as illustrated below:

77-78] Write a block of PHP code which contains a for loop which will display the elements of Faculty as illustrated below:

79-80] Write a block of PHP code which contains a foreach loop which will display the elements of Faculty as illustrated below:

81-82] ______Write the output from the following block of PHP code:
$Staff[0] = "Tom";
$Staff[2] = "Dick";
$Staff[1] = "Harry";
foreach ($Staff As $Staffer)
print $Staffer . ", ";

83-84] ______Write the output from the following block of PHP code:
$Staff[0] = "Tom";
$Staff[2] = "Dick";
$Staff[1] = "Harry";
for ($pos = 0; $pos < count($Staff); $pos ++)
print $Staff[$pos] . ", ";

85-86] ______Write the output from the following block of PHP code:
$Nos = Array(3, 4, 8, 1, 2, 7, 6, 5);
ASort($Nos);
foreach ($Nos As $No)
print $No . ", ";

87-88] ______Write the output from the following block of PHP code:
$Folks = Array("Jane", "Ann", "Tony", "Jill", "Karen");
ASort($Folks);
foreach ($Folks As $Folk)
print $Folk . ", ";

What To Turn In

1] All pages of this lab with questions completed.

------No Lab Is Complete Until Both Are Complete ------

1] You sign & submit the Pledge form at the top of this lab!. No Lab Will Be Considered Complete until this is done. Late penalties will continue to accrue until the pledge form is submitted.

a)  Sign & Pledge

b)  Record the amount of time you think you spent on this lab

c)  Staple all pages of this lab. Fold in half length-wise (like a hot-dog). Put your name on the outside. Place it on the professor desk before the beginning of lecture on the day it is due. The penalty for late homework will not exceed 25% off per day.

d)  Short answer questions must be hand written, unless the professor has granted an exception for physical reasons.

2] Place all programming code associated with this program, if any, in the Professor’s Code Drop Box or on the Virtual System as directed.
I do not accept programs by mail; do not submit labs via email!