THE UNIVERSITY OF DODOMA

COLLEGE OF INFORMATICS AND VIRTUAL EDUCATION

SCHOOL OF INFORMATICS


UNDERGRADUATE UNIVERSITY EXAMINATION

FIRST SEMESTER 2017/2018


Course Code: CS 312

Course Title: INTERNET PROGRAMMING AND APPLICATIONS

Date: 20th February 2018

Time Allocated: 3 Hours


INSTRUCTIONS TO CANDIDATES:

  1. Closed Book Examination.
  2. This examination consists EIGHT questions.
  3. Answer all questions in Section A and only three (3) questions from Section B.
  4. All University of Dodoma examination regulations apply.

SECTION A: (40 Marks)

Question One

Choose the letter of the most correct answer. (1 Mark Each)


i. microtime() returns

(a) current Unix timestamp with seconds (b) current Unix timestamp with nanoseconds (c) current Unix timestamp with microseconds (d) None of the above


ii. In which circumstance it is not possible to assign default value to a parameter while declaring a function?

(a) When the parameter is Boolean (b) When the function is being declared as a member of a class (c) When the parameter is being declared as passed by reference (d) When the function contains only one parameter


iii. The function _____ automatically transforms newline characters into HTML <br /> tags.

(a) br2nl (b) nl2br (c) nlbr (d) None of the above


iv. By default, PHP stores session data in

(a) The filesystem (b) A database (c) Virtual memory (d) Shared memory


v. How would you store an array in a cookie?

(a) By adding two square brackets ([]) to the name of the cookie (b) By using the implode function (c) It is not possible to store an array in a cookie due to storage limitations (d) By using the serialize function (e) By adding the keyword ARRAY to the name of the cookie


vi. What is the correct CSS syntax for making all the <p> elements bold?

(a) p {text-size:bold} (b) p {font-weight:bold} (c) style:bold (d) p{font:bold} (e) All of the above.


vii. How do you make a list that lists its items with squares?

(a) type: square (b) list-style-type: square (c) list-type: square (d) style-list: square (e) style-list-type: square


viii. What is the correct HTML for referring to an external style sheet?

(a) <link rel="stylesheet" type="text/css" href="mainstyle.css"> (b) <style src="mainstyle.css"> (c) <stylesheet>mainstyle.css</stylesheet> (d) <link url="stylesheet" type="text/css" href="mainstyle.css"> (e) <link src="stylesheet" type="text/css" href="mainstyle.css">


ix. Which property in Javascript would you use to redirect visitor to another page?

(a) window.location.href (b) document.href (c) java.redirect.url (d) link.redirect.href (e) header(‘Location: url’)


x. What happens when a form submitted to a PHP script contains two elements with the same name?

(a) They are combined in an array and stored in the appropriate superglobal array (b) The value of the second element is added to the value of the first in the appropriate superglobal array (c) The value of the second element overwrites the value of the first in the appropriate superglobal array (d) The second element is automatically renamed (e) PHP outputs a warning


Question Two

(a) What is the value displayed when the following is executed? [2 Marks]

<?php
$y = 3;
$z = 5;
$x = ++$y + $z--;
echo $x;
?>

(b) What is the output of the following PHP script? [2 Marks]

<?php
$a = 5;
$b = 2;
$c = $a % $b;
echo $c;
?>

(c) What is the output of the following script? [2 Marks]

<?php
$a = "b";
$b = 20;
$a .= 11;
echo $$a;
?>

(d) What will be the output of the following script? [2 Marks]

<?php
define('FOO', 10);
$array = array(10 => FOO, "FOO" => 20);
print $array[$array[FOO]] * $array["FOO"];
?>

Question Three

Answer the following questions. (2.5 Marks Each)


a) What is a Document Type Definition (DTD)? What DTD do you generally use? Why? What are its Pros and cons.


b) Write a snippet of CSS that will display a paragraph in blue in older browsers, red in newer browsers, green in IE6 and black in IE7.


c) With the help of a code segment, describe three different ways that can be used to create a JavaScript object.


d) Explain two advantages of using XML.


e) How can we get the browser properties using PHP? (From the provided text: “5- SERVER(HTTP- USER- AGENT)?“)


Question Four

Answer the following questions. (2.5 Marks Each)


(a) How can we get the browser properties using PHP?


(b) How can we increase the execution time of a PHP script?


(c) How can we optimize or increase the speed of a MySQL select query?


(d) How can I know that a variable is a number or not using a JavaScript?


(e) How can we send mail using JavaScript?


(f) How can we know the number of days between two given dates using PHP?


SECTION B (60 Marks)

Attempt ANY THREE questions from this section.


Question Five

(a) With the help of Php and XHTML write script that can be used to upload and extract a zipped file in the server. [10 Marks]


(b) Use the code snippet 1 to:

Code Snippet 1 (HTML):

<!DOCTYPE html>
<html>
<head>
    <title>Sample Page</title>
