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

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...
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...
(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
Q 3 b) In this question you must write a php script to take Name[input =...
Q 3 b) In this question you must write a php script to take Name[input = text], Country[input = select, card_number[input = number], and type of card[input = radio button]to get user's input. The name of this file will be payment.php. Once the user submits the form; you must direct all the information to cust_info.html. The task is to keep a record in the cust_info.html of all the users who fill the forms and hit submit. the output must populate...
Write a PHP program that checks the elements of a string array named $Passwords. Use regular...
Write a PHP program that checks the elements of a string array named $Passwords. Use regular expressions to test whether each element is a strong password. For this exercise, a strong password must have at least one number, one lowercase letter, one uppercase letter, no spaces, and at least one character that is not a letter or number. (Hint: Use the [^0-9A-Za-z] character class.) The string should also be between 8 and 16 characters long. The $Passwords array should contain...
Create a bash script file named assessment-script-a that: 1. Accepts any number of file names on...
Create a bash script file named assessment-script-a that: 1. Accepts any number of file names on the command line 2. For each file name provided, delete any line that contains the string: qwe.rty When the changes are completed, the script should display the total number of files scanned, and the total number of files changed. Example Command: assessment-script-a file.a file.b file.c file.d file.e    Example Output: 5 files scanned, 3 files changed 3. Your script should include a series of...
PHP    1. Create a new PHP document (nit Objective 1)    2. Write a comment...
PHP    1. Create a new PHP document (nit Objective 1)    2. Write a comment similar to the following: "This is my first PHP document, which displays some data in the web browser"(Unit Objective 1)    3. Assign your name as a string value into the variable labeled myName (Unit Objective 2)    4. Assign 53870 numeric value into the variable named randomNumber (Unit Objective 2) 5. ssign the name of the web browser and operating system of the...
Write a function script DirCos.m that takes a vector (any row or column array) as the...
Write a function script DirCos.m that takes a vector (any row or column array) as the argument and returns the direction cosines for that vector. This is for a MatLab script
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT