Practical - 3 IWD

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

GTUGRADE

Mark-Range

AA

85-100

AB

75-8

BB

65-74

BC

55-64

CC

45-54

CD

40-44

DD

35-39

FF

<35(FAIL)

a.       Eachofthefoursubjectsisworth100Marks.

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.


File Name :gtugrade.php

PHP Script: GTU Result Calculation

<?php // Function to calculate grade based on marks function getGrade($marks) { if ($marks >= 85 && $marks <= 100) return "AA"; else if ($marks >= 75 && $marks <= 84) return "AB"; else if ($marks >= 65 && $marks <= 74) return "BB"; else if ($marks >= 55 && $marks <= 64) return "BC"; else if ($marks >= 45 && $marks <= 54) return "CC"; else if ($marks >= 40 && $marks <= 44) return "CD"; else if ($marks >= 35 && $marks <= 39) return "DD"; else return "FF"; } // Marks of 4 subjects $subjects = array( "Subject 1" => 78, "Subject 2" => 66, "Subject 3" => 82, "Subject 4" => 34 ); $result = "PASS"; // Check pass/fail condition foreach ($subjects as $marks) { if ($marks < 35) { $result = "FAIL"; break; } } ?> <!DOCTYPE html> <html> <head> <title>GTU Result</title> <style> table { border-collapse: collapse; width: 50%; } th, td { border: 1px solid black; padding: 8px; text-align: center; } th { background-color: #f2f2f2; } </style> </head> <body> <h2>Student Result</h2> <table> <tr> <th>Subject</th> <th>Marks</th> <th>Grade</th> </tr> <?php foreach ($subjects as $subject => $marks) { echo "<tr>"; echo "<td>$subject</td>"; echo "<td>$marks</td>"; echo "<td>" . getGrade($marks) . "</td>"; echo "</tr>"; } ?> </table> <h3>Final Result: <?php echo $result; ?></h3> </body> </html>

Comments

Popular posts from this blog

Unit I - Introduction to PHP

Practical - 1 IWD

Practical - 10 IWD