Question

Use PHP to perform the following operations: 1. define an array having at least 20 elements...

Use PHP to perform the following operations: 1. define an array having at least 20 elements representing the grade of some students, i.e., 0<=$grade[i]<=100. 2. find out the length of the array 3. use switch to work on each element, converting a numeric grade to a letter grade and print the letter grade. The rules are below: A 90 - 100 B 80 - 89 C 70 - 79 D 60 - 69 F 0 - 59

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Following is the answer:

<?php

//define the array of 20 elements

$array = array(60,65,75,85,95,78,89,46,93,76,36,79,69,79,85,63,60,79,74,83);

//prints the length of the array

echo "Length of the array: " . sizeof($array);

$i = 0;

//prints the grades using while loop

while($i < sizeof($array)){

echo "<br />";

if($array[$i] >= 90 && $array[$i] <= 100){

echo $array[$i] . ": " . "A" . "\n";

}else if($array[$i] >= 80 && $array[$i] <= 89){

echo $array[$i] . ": " . "B" . "\n";

}else if($array[$i] >= 70 && $array[$i] <= 79){

echo $array[$i] . ": " . "C" . "\n";

}else if($array[$i] >= 60 && $array[$i] <= 69){

echo $array[$i] . ": " . "D" . "\n";

}else {

echo $array[$i] . ": " . "F" . "\n";

}

$i+=1;

}

?>

Output:

Length of the array: 20 60: D 65: D 75: C 85: B 95: A 78: C 89: B 46: F 93: A 76: C 36: F 79: C 69: D 79: C 85: B 63: D 60: D 79: C 74: C 83: B

Add a comment
Know the answer?
Add Answer to:
Use PHP to perform the following operations: 1. define an array having at least 20 elements...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Java, write a program that teachers can use to enter and calculate grades of individual...

    Using Java, write a program that teachers can use to enter and calculate grades of individual students by utilizing an array, Scanner object, casting, and the print method. First, let the user choose the size for the integer array by using a Scanner object. The integer array will hold individual assignment grades of a fictional student. Next, use a loop to populate the integer array with individual grades. Make sure each individual grade entered by the user fills just one...

  • Write a C++ program that will provide a user with a grade range if they enter...

    Write a C++ program that will provide a user with a grade range if they enter a letter grade. Your program should contain one function. Your function will accept one argument of type char and will not return anything (the return type will be void), but rather print statements to the console. Your main function will contain code to prompt the user to enter a letter grade. It will pass the letter grade entered by the user to your function....

  • [Using Python] Use the grade scale in the syllabus for this class, write a program that...

    [Using Python] Use the grade scale in the syllabus for this class, write a program that inputs a score, and prints the grade for that score. For example, if I input 90.0, your program should print A. Grading Scale is: 100% - 90% A 89% - 80% B 79% - 70% C 69% - 60% D 59% - 0% E

  • 1. Create a program that takes a numerical score and outputs a letter grade. 2. In...

    1. Create a program that takes a numerical score and outputs a letter grade. 2. In this program, create two void functions titled makeScore and theGrade with an int argument. 3. The function makeScore should have a Reference parameter and theGrade should have a Value parameter. Note: Specific numerical scores and letter grades are listed below: 90-100 = Grade A 80-89 = Grade B 70-79 = Grade C 60-69 = Grade D 0-59 = Grade F 4. The function makeScore...

  • Microsoft Excel Question. I'm having trouble using the vlookup function, I have calculated a final numerical...

    Microsoft Excel Question. I'm having trouble using the vlookup function, I have calculated a final numerical grade for a hypothetical course, and and trying to use a set of numerical grades with their corresponding letter grades to get a vlookup function to return the letter grade from the numerical grade. However the function for some reason only returns the lowest value out of the set grades, not the closest match. Projects Classwork Teamwork/Integrity 100 100 A+ 98 A+ 97 A...

  • Create a MIPS program that does the following: 4. Determine the letter grade a. Use the...

    Create a MIPS program that does the following: 4. Determine the letter grade a. Use the floating point calculated average to determine the letter grade. You will need to research the instructions to use to do comparisons with floating point numbers. (see Course Resources) b. Use the following chart: 90 - 100 80 - 89 70 - 79 ............. 60 - 69.............. <60 ..................... ............... 5. Display a message and the letter grade. 6. Your output should look similar to...

  • SOLVE IN PYTHON:Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes...

    SOLVE IN PYTHON:Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array....

  • PYTHON PART 1) SIMPLE IF STATEMENTS INSIDE A LOOP. The first part of your program should...

    PYTHON PART 1) SIMPLE IF STATEMENTS INSIDE A LOOP. The first part of your program should do the following: • Write a section of code that prints off the numbers from 50 to 100. • It should also print off the letter grade that goes with that number on the same line using an if statement o 0 – 59 = F o 60 – 69 = D o 70 – 79 = C o 80 – 89 = B...

  • We have to make HTML form with 3 fields, all labeled appropriately: Even or Odd: A...

    We have to make HTML form with 3 fields, all labeled appropriately: Even or Odd: A text field for entering a number. Grade: A text field for entering percentage grades from 0-100. Month: A text field for entering a numeric month value from 1-12. IN PHP :- The script for the first field (Even or Odd) will tell us if the number is even or odd. (Hint: Use the modulus operator.) The script for the second field (Grade) will use...

  • This program should be written in C Thoroughly following the Code Conventions, write an efficient program,...

    This program should be written in C Thoroughly following the Code Conventions, write an efficient program, which ask the user for their numeric grade, and determines and displays the equivalent letter grade, based on the following information: Use appropriate data types and initialize the variables correctly Use the following grading scale: A: 90 - 100 B: 80 - < 90 C: 70 - < 80 D: 60 - < 70 F: 0 - < 60 If the input is invalid,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT