Question

In: Computer Science

Write a PHP script that: 1) Has an associative array with 10 student names and test...

Write a PHP script that:

1) Has an associative array with 10 student names and test scores (0 to 100). ie. $test_scores('John' => 95, ... );

2)Write a function to find the Average of an array. Input is an array, output is the average. Test to make sure an array is inputted. Use ARRAY_SUM and COUNT.

3)Output the test scores highest to lowest, print scores above the average in Green. Find a PHP Sort function for associative arrays, high to low. <font color='green'>text</font>

4)Output the test scores lowest to highest, print scores below the average in Red. Find a PHP Sort function for associative arrays, low to high. <font color='red'>text</font>

Solutions

Expert Solution

If you have any doubts, please give me comment...

<?php

function calcAvg($test_scores){

    return array_sum($test_scores)/count($test_scores);

}

$test_scores = array("John"=>95, "Smith"=>87, "Kim"=>91, "Julie"=>75, "Doe"=>80, "Raju"=>85, "James"=>78, "Sam"=>65, "Rubi"=>80, "Dean"=>72);

$avg = calcAvg($test_scores);

echo "Average: ".$avg."<br />";

arsort($test_scores);

echo "<b>Above average: </b><br />";

foreach($test_scores as $name=>$score){

    if($score>=$avg)

        echo "<font color='green'>".$name." - ".$score."</font><br />";

}

asort($test_scores);

echo "<b>Below average: </b><br />";

foreach($test_scores as $name=>$score){

    if($score<$avg)

        echo "<font color='red'>".$name." - ".$score."</font><br />";

}


Related Solutions

[JAVA SCRIPT] Please create an array of student names and another array of student grades. Create...
[JAVA SCRIPT] Please create an array of student names and another array of student grades. Create a function that can put a name and a grade to the arrays. Keep Read student name and grade until student name is “???”. And save the reading by using a function Create another function to show all the grade in that object. Create the third function that can display the maximum grade and the student’s name. Create a sorting function that can sort...
JAVASCRIPT: Please create an array of student names and another array of student grades. - Create...
JAVASCRIPT: Please create an array of student names and another array of student grades. - Create a function that can put a name and a grade to the arrays. - Keep Read student name and grade until student name is “???”. And save the reading by using a function - Create another function to show all the grade in that object. - Create the third function that can display the maximum grade and the student’s name. - Create a sorting...
<HTML JAVASCRIPT> Please create an array of student names and another array of student grades. Create...
<HTML JAVASCRIPT> Please create an array of student names and another array of student grades. Create a function that can put a name and a grade to the arrays. Keep Read student name and grade until student name is “???”. And save the reading by using a function Create another function to show all the grade in that object. Create the third function that can display the maximum grade and the student’s name. Create a sorting function that can sort...
Write a simple PHP script. In your script use all of the following: HTML, Javascript, and...
Write a simple PHP script. In your script use all of the following: HTML, Javascript, and PHP.
Write a PHP script that checks a word or a phrase (stored in a string variable)...
Write a PHP script that checks a word or a phrase (stored in a string variable) to determine if it is a standard palindrome, a perfect palindrome, or not a palindrome at all. Also, for each letter that the word/phrase contains, count and print the number of times that each consonant and vowel is encountered. Your output will look as follows: Word/phrase: racecar Perfect palindrome Contains consonants: r - 2 c - 2 Contains vowels: a - 2 e -...
Task 1 Write a program that allocates an array large enough to hold 5 student test...
Task 1 Write a program that allocates an array large enough to hold 5 student test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Input Validation: Do not accept negative numbers for test scores. Task 2 Modify the program so the lowest test...
Write a PHP script to display in frequency all the words in the submitted paragraph. Convert...
Write a PHP script to display in frequency all the words in the submitted paragraph. Convert the string to an array of words. Count the number of times the words are used. Hint: array_count_values($arrayname) Sort the array in frequency order. Print the array to the screen. Hint: print_r($arrayname)
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...
Write a java script function that accepts integer array as input, and display a new array...
Write a java script function that accepts integer array as input, and display a new array by performing fol lowing modifications, • The values in odd index positions must be incremented by 1 • The values in even index positions must be decremented by 1. • Assume the array index starts from 0. Input 1: arr = [1,2,3,4] Output 1: arr = [0,3,2,5 it done html and javascript and plz do it in simple way
• In this script, write MATLAB code to create an array A of size 100 ×...
• In this script, write MATLAB code to create an array A of size 100 × 3. The first column should contain random numbers between 0 and 10. The second column should also contain random numbers between 0 and 10. The third column should contain random integers between 20 and 50. The first two columns represent the x and y coordinates of a map, respectively. The third column represents the height of buildings. For example, if the first row of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT