Write A Script To Read The Marks Of 4 Subjects And Display The Result As Per The Below Instructions

0

Write a script to read the marks of 4 subjects and display the result as per the below instructions:

Write a script to read the marks of 4 subjects and display the result as per the below instructions: a.Each of the four subjects is worth 100 marks. b.If a student gets less than 35 marks in any subject, then he/she will be marked as FAIL, otherwise he/she will be marked as PASS. The result contains the grade of each individual subject in tabular format as per the above table.

  •  Each of the four subjects is worth 100 marks. 
  •  If a student gets less than 35 marks in any subject, then he/she will be marked as FAIL, otherwise he/she will be marked as PASS. 
The result contains the grade of each individual subject in tabular format as per the below table. 

Write a script to read the marks of 4 subjects and display the result as per the below instructions:

Here is a PHP script that serves a simple grade calculator.


PROGRAM
<html>
<head>
    <title>Grade Calculator</title>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    $marks = [];
    for ($i = 1; $i <= 4; $i++) {
        $marks[$i] = (int)$_POST["subject$i"];
    }

    $grades = [];
    foreach ($marks as $subject => $mark) {
        if ($mark >= 85 && $mark <= 100) {
            $grades[$subject] = 'AA';
        } elseif ($mark >= 75 && $mark <= 84) {
            $grades[$subject] = 'AB';
        } elseif ($mark >= 65 && $mark <= 74) {
            $grades[$subject] = 'BB';
        } elseif ($mark >= 55 && $mark <= 64) {
            $grades[$subject] = 'BC';
        } elseif ($mark >= 45 && $mark <= 54) {
            $grades[$subject] = 'CC';
        } elseif ($mark >= 40 && $mark <= 44) {
            $grades[$subject] = 'CD';
        } elseif ($mark >= 35 && $mark <= 39) {
            $grades[$subject] = 'DD';
        } else {
            $grades[$subject] = 'FF (FAIL)';
        }
    }

    $average = array_sum($marks) / count($marks);

    if ($average >= 85 && $average <= 100) {
        $overallGrade = 'AA';
    } elseif ($average >= 75 && $average <= 84) {
        $overallGrade = 'AB';
    } elseif ($average >= 65 && $average <= 74) {
        $overallGrade = 'BB';
    } elseif ($average >= 55 && $average <= 64) {
        $overallGrade = 'BC';
    } elseif ($average >= 45 && $average <= 54) {
        $overallGrade = 'CC';
    } elseif ($average >= 40 && $average <= 44) {
        $overallGrade = 'CD';
    } elseif ($average >= 35 && $average <= 39) {
        $overallGrade = 'DD';
    } else {
        $overallGrade = 'FF (FAIL)';
    }

    echo "<table border='1'>
          <tr><th>Subject</th><th>Mark</th><th>Grade</th></tr>";
    foreach ($marks as $subject => $mark) {
        echo "<tr><td>Subject $subject</td><td>$mark</td><td>{$grades[$subject]}</td></tr>";
    }
    echo "<tr><td>Average marks</td><td>$average</td><td>$overallGrade</td></tr>
          </table>";
}

?>

    <form method="post">
        <label for="subject1">Subject 1:</label>
        <input type="number" id="subject1" name="subject1"><br>

        <label for="subject2">Subject 2:</label>
        <input type="number" id="subject2" name="subject2"><br>

        <label for="subject3">Subject 3:</label>
        <input type="number" id="subject3" name="subject3"><br>

        <label for="subject4">Subject 4:</label>
        <input type="number" id="subject4" name="subject4"><br>

        <input type="submit" value="Calculate Grade">
    </form>
</body>
</html>

OUTPUT
*If image are looking blur then click on the image for HD quality.
Write a script to read the marks of 4 subjects and display the result as per the below instructions: a.Each of the four subjects is worth 100 marks. b.If a student gets less than 35 marks in any subject, then he/she will be marked as FAIL, otherwise he/she will be marked as PASS. The result contains the grade of each individual subject in tabular format as per the above table.


Write a script to read the marks of 4 subjects and display the result as per the below instructions: a.Each of the four subjects is worth 100 marks. b.If a student gets less than 35 marks in any subject, then he/she will be marked as FAIL, otherwise he/she will be marked as PASS. The result contains the grade of each individual subject in tabular format as per the above table.


Explanation
This is a PHP script for a simple grade calculator. It takes in marks for four subjects as input and calculates the grade for each subject as well as the overall grade based on the average of the marks. The grades are calculated using a grading system with eight grades ranging from AA (highest) to FF (lowest, fail).

The script first checks if the request method is POST, which means that the form has been submitted. If it is, it retrieves the marks entered by the user, calculates the grade for each subject using a series of if-else statements, and stores the grades in an array. It then calculates the average of the marks and calculates the overall grade using the same grading system.

Finally, it displays the marks, grades, and the overall grade in a table format using HTML. The table has a header row with three columns: "Subject", "Mark", and "Grade". Each row after the header corresponds to a subject and displays the subject number, the mark, and the grade. The last row displays the average marks and the overall grade.

The form uses the POST method to submit the marks entered by the user. Each input field is labeled with a subject number, and the form also has a "Calculate Grade" submit button.

❤️ I Hope This Helps You Understand, Click Here To Do More Exercise In PHP Programming.

Post a Comment

0Comments
Post a Comment (0)