For this activity, you may work alone or with another student in this course. Write PHP programs to solve at least three of the following problems.
Imagine you are writing a PHP app that takes a grid information and a tile.
Use simplegrid.php (text version),
write 2 functions: isDiagonal
and isEdge
isDiagonal
that
will return either true
or false
depending on
whether or not the tile is along the diagonal of the square grid.
For example, on a 7x7 grid,
assuming the tile numbers (starting at the top-left corner)
are 1, 2, 3, ..., 491 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | ||||||
15 | ||||||
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | |||||
36 | ||||||
43 |
$row = intdiv(($tile - 1), $width); // intdev() returns the integer quotient of the division of dividend by divisor $col = fmod(($tile - 1), $width); // fmod() returns the remainder of the division
isEdge
that
will return either true
or false
depending on
whether or not the tile is along the edge of grid.
For example, on a 7x8 grid,
assuming the tile numbers (starting at the top-left corner)
are 1, 2, 3, ..., 561 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | ||||||
15 | ||||||
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | |||||
36 | ||||||
43 | ||||||
50 |
$row = intdiv(($tile - 1), $width); // intdev() returns the integer quotient of the division of dividend by divisor $col = fmod(($tile - 1), $width); // fmod() returns the remainder of the division
Use computeAvg.php (text version). Write a PHP function that accepts six project scores and an option specifying whether the lowest project score will be dropped. All scores are out of 100 points, except the first (which is out of 30) and the fifth (which is out of 50). You may assume that the drop option is given as a boolean value where true means drop the lowest project score and false means no drop. If there are multiple lowest project scores (i.e., same scores), you decide which one to drop.
The function then computes and returns the highest average score for the projects.
For example, if a user enters
Score for project 1 = 15
Score for project 2 = 55
Score for project 3 = 55
Score for project 4 = 55
Score for project 5 = 25
Score for project 6 = 55
With the lowest project score being dropped, the function returns 54
Without the lowest project score being dropped, the function returns 53.33
You do not need to round the average.
Use combineFriendBook.php (text version). Write a PHP function that accepts two arrays of friend books and returns a merged friend book.
For example, if the incoming address books are
friend_book1 = Array('Humpty' => '111-111-1111', 'Dumpty' => '222-222-2222', ' 'Duh' => '333-333-3333', 'Oops' => '444-444-4444', 'Huh' => '555-555-5555') friend_book2 = Array('Dumpty' => 'dumpty@uva.edu', 'Duh' => 'duh@uva.edu', 'Humpty' => 'humpty@uva.edu', 'Huh' => 'huh@uva.edu', 'Wacky' => 'wacky@uva.edu')The function returns a merged friend book in a (human-readable) format; for example,
Humpty : [ 111-111-1111, humpty@uva.edu ] Dumpty : [ 222-222-2222, dumpty@uva.edu ] Duh : [ 333-333-3333, duh@uva.edu ] Oops : [ 444-444-4444 ] Huh : [ 555-555-5555, huh@uva.edu ] Wacky : [ wacky@uva.edu ]
Use simplearray.php (text version),
write 2 functions: findLargest
and divideByThree
findLargest
that takes an array of integers and
then returns the index of the last occurrence of the largest element in the array.
For example,
divideByThree
that takes an array of integers and
then returns the number of elements in the array that are evenly divisible by 3.
For example,
To deploy and test your program use one of the following options:
Released under the CC-BY-NC-SA 4.0 license.
Last updated 2022-05-29 12:58