Question: I have a programmng assignment to give in next week, and I was wondering if someone could help me answer these questions : Exercise 1
I have a programmng assignment to give in next week, and I was wondering if someone could help me answer these questions :
Exercise 1
The following set of short questions will focus on getting you familiar with how to write PHP
functions as well as how to make use of the pre-existing PHP functions. All your PHP functions
must be declared in the document body section and each functions name must be as specified
below. To demonstrate the functionality of each method, you must make function calls in the
document body. Include a heading (h1 h6) that indicates which function is being tested before
each function demonstration. The use of Global Variables is forbidden! Test all your functions
with some relevant input parameter values.
A. Function: computefactorial
Parameter(s): Number
Given the number, find its factorial and return it. If the parameter is not an integer
number or if it is a negative number, return false.
B. Function: findMostFrequent
Parameter(s): String Array
Outputs the string (element) that appears the most frequently within the array with its
frequency of repetition. Strings should be case insensitive.
C. Function: toUppercaseFirst
Parameter(s): String
For each word in the string, capitalize (uppercase) the first letter, and make sure the rest
of the letters of all words are lower case, then return the modified string.
D. Function: splitCapitalizeSort
Parameter(s): String
Given the string, place each word into an index array and then capitalize (uppercase) the
first letter of all those words in the array, then sort the array alphabetically. The return the
resulting array. Duplicated words, if any, are kept.
E. Function: dayofNextFriday
Parameter(s): None
Return the date of the next Friday in the following format: DD/MM/YYYY.
(if today is Friday return the date of next Friday)
F. Function: findUniqueandSort
Parameter(s): Array of integer numbers
Scan the entire array and print out the array excluding any duplicate elements, then sort
the array. Example: input Array a = 1,3,2,1,3, 1 would output 1,2,3.
G. Function: sortHash1
Parameter(s): Associative Array
Given an associative array using full-names as keys and annual salaries as values; in a
table format, print out the name and corresponding salary of each individual in increasing
order (from lowest salary to the highest).
H. Function: sortHash2
Parameter(s): Associative Array, code
Write a PHP function to accept an associative array (as follows) and a code as input
parameters, and then sort the input associative array as follows. Example of the input array:
array("Jack"=>"55",
"Anita"=>"30","Ramesh"=>"40","Sophia"=>"21","Nastran"=>"41","William"=>"39","Davi
d"=>"5") in :
a) if code =1: ascending order sort by value
b) if code =2: ascending order sort by Key
c) if code =3: descending order sorting by Value
d) if code =4: descending order sorting by Key
e) For other values of code: Function only prints (Wrong Code)
I. Function: averageTemp
Parameter(s): Associative Array
Write a PHP function to calculate and display average temperature, and four lowest and
highest temperatures.
Recorded temperatures are : [78, 60, 62, 68, 71, -17, 52, 68, 73, 85, 66, 64, 76, 63, 75, 76,
73, 68, 62, 73, -10, 72, 65, 80,74, 62, 62, 65, 64, 0, 68, 73, 75, 79, 73, 77]
Expected Outputs:
Average Temperature is : Average Value
List of four lowest temperatures : -17, -10, 0, 52
List of four highest temperatures : 79, 80, 81, 85
J. Function: findatStartorEnd
Parameter(s): word, string
Write a PHP function to test if a given word occurs at the beginning or at the end of a
given string. If yes, it returns: True, otherwise it returns: False
Example for: I love PHP, PHP --? function returns : True
Example for: I love PHP and C++, PHP --? function returns : False
Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
