Page 258 - Computer Software Application TP - Volume 1
P. 258
COMPUTER SOFTWARE APPLICATION - CITS
1 Write a function named calculateArea that calculates the area of a rectangle given its length and width.
2 Write a PHP function that takes two numbers as parameters ($num1 and $num2) and print their sum. Call the
function with different values and print result.
3 Create a function called sayHello that takes a parameter $name and defaults to “Guest” if no value is provided.
The function should echo “Hello, $name!”. Call the function without providing a value for $name and observe
the output.
4 Create a function named getAgeCategory that determines the age category based on the provided age. It
should take one parameter $age with a default value of 25. The function should return “Child” for ages 0-12,
“Teen” for ages 13-19, “Adult” for ages 20-59, and “Senior” for ages 60 and above.
5 Create a function called incrementByReference that takes an integer parameter $num by reference and
increments it by 1 inside the function. Call the function with a variable and observe its value change after the
function call.
6 Implement a function called swapValues that takes two variables $a and $b by reference and swaps their
values inside the function. Call the function with two variables and print their values before and after the
function call to demonstrate the swap.
7 Write a PHP script that defines a dynamic function named multiply which takes two parameters and returns
their product. Then, call this dynamic function with values 5 and 3, and echo the result.
243
CITS : IT & ITES - Computer Software Application - Exercise 52