Main Exam
Updated on 28 Dec 2018
UNIT CODE | COMP306 |
UNIT TITLE | Software Design & Development |
LECTURER | Brent Knigge |
DURATION | 2 hours |
READING TIME | 10 mins |
WEIGHTING | 40 % |
SPECIAL INSTRUCTIONS TO STUDENTS:
- There are a total of 20 questions. Attempt all questions.
- Each question is worth 2 marks. There are a total of 40 marks available.
- This exam constitutes 40% of your overall assessment.
- This is a closed book assessment.
Question 1
2 marks
This error message is displayed on the browser. What could have been the PHP code that caused this error?
Parse error: parse error, unexpected $end in d:\my documents\My Site\php\test.php on line 13
Question 2
2 marks
For the code snippet shown below, under what circumstances would ‘Hello World’ be displayed on the browser?
if(!$logged_in)
echo ‘Hello World’;
Question 3
2 marks
Can you write $_POST[‘submit’] in place of $_POST[‘Submit’]?
Question 4
2 marks
In the previous question, what would $_POST[‘submit’] usually represent?
Question 5
2 marks
What function can be used with arrays to tell you the number of elements that it contains?
Question 6
2 marks
The following snippet of code is supposed to display ‘Good Morning’, ‘Good Afternoon’ or ‘Good Evening’ depending on the time of day. However ‘Good Evening’ is never displayed on the browser. Why, and what needs to be done to make the code work as expected?
$hour = date('G');
if($hour >= 0 && $hour < 12)
echo '<p>Good Morning</p>';
else if($hour >= 12 || $hour < 17)
echo '<p>Good Afternoon</p>';
else
echo '<p>Good Evening</p>';
Question 7
2 marks
If I wanted an array that contained the letters A to Z, how could I declare that array without having to type out each letter of the alphabet?
Question 8
2 marks
stripslashes is an important PHP function. It’s purpose is to remove slashes from string variables. Why is this necessary and what is the likely cause of the slashes appearing in the string variable in the first place?
Question 9
2 marks
A function has been declared as follows:
function greeting($message = 'hello')
What does the $message = ‘hello’ mean?
Below is the table structure for myContacts which is used for questions 10 & 11
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
user_id | mediumint(8) | PRI | NULL | auto_increment | |
contact_id | tinyint | ||||
last_name | varchar(30) | ||||
first_name | varchar(30) | ||||
varchar(60) | YES | NULL | |||
age | tinyint | YES |
Question 10
2 marks
For what reasons will the following insert query fail?
insert into myContacts values (0, ‘Mr’, ‘Smith’)
Question 11
2 marks
Write a query that will retrieve the last_name and first_name fields where the age is greater than 18
.
Question 12
2 marks
What is the purpose of a table index?
Question 13
2 marks
What are the following functions used for?
- ob_start
- ob_end_flush
Question 14
2 marks
If Address were defined as a class, and display were a method of that class, show an example of how you might instantiate an object of Address and call the display method.
Question 15
2 marks
Describe one of the access modifiers available for methods and properties in Object Orientated Programming.
Question 16
2 marks
What is the purpose of a constructor, and when is it called?
Question 17
2 marks
The md5 function is a PHP function, and a MySQL function. What does it do?
The following Regular Expression Tables are used for Questions 18 – 20
Metacharacter
Symbol | Meaning |
---|---|
^ | Indicates the beginning of a string |
$ | Indicates the end of a string |
. | Any single character |
| | Alternatives (or) |
\|Escapes the following character | |
() | Used for making groups |
[] | Used for defining classes |
Quantifiers
Symbol | Meaning |
---|---|
? | 0 or 1 |
* | 0 or more |
+ | 1 or more |
{x} | exactly x occurrences |
{x,y} | between x and y (inclusive) |
{x,} | at least x occurrences |
Character Classes
Class | Short Cut | Meaning |
---|---|---|
[0-9] | \d | Any digit |
[\f\r\t\n\v] | \s | Any white space |
[A-Za-z0-9_] | \w | Any word character |
[ ^0-9] | \D | Not a digit |
[^\f\r\t\n\v] | \S | Not white space |
[^A-Za-z0-9_] | \W | Not a word character |
Question 18
2 marks
Write a valid string entry that would satisfy this regular expression.
/^[\w.-]+@[a-z0-9_.-]+\.[a-z]{2,6}$/
What would be the likely use for this regular expression?
Question 19
2 marks
Under what circumstances is the following conditional true?
if(preg_match('/col(o|ou)r/', $text_string))
Question 20
2 marks
Write a regular expression that will accept only 4 digits.
NB Your answer should start with / and end with /