0% found this document useful (0 votes)
107 views11 pages

ICT2613 S1 MayJune 2017 ExaminationPaper

ICT2613_S1_MayJune_2017

Uploaded by

Rotondwa Mulondo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views11 pages

ICT2613 S1 MayJune 2017 ExaminationPaper

ICT2613_S1_MayJune_2017

Uploaded by

Rotondwa Mulondo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

INSTRUCTIONS:

1. This examination paper consists of 9 pages and 2 additional pages for rough work.
2. This is a closed book examination.
3. The mark for each question is given in brackets next to the question.
4. Answer all seven questions in the blocks provided in the question paper.

GOOD LUCK!

[TURN OVER]
2 ICT2613
May/June 2017
Question 1 [4]
Write PHP code to initialise two variables to values "ICT2613" and "Internet Programming".
The variable names should use camel casing. Use the initialised variables to display the following
sentence exactly (including bold) using an echo statement:

Code: ICT2613, Name: Internet Programming

Question 2 [14]
Study the code below and answer the questions that follow:

<form action="process.php" method="post">


<label><b>Full Name: </b></label> <br>
<input type="text" name="full_name"> <br><br>

<label><b>New Year's Resolutions: </b></label> <br>


<input type="checkbox" name="rone"> Quit Smoking <br>
<input type="checkbox" name="rtwo"> Lose Weight <br>
<input type="checkbox" name="rthree"> Save for a holiday <br><br>
<input type="submit" value="Submit"> <br>
</form>

2.1 Write PHP code to read the data entered in the form. Use four variables to store the data read from
the form; one variable for the full name and the other three variables to store whether three check boxes
are selected or not. (4)

[TURN OVER]
3 ICT2613
May/June 2017
2.2 Write PHP code to calculate the number of New Year’s resolutions (check boxes) selected by the
user. Display the name (entered in the text field) and the calculated number of resolutions using an
echo statement. Use the variables declared in 2.1. (5)

2.3 The form is incomplete if the user name is empty or if none of the checkboxes is selected when it is
submitted. If the form is incomplete, display a message, Incomplete Form – All Fields
Required. Use the variables declared in 2.1 to check whether the form is incomplete. (5)

Question 3 [20]
Consider a SQL database diploma with a table named modules. The modules table has the
following columns:

- code, which is the primary key of the table for storing unique 7 character module codes
- name, which stores module names
- lecturer, which stores the names of the primary lecturers for the modules

[TURN OVER]
4 ICT2613
May/June 2017
Assume that the modules database table has been populated with the following information:
ICT2612 Interactive Programming Mrs C van Staden
ICT2613 Internet Programming Mrs A Thomas
ICT3612 Advanced Internet Programming Mrs P Le Roux

3.1 Assume that a database connection is established using a PDO object named $db. Write the
necessary code to extract all the data in the modules database table. By using the echo statement
display each row in the database table in a new line in a comma-separated format. (8)

3.2 Assume that a database connection is established using a PDO object named $db. Write the
necessary PHP code to add a row of data in the modules database table. Assume that the module
code, module name and lecturer name are stored in the variables $nCode, $nName and
$nLecturer respectively. (8)

[TURN OVER]
5 ICT2613
May/June 2017
3.3 Write one line of PHP code to assign a variable $query to a query statement to update the name of
the lecturer of an existing module code in the modules database table. Assume that the module code
and the lecturer’s name are stored in variables. (2)

3.4 Write one line of PHP code to assign a variable $query to a query statement to delete a row of
data for the specified module code from the modules database table. Assume that the module code is
stored in a variable. (2)

Question 4 [20]

Refer to the code fragment below to answer questions 4.1 and 4.2:

if ($mark >= 75)


$result = "++";
else if ($mark >=50 && $mark <= 74)
$result = "+";
else if ($mark >=40 && $mark <=49)
$result = "*";
else if($mark < 40)
$result = '-';

4.1 What will be stored in $result for the following values of $mark: (5)

(a) 15
(b) 40
(c) 49
(d) 50
(e) 78

[TURN OVER]
6 ICT2613
May/June 2017
(a)

(b)

(c)

(d)

(e)

4.2 Write a function so that the given code is placed inside the function. The function takes $mark as
its parameter and returns $result. (3)

4.3 Write one line of code to invoke the function you have written for question 4.2 with the mark 49.
(1)

4.4 Write a for loop that iterates 7 times. During each iteration of the loop, generate a random number
between 1 and 4. Use a switch statement inside the for loop to display East, West, South and
North for values 1, 2, 3 and 4 respectively using an echo statement. (5)

[TURN OVER]
7 ICT2613
May/June 2017

Refer to the code below to answer questions 4.4 and 4.5:

$i = 4;
while($i <= 7){
if($i%2 != 0)
echo "$i - Odd number <br>";
else
echo "$i - Even number <br>";
$i++;

4.4 What is the output generated by the given code? (4)

4.5 Rewrite the code to use do while instead of while without changing its logic. (2)

[TURN OVER]
8 ICT2613
May/June 2017

Question 5 [6]

Consider the statement $module = "ICT2613"; and answer the questions below:

5.1 What is returned by the statement strlen($module);? (2)

5.2 What is returned by the statement substr($module, -2);? (2)

5.3 What is stored in $result after the statement $result = explode("2", $module);?
(2)

Question 6 [4]

Write lines of code to do the following in the given sequence:

(a) Create a DateTime object to store the date 21-12-2017


(b) Create another DateTime object with the current date (today’s date)
(c) Calculate the number of months from the current date to the date specified in (a) using relevant
functions of DateTime

[TURN OVER]
9 ICT2613
May/June 2017

Question 7 [7]

7.1 What is stored in $nums after the statement $nums = range(5,8);? (2)

7.2 Write the contents of $nums (declared and initialized in 7.1) after the function rsort() is
invoked on it. (2)

7.3 Write code to create an associative array with keys 1, 2 and 3, and one, two and three as values
respectively. (2)

7.4 Write the contents of the associative array (declared and initialized in 7.3) after the function
krsort() is invoked on it? (1)

©
UNISA 2017

[TURN OVER]
10 ICT2613
May/June 2017
ROUGH WORK PAGE

[TURN OVER]
11 ICT2613
May/June 2017

ROUGH WORK PAGE

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy