Ex No: 3 Write a program to Perform Student Grade Manipulation
Aim: To perform Stuent Grade Manipulation using php
Algorithm
Step1: Design a webpage to get Student Name, Register Number and three subnect marks.
Step2: On form submit check if Register number is set and not empty
   A) Get values of Student Name, Register Number and three subnect marks from POST method
   B) Calculate total as sum of subject1, subject2 and subject3
   C) Check if each subject mark is greater than 50
     i) Assign result as PASS
   D) Else
     i) Assign result as FAIL
   E) Display the data in marksheet format
   F) Get grade of each subject using the grade function
function grade($mark)
Step1: Calculate option as floor(mark/10)
Step2: Switch option value
   A)For option values 0,1,2,3,4 assign grade as F
   B)For option value 5 assign grade as E
   C)For option value 6 assign grade as D
   D)For option value 7 assign grade as C
   E)For option value 8 assign grade as B
   F)For option value 9 assign grade as A
   G)For option value 10 assign grade as A
Step3: Return assigned grade value
Source Code

index.html


<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title>Student Grade Manipulation</title>
</head>
<body>
 <h3>Student Grade Manipulation</h3>
 <div style="float: left; width: 500px;">
  <form id="gradeform" name="gradeform" method="POST" action="ex3.php">
   <table>
    <tr>
     <td>Register No:</td>
     <td><input type="text" id="regno" name="regno"/></td>
    </tr>
    <tr>
     <td>Name:</td>
     <td><input type="text" id="name" name="name"/></td>
    </tr>
    <tr>
     <td>Subject1 Marks:</td>
     <td><input type="text" id="sub1" name="sub1"/></td>
    </tr>
    <tr>
     <td>Subject2 Marks:</td>
     <td><input type="text" id="sub2" name="sub2"/></td>
    </tr>
    <tr>
     <td>Subject3 Marks:</td>
     <td><input type="text" id="sub3" name="sub3"/></td>
    </tr>
    <tr>
     <td><input type="submit" value="Mark Sheet"/></td>
     <td><input type="reset"/></td>
    </tr>
 </table>
 </form>
 </div> 
</body>
</html>

ex3.php


<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8">
 <title>Student Grade Manipulation</title>
</head>
<body>
 <?php
  function grade($mark)
  {
  	$opt = floor($mark/10);
  	$grd="";
  	switch($opt)
  	{
	  case 0:
	  case 1:
	  case 2:
	  case 3:
	  case 4:
	  	$grd = "F";
	  	break;
	  case 5:
	  	$grd = "E";
	  	break;
	  case 6:
	  	$grd = "D";
	  	break;
	  case 7:
	  	$grd = "C";
	  	break;
	  case 8:
	  	$grd = "B";
	  	break;
	  case 9:
	  	$grd = "A";
	  	break;
	  case 10:
	  	$grd = "S";
	  	break;
	}
  	return $grd;
  }//End of Grade function
  
  #starting point of the php program
  if(isset($_POST["regno"]) && $_POST["regno"]!="")
  {
	$regno = $_POST["regno"];
	$name = $_POST["name"];
	$sub1 = $_POST["sub1"];
	$sub2 = $_POST["sub2"];
	$sub3 = $_POST["sub3"];
	$total = $sub1 + $sub2 + $sub3;
	if($sub1 >= 50 && $sub2 >=50 && $sub3 >= 50)
	{
	  $res = "PASS";
	}
	else
	{
	  $res = "FAIL";	
	}
 ?>
 <h4>Mark Sheet</h4>
 <p>
  <b>Name: <?php echo $name; ?></b><br>
  <b>Reg No: <?php echo $regno; ?> 	</b>
 </p>
 <table style="text-align: center;">
  <tr>
   <th>Subject</th><th>Marks</th><th>Grade</th>	
  </tr>
  <tr>
    <td>Subject1</td>
    <td><?php echo $sub1; ?></td>
    <td><?php echo grade($sub1); ?></td>
  </tr>
  <tr>
    <td>Subject2</td>
    <td><?php echo $sub2; ?></td>
    <td><?php echo grade($sub2); ?></td>
  </tr>
  <tr>
    <td>Subject3</td>
    <td><?php echo $sub3; ?></td>
    <td><?php echo grade($sub3); ?></td>
  </tr>
  <tr>
    <td colspan="2">Total: <?php echo $total;?></td>
    <td></td>
  </tr>
  <tr>
    <td colspan="2">Result: <?php echo $res;?></td>
    <td></td>
  </tr>
 </table>
 <?php
  }
 ?>
 </body>
</html>
                  
Result: Thus a webpage is designed using php to perform Student Grade Manipulation.