899c785f4cf095b46cd82a4858586217
htmlphp
lab4
v2
rasb14
2017-10-06 17:12:47
v2.3.3 (2017-06-12)

Generated 2017-10-06 19:12:47 by dbwebb lab-utility v2.3.3 (2017-06-12).


Lab 4 - Htmlphp

If you need to peek at examples or just want to know more, take a look at the PHP Manual.

There you will find everything this lab will go through and much more.

1. Basic functions

Exercise 1.1 (1 points)

Create a function called sumNumbers() that should take 2 numbers as arguments and return the sum of them.

Answer with a call to the function using the numbers 591 and 119.

Exercise 1.2 (1 points)

Create a function called sumArray() that should take an array as argument and return the sum of all items in the array.

Answer with a call to the function using the array: [5,946,2,86,9].

Exercise 1.3 (1 points)

Create a function called modArray() that should take 2 arguments, an array and a string. Replace the first item in the array with the string and return the array.

Answer with a call to the function using the arguments: [4,256,5,13,1] and "onion".

Exercise 1.4 (1 points)

Create a function called printRange() that should take 2 numbers as arguments, start and stop. The function should add all even numbers between start and stop (not including) to an array and return it.

Answer with a call to the function using the arguments: 20 and 40.

Exercise 1.5 (1 points)

Create a function called combineArrays() that takes two arrays as arguments. The function should combine the arrays to one associative array and return it. The first argument is the key and the second argument is the value.

Answer with a call to the function using the arguments: [green,brown,pink,white,gray,blue] and [frog,bear,pig,lion,wolf,whale].

Exercise 1.6 (1 points)

Create a function called euroToDollar() that takes one argument, the euro amount to convert to dollars. Count 1 Euro as 1.261215 dollars. Return the dollar amount of 292 Euros.

Answer with the result as a double with 4 decimals.

Exercise 1.7 (1 points)

Create a function called inRange() that takes one argument. The function should return true if the argument is higher than 50 and lower than 100. If the number is out of range, the function should return false. The return type should be boolean.

Use the argument 134 and answer with a call to the function.

Exercise 1.8 (1 points)

Create a function called calculateArea() that takes one argument, the diameter of a circle. The function should return the area of the circle, with 4 decimals.

Answer with the result if the diameter is 9. ( hint: pi() )

Exercise 1.9 (1 points)

Create a function called fibonacci(). The function should use the Fibbonacci Sequence, starting with 1 and 2. Return the sum of all odd numbers in the sequence, when the sequence value dont exceed 1.000.000.

Answer with a call of the function. A Fibonacci-sequence can look like this: 1, 2, 3, 5, 8, 13, 21, 34, 55 etc. You add the current value with the last, i.e. 1+2=3, 3+2=5, 5+3=8 etc.

2. Extra assignments

These questions are worth 3 points each. Solve them for extra points.

Exercise 2.1 (3 points)

In this exercises you should use the former functions sumArray() and calculateArea(). Create a new function called calculateMany() that takes an array with numbers as argument. For every number in the array, call calculateArea() and store the result in a new array. The last position in your new array should hold the result of a call to the function calculateArea() where you pass the sum of the whole array, you passed as argument. All numbers in the resulting array should be rounded up to nearest integer.

Answer with a call to calculateMany() with the array 27, 47, 5, 32, 46.


899c785f4cf095b46cd82a4858586217