THE UNIVERSITY OF DODOMA

COLLEGE OF INFORMATICS AND VIRTUAL EDUCATION

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


UNDERGRADUATE UNIVERSITY EXAMINATIONS

FIRST SEMESTER 2018/2019


Course Code: CS 312

Course Title: INTERNET PROGRAMMING AND APPLICATIONS


INSTRUCTIONS:

  1. Closed Book Examination.
  2. This examination consists SEVEN questions.
  3. Answer all questions in Section A and only two (2) questions from Section B.
  4. Use the user Cs312 and password 312Pass to access the database udom_sr.
  5. The IP address for the PHP server is 192.168.2.1 and MySQL server is 192.168.2.4.
  6. 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. If no expiration time is explicitly set for a cookie, what happens to it?

(a) It expires right away (b) It never expires (c) It is not set (d) It expires at the end of the user’s browser session (e) It expires only if the script doesn’t create a server-side session


ii. Under what circumstance is it impossible to assign a 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 (e) Never


iii. By default, PHP stores session data in

(a) The filesystem (b) A database (c) Virtual memory (d) Shared memory (e) None of the above


iv. Which of the following will not combine strings s2 into a single string?

(a) s2 (b) “s2” (c) s2 (d) implode("", array(s2)) (e) All of the above combine strings


v. Given a variable $email containing the string user@example.com, which of the following statements would extract the string example.com?

(a) substr(email,”@”)); (b) strstr(email,”@”) (d) substr(email,”@”)+1); (e) strpos($email,”@”);


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. Under what circumstance is it impossible to assign a 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 (e) Never


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. Run-time inclusion of a PHP script is performed using the _____ construct, while compile-time inclusion of PHP scripts is performed using the _____ construct.

(a) include_once, include (b) require, include (c) require_once, include (d) include, require (e) All of the above are correct


Question Two

What will be the output of the following script? (10 Marks)

<?php
$array = array(1,2,3,5,8,13,21,34,55);
$sum = 0;
for($i = 0; $i < 5; $i++) {
    $sum += $array[$array[$i]];
}
echo $sum;
?>

Question Three

Write CSS rules for the following: (2 Marks Each)


i. Write a CSS rule that makes all text 1.5 times larger than the base font of the system and color the text red.


ii. Write a CSS rule that places a background image halfway down the page, tiling it horizontally. The image should remain in place when the user scrolls up or down.


iii. Write a CSS rule that gives all h1 and h2 elements a padding of 0.5ems, dashed border style and a margin of 0.5 ems.


iv. Write a CSS rule that changes the color of all elements containing attribute class=“green-Move” to green and shift them down 25 pixels and right 15 pixels.


v. Write a layout template that contains a header and two columns. Use divs for each layout component, and use float to line up the columns side by side. Give each component a border and/or a background color so you can see where your divs are.


Question Four

Find SIX (6) errors in the following JavaScript code and rewrite the correct one. (10 Marks)

<script language="javascript">
 
var test1= prompt("Insert test 1 marks (0-50)","");
var test2 = prompt("Insert test 2 marks (0-50)","");
marks = parseFloat(test1) + parseFloat(test1);
 
if ((marks>=80) (marks<=100)){
    document.write("Excellent");
}
 
elseif ((marks>=60) && (marks<=79)){
    document.write("Good");
}
 
else if ((marks>=30) && (marks<=59)){
    document.write("Intermediate");
}
 
{
    document.write(Try again);
}
 
</script>

SECTION B (60 Marks)

Attempt ANY TWO questions from this section.


Question Five

The University of Dodoma wants to modify the Continuous Assessment (CA) registration form so that it appears like the one shown in figure 1. The Course instructor can use it to register CA for more than two students by clicking the Add Row button to append the row. The appended row may be deleted by clicking the delete Row button. You are required to create a form using XHTML, Ajax and PHP, the submit button should save the information in the ca_result table in the database udom_sr. [30 Marks]

Table Structure:

  • tbl_student (student_id, registration_no)
  • tbl_ca_result (student_id, test_one, test_two)

Figure 1: CA registration form

#Registration NoTest One (0-50)Test Two (0-50)AssignmentTotal
1T/UDOM/2010/03999807060210
2

Question Six

a) Computers are playing an increasing role in education. Use XHTML and JavaScript to write a program that will help elementary-school student learn multiplication. Use random function to produce two positive one digit integers. It should then display a question such as “How much is 4 times 9?” The student then types the answer into a text field. Your program checks the student’s answer. If it is correct, display the string “Very good!” and generate a new question. If the answer is wrong, display the string “No. Please try again.” And let the student try the same question again repeatedly until the student finally gets it right. A separate function should be used to generate each new question. This function should be called once when the script begins execution and each time the user answers the question correctly. [15 Marks]

b) Modify the program from question One to allow the user to pick the type of arithmetic problems he or she wishes to study. An option of 1 means addition problem only, 2 means subtraction problems only, 3 means multiplication problem only, 4 means division problems only and 5 means to intermix randomly of all these types. [15 Marks]


Question Seven

Write the PHP code for a web page filter.php that filters lines of text from a file. The page should contain a short form with a text box where the user can type a word. The page also displays the current contents of the file text.txt as a pre-formatted block. The form submits back to the same page, filter.php, as a POST request. When the word is submitted, your code should examine the contents of text.txt and remove any lines from the file that contain the given word, case-insensitively. Write the changes to the file so that any future viewings of the page will see the changes. You can write just the code dealing with the page’s body; you don’t need to output a head section or a complete page. [30 Marks]

Match the exact word, not other words that contain it as a substring. For example, if the user submits the word “me” you would filter out lines containing the word “me”, but not lines that just contain a word such as “men” or “game”.


END OF EXAMINATION PAPER