IT3505 2018 Part1
IT3505 2018 Part1
Important Instructions :
1
1) Which of the following statements about the PHP programming language is/are correct?
(a) PHP stands for “Hypermedia Preprocessor”.
(b) A PHP script should be surrounded by delimiters <?php> ....<?>
(c) All variable in a PHP script start with the symbol $.
(d) A PHP script can be included anywhere in a HTML script.
(e) A PHP script can be created by using any text editor.
i) Django
ii) CodeIgniter
iii) JavaScript
2
5) Consider the following statements.
i) When the GET method is used to submit data of a web Form to the server,
variables are displayed in the URL.
ii) The PHP statement fopen(“mydata.txt”,”r”); opens a file named
“mydata.txt” to which data can be written.
iii) The location of a script can be obtained from the PHP superglobal variable $_GET.
<?php
echo 2 + "1","2"+1;
?>
3
9) Which of the following PHP script(s) display the value 12 when executed?
(a) (b)
<?php <?php
$a = array(1,2,3,4,5,6); $a = array(1,2,3,4,5,6);
$sum = 0;$i = 0; $sum = 0;
while ($i < count($a)){ foreach ($a as $key=>$val){
if ($i % 2){ if ($val % 2){
$sum = $sum + $i; $sum = $sum + $key;
} }
$i++;
} }
echo $sum; echo $sum;
?> ?>
(c) (d)
<?php
$a = array(1,2,3,4,5,6); <?php
$sum = 0;$i = 0; $a = array(1,2,3,4,5,6);
while ($i < count($a)){ $sum = 0;
if ($i % 2){ foreach ($a as $key=>$val){
$sum = $sum +$a[$i]; if ($key % 2){
} $sum = $sum + $val;
$i++; }
}
echo $sum; }
?> echo $sum;
?>
(e)
<?php
$a = array(1,2,3,4,5,6);
$sum = array_sum($a);
echo $sum;
?>
4
11) Which one of the following statements about PHP user defined functions is/are correct?
(a) Each user defined function declaration should start with the reserved word def.
(b) Function names are case-sensitive.
(c) Function can have zero or more parameters.
(d) A function may not return any value.
(e) A function declaration may have other function declarations inside its body.
5
13) Consider the following PHP function declaration.
function f1($a){
if (count($a) == 0){
return 0;
} else {
return array_shift($a)+f1($a);
}
}
Note : The array_shift() function removes the first element (the element at index 0) from an
array, and returns the value of the removed element.
What would be the return value when this function is called as f1(array(1,2,3,4,5,6))?
(a) 1 (b) 6 (c) 7
(d) 4 (e) 21
14) What would be the output of the following script when executed?
<?php
$a = 10;
$b = 15;
function f1(&$a,$b){
$a = 20;
$b = 30;
}
f1($a,$b);
echo $a,",",$b;
?>
6
Questions (15), (16) and (17) are based on the code given below.
<?php
class Rectangle{
private $length,$width;
function __construct($length,$width){
$this->length = $length;
$this->width = $width;
}
function setLength($length){
$this->length = $length;
}
function setWidth($width){
$this->width = $width;
}
function area(){
return $this->length * $this->width;
}
function perimeter(){
return ($this->length + $this->width) * 2;
}
}
?>
15) Which of the following statements about the above definition is/are correct?
(a) Both setWidth($width)and area() are methods of the class.
(b) The function area() can be accessed only by the statements inside the class
declaration.
(c) The function setLength($length) is a public method of this class.
(d) The Rectangle class has a constructor.
(e) The __construct($length,$width)method is executed automatically
whenever new instances of this class are created.
16) Which of the following statement(s) would not result in an error when executed?
(a) $c = new Rectangle();
(b) $c = new Rectangle(5);
(c) $c = new Rectangle(5,10);
(d) $c = new Rectangle(5,5,10);
(e) new Square(5,10);
7
17) What would be displayed if the following statements are executed in the given order?
$s = new Rectangle (2,3);
echo $s->area($s->setLength(10)),",",$s->perimeter();
Questions (18), (19) and (20) are based on the HTML script given below.
<!DOCTYPE html>
<html lang="en">
<head>
<title>JQuery Examples</title>
<script src="https://code.jquery.com/jquery-
3.2.1.slim.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
var colour_n = "Red";
$("p.c1").click(function(){
$(this).hide();
});
$("p.c2").click(function(){
var colour_t = $(".c2").css("color");
$(this).css("color", colour_n);
colour_n = colour_t;
});
});
function display(){
$( ".c1" ).show();
}
</script>
</head>
<body>
<button type="button" onclick="display()">Display</button>
<p class="c1"> <b> First Paragraph </b> </p>
<p class="c2" style="color:Blue;"> <b> Second Paragraph </b>
</p>
</body>
</html>
8
18) Which of the following statements is/are correct when the HTML script is rendered by a web
browser?
(a) There would be a button on the rendered page.
(b) When rendered, it loads the jQuery library from the folder where the HTML
script is stored.
(c) There would be a paragraph with the text “First Paragraph” on the page.
(d) The text “First Paragraph” on the page would appear in red colour.
(e) There would be a paragraph with the text “This is a Paragraph” on the page.
************************