St. Name: ………………………………. St. #: …………………………………. Philadelphia University Lecturer(s): Faculty of IT Department of MIS Internal examiner: Examination Paper --------------------------------------------------------------------------------------- (731213) Introduction to Web Programming 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: 1) The output of the following code is: <?php function f($x) { $x=1; $x++; return ($x); } echo f(1); echo f(2); ?> a) 12 b) 23 c) 22 d) 1122 2) The output of the following code is: <?php function f() { static $var=10; $var++; return ($var); } echo f(); echo f(); ?> a) 1112 b) 1010 3) The output of the following code is: c) 12 Page 1 of 6 d) 1211 [5 marks] <?php $x=6; do { echo "The number is: $x <br>"; $x++; } while ($x<=5); ?> a) 10 b) 6 c) 2 d) 5 4) The output of the following code is: <?php $s = ‘ali’; function fun() { $s=’ola’; } echo ($s); fun(); echo ($s); ?> a) aliola b) aliali c) olaola d) olaali 5) The output of the following code is: <?php $s = ‘ali’; function fun() { global $s; $s=’ola’; } echo ($s); fun(); echo ($s); ?> a) aliola b) olaali c) aliali Q2. Find the output of the following code: Page 2 of 6 d) olaola A) [2 marks] <?php for($j=3; $j>0; $j--) switch($j-1) { case 2: echo "HI<br>"; break; case 1: echo "BYE<br>"; break; default: echo "Chow<br>"; } HI BYE Chow ?> B) [2 marks] <? function test(&$b) { $b++; echo ++$b; $b = $b++ + 4; echo $b; } $y=2; test($y); echo $y; ?> 488 [3 marks] C) Page 3 of 6 <? define("X", "0"); define("Y", "1"); define("Z", "2"); $a = ""; $b = "ABC"; $c = 5; if(empty($a)) echo "X"; else echo "Y"; if($a++-1==5 xor $b==Y) echo "A"; else echo "B"; if(X==empty($a)) echo "X"; else echo "Y"; if(isset($a)) echo "A"; else echo "B"; if($a++-1==5 xor $b=Y) echo "A"; else echo "B"; XBXAAB if(empty($a)==isset($a)) echo "A"; else echo "B"; ?> Page 4 of 6 II. Familiar problem solving Objectives: the aim of the following question is to evaluate your capabilities in solving familiar cases. Q3: Write a function that receives a number and returns 1 if the received number is perfect. Otherwise, the function returns 0. [5 marks] Hint: A perfect number is a positive integer that is equal to the sum of it’s positive integral factors including 1 but excluding itself . <? function isP($x) { $c = 0; for($i=1; $i<$x; $i++) if($x%$i==0) $c=$c+$i; if($c==$x) return 1; else return 0; } echo isP(6); ?> Page 5 of 6 III. Unfamiliar problem solving Objectives: the aim of the following question is to evaluate your capabilities in solving unfamiliar cases. Q4: Write a function that calculates and returns the average of the numbers between 1 and 100 that are a multiple of five and even. [3 marks] <? function fun1() { $c = 0; $sum = 0; for($i=1; $i<=1000; $i++) if($i%5==0 and $i%2==0) { $c++; $sum+=$i; } return $sum/$c; } echo fun1(); ?> GOOD LUCK Page 6 of 6