St. Name: ………………………………. St. #: …………………………………. Philadelphia University Lecturer(s): Dr. Murad Magableh Faculty of IT Department of MIS Internal examiner: Dr. Ali Alawneh Examination Paper --------------------------------------------------------------------------------------- (731213) Introduction to Web Programming 2nd Exam. 2nd Sem. 2014/2015 19/5/2015 Time: 50 min Information for Candidates This examination paper contains 4 questions totaling 20 marks. Advices to Candidates Attempt all questions. Read all questions carefully before answering. Allocate the available exam time to given questions properly Write your answers clearly. ------------------------------------------------------- Multiple choices question: Question Number Answer 1 C 2 C 3 D 4 C 5 B 6 A 7 A 8 C 9 D Page 1 of 6 St. Name: ………………………………. St. #: …………………………………. Philadelphia University Lecturer(s): Dr. Murad Magableh Faculty of IT Department of MIS Internal examiner: Dr. Ali Alawneh Examination Paper --------------------------------------------------------------------------------------- (731213) Introduction to Web Programming 2nd Exam. 2nd Sem. 2014/2015 19/5/2015 Time: 50 min Information for Candidates This examination paper contains 4 questions totaling 20 marks. Advices to Candidates Attempt all questions. Read all questions carefully before answering. Allocate the available exam time to given questions properly Write your answers clearly. ------------------------------------------------------- I. Basic Notions Objectives: the aim of the following question is to evaluate your basic knowledge. Q1: Select the correct answer from the choices given for the following questions: [9 marks] 1) What is the output of the following code: <?php $a[0]=7; $a[2]=5; $a[5]=33 echo count($a); ?> a) 5 b) 6 c) 3 d) 33 2) The output of the following code: <?php function f($x) { $var=1; $var++; return ($x + $var); } echo f(10); echo f(20); ?> a) 1121 b) 1020 c) 1222 Page 2 of 6 d) 1223 3) The output of the following code: <?php function f($x) { static $var=1; $var++; return ($x + $var); } echo f(10); echo f(20); ?> a) 1121 b) 1020 c) 1222 d) 1223 4) The value of $sum after executing the following code is: <?php $a = array(5, 10, 15, 20); $sum = 0; for($i=0; $i<=2; $i+=2) $sum += $a[$i]; ?> a) 10 b) 15 c) 20 d) 25 5) The output of the following code is: <?php $a = array(57, 35, 10, 7, 46, 72); sort($a); ksort($a); krsort($a); echo $a[0]; ?> a) 57 b) 7 c) 72 d) 0 6) The output of the following code is: <?php $a = array(57, 35, 10, 7, 46, 72); arsort($a); echo $a[0]; ?> a) 57 b) 7 c) 72 Page 3 of 6 d) 0 7) The output of the following code is: <?php $a = array(57, 35, 10, 7, 46, 72); list($x, $y) = each($a); $x++; $a[$x] = $y++; list($x, $y) = each($a); echo $y; ?> a) 57 b) 58 c) 35 d) 36 c) 012 d) 010 c) BCBC d) BB 8) The output of the following code is: <?php $var = 1; function fun() { global $var; echo $var; } echo ($var – 1); fun(); echo ($var + 1); ?> a) 011 b) 02 9) The output of the following code is: <?php $s = "B"; function fun() { $s = "BC"; } echo ($s); fun(); echo ($s); ?> a) BBC b) BBCB Page 4 of 6 II. Familiar problem solving Objectives: the aim of the following question is to evaluate your capabilities in solving familiar cases. Q2: Write a PHP function called Last_Letter($str) that receives a string and returns true if the last letter in the received string is "A". Otherwise, the function returns false. [2 marks] <?php function Last_Letter($str) { if(substr($str, -1) == "A") return true; else return false; } ?> Q3: What is the output of the following code fragments: <? function fun(&$a) { foreach($a AS $k1=>$v1) { $v1++; echo "$k1 - $v1 <br>"; } for($i=0; $i<2; $i++) $a[$i] = $i; foreach($a AS $k2=>&$v2) { echo "$k2 - $v2 <br>"; $v2++; } } $array = array("A"=>100, "B"=>200); foreach($array AS $k=>$v) echo "$k - $v <br>"; fun($array); foreach($array AS $k=>$v) echo "$k - $v <br>"; ?> Page 5 of 6 [6 marks] A - 100 B - 200 A - 101 B - 201 A - 100 B - 200 0-0 1-1 A - 101 B - 201 0-1 1-2 III. Unfamiliar problem solving Objectives: the aim of the following question is to evaluate your capabilities in solving unfamiliar cases. Q4: Write a PHP program that prints the following triangle of numbers using nested “for” loop. Each “echo” statement should print only one number. [3 marks] 1 2 5 3 6 8 4 7 9 10 <?php for($i=1; $i<=4; $i++) { $start = $i; $increment = 3; for($j=1; $j<=$i; $j++) { echo $start." "; $start += $increment; $increment--; } echo "<BR>"; } ?> GOOD LUCK Page 6 of 6