WEB PROGRAMMING II - TUTORIAL 3
Duration: 2 hours 30 minutes
SECTION A: MULTIPLE CHOICE QUESTIONS (20 marks)
Instructions: Answer all questions. Each question carries 1 mark.
1. Which PHP function is used to add an element to the end of an array?
• array_push()
• push()
• add_element()
• append()
2. What is the purpose of the break statement in PHP?
• To stop the program
• To exit a loop
• To skip an iteration
• To pause execution
3. Which operator is used for division in PHP?
•/
•÷
• div
• \\
4. In CSS, what does the 'margin' property control?
• Inner spacing
• Outer spacing
• Border thickness
• Text spacing
5. Which PHP function is used to get the current date?
• now()
• current_date()
• date()
• get_date()
6. What is the purpose of the <head> tag in HTML?
• To display headings
• To contain metadata
• To create headers
• To style text
7. What does the modulus operator (%) return?
• Quotient
• Remainder
• Product
• Sum
8. In PHP, which function is used to find the length of an array?
• length()
• size()
• count()
• array_length()
9. What does the 'display: block' CSS property do?
• Hides the element
• Makes element take full width
• Makes element inline
• Blocks user interaction
10. Which PHP function removes the first element from an array?
• array_shift()
• shift()
• remove_first()
• array_remove()
11. In HTML, which tag is used to create a table row?
• <table>
• <tr>
• <td>
• <row>
12. Which function converts a string to uppercase in PHP?
• upper()
• strtoupper()
• uppercase()
• to_upper()
13. What is the purpose of the continue statement in loops?
• Exit the loop
• Skip current iteration
• Restart the loop
• Stop the program
14. Which CSS property is used to add space inside an element?
• margin
• padding
• spacing
• border
15. In PHP, which function generates a random number?
• random()
• rand()
• generate()
• random_number()
16. What does the <body> tag contain in HTML?
• Metadata
• Visible content
• Scripts only
• Styles only
17. Which PHP function combines array elements into a string?
• join()
• implode()
• Both A and B
• concat()
18. In HTML, which attribute specifies an image source?
• href
• src
• link
• source
19. Which PHP function searches for a value in an array?
• in_array()
• array_search()
• Both A and B
• find()
20. What is the purpose of CSS?
• Structure content
• Style content
• Add functionality
• Store data
SECTION B: STRUCTURAL QUESTIONS (20 marks)
Instructions: You are required to answer all questions in a clean and brief manner giving
examples where necessary.
1. Give the difference between: (10 marks)
• Array and Variable
• Domain and IP address
• GET and POST methods
• XAMMP and WAMP
• include() and require()
2. What are the three types of loops in PHP? Give an example of each. (3 marks)
3. Consider the given URL. https:/[Link] (3mrks)
a. What is the fully qualified domain name
b. What is the top level domain name
c. What is the protocol
3. Write a PHP script to find the largest of three numbers. (4 marks)
SECTION C: PROBLEM SOLVING (30 marks)
Instructions: This section tests your ability to write PHP scripts. Ensure to maintain proper
indentation and orderly presentation of your codes.
Problem 1: Simple Calculator
SIMPLE CALCULATOR
Number 1: ___________________________
Number 2: ___________________________
Operation: ▼ Select Operation (Add, Subtract, Multiply, Divide)
CALCULATE CLEAR
a. Using HTML and CSS, write the code to produce the exact form above. (10 marks)
b. Write the PHP script that performs the selected operation and displays the result. (5
marks)
Problem 2: Prime Number Checker
PRIME NUMBER TEST
Enter a Number: ___________________________
CHECK PRIME NUMBER RESET
a. Using HTML and CSS, write the code to produce the exact form above. (6 marks)
b. Write the PHP script to determine if the entered number is prime and display the result.
(9 marks)