</head>
<body>
    <h1 class="h">Main Heading</h1>
    <p id="para1">This is paragraph one with id para1.</p>
    <p class="h">This is paragraph two with class h.</p>
    <div class="h">This is a div with class h.</div>
    <p>This is a normal paragraph.</p>
</body>
</html>

(i) Prepare an internal style sheet which will use only group selectors (minimize code) to change the font color of all text to red and change all texts to uppercase. [3 Marks]


(ii) Write a style to change the color of the element with id=“para1”, to “red” and align text to center. [3 Marks]


(iii) Write a style to change the color of the element with class=“h”, to “red” and hide the elements when mouse hover it (Use CSS pseudo classes). [4 Marks]


Question Six

Write the JavaScript code for a basic vocabulary quiz built using Ajax and JSON that allows the user to try to guess the definitions to randomly chosen words from the server. The quiz data comes from a web service named word.php, located on your web server in the same directory as your code. Contact this service with a GET parameter of part for a part of speech such as noun or adjective. It outputs JSON data about a random dictionary word and several possible definitions for the word (at least 2 definitions, of which exactly 1 is correct) in the following format. For example, a request to word.php?part=noun might return:

{
    "word": "neophyte",
    "part": "noun",
    "choices": [
        {"definition": "a person who excels in telling anecdotes", "correct": false},
        {"definition": "evenness of mind especially under stress", "correct": false},
        {"definition": "a new convert; proselyte", "correct": true},
        {"definition": "degree of mixture with base metals; fineness", "correct": false},
        {"definition": "rigor, severity", "correct": false}
    ]
}

When the page loads, contact the web service with Ajax. Display the random word and its part of speech in the “word” area. Display all of the possible definitions as buttons in the “choices” area. When the user clicks a button to guess the definition, display an alert message of either “You are correct” or “You are incorrect” appropriately, and then once the alert box is closed, start a new quiz by fetching a new word and displaying it and its definitions to the user. At any time the user can change the part of speech from the select box, which should affect any future words.

The relevant existing HTML in the page is the following:

<h1>Vocab-It</h1>
<fieldset>
    <legend>part of speech:</legend>
    <select id="part">
        <option>noun</option>
        <option>verb</option>
        <option>adjective</option>
    </select>
</fieldset>
<div id="word"></div>
<div id="choices"></div>
<div id="result"></div>

For the example JSON shown above, the page would look as follows. The three screenshots show the page’s initial state, the state after a button is clicked, and then the state after the alert box is closed and a new word is fetched.

You may assume that the JSON data is valid in the format described previously, and that the .php service is reachable. Do not use any JavaScript libraries such as jQuery or Prototype. [20 Marks]


Question Seven

Write the JavaScript code to add behavior to the following page for finding palindromes. A palindrome is a word that is spelled the same forward as backward, such as “madam” or “Anna”. The page UI allows the user to type a phrase into a text box. The user can click a “Find Palindromes” button to find palindrome words in that phrase. Match case-insensitively; for example, “rotOR” is a palindrome. You may assume that words in the phrase are separated by single spaces and contain only letters. A one-letter word such as “I” is defined to be a palindrome.

Each palindrome found should be inserted as a bullet into a list with the id of palindromes. Every other palindrome (the first, third, fifth, etc.) should be given a gray background color of CC0000. Underneath the list of palindromes you should display text such as “5 total palindrome(s)” in the div with id of count.

The user can optionally specify a minimum and maximum word length by typing integer values into two text boxes with id of min and max respectively. If a minimum is specified, you should include only palindrome words that contain at least that many letters inclusive. If a maximum is specified, you should include only palindrome words that contain at most that many letters inclusive. If the min or max is left blank, the length is unbounded in that direction. For example, a minimum of 3 and a blank maximum finds all palindromes of at least 3 letters. You may assume that the text typed in these boxes will either be blank or a valid non-negative integer, and that max will be ≥ min.

The code should work for multiple clicks of the button. On each click it should clear any previous found information.

The relevant HTML:

<h1>Palindrome Finder!</h1>
<div>
    Phrase: <input id="phrase" type="text" size="70" />
</div>
<div>
    Length: <input id="min" type="text" size="2" /> to
    <input id="max" type="text" size="2" />
</div>
<button id="find">Find Palindromes</button>
<ul id="palindromes"></ul>
<div id="count"></div>

[20 Marks]


Question Eight

The University of Dodoma has been asked you to create the student registration form for the online Passport size pictures submission. The form should contain all fields as they appear on figure 1. The page should filter the list of schools based on the selected college all from the database, when student submit the form you are required to rename the picture file (preferably name with six random numbers) and save all student information in the student table. You should upload all pictures to the folder studentPictures located in the system root directory.

Figure 1: Registration Form

Table 1: College

idcollege_name
1CIVE
2COED

Table 2: School

idcollege_idschool_name
11SOI
21SOVE

Table 3: student

idreg_nofirst_namelast_namepicture
1T/UDOM/2018/00001StevenEdward345612.jpg

[20 Marks]


END OF EXAMINATION PAPER