Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,241 members, 7,815,329 topics. Date: Thursday, 02 May 2024 at 10:55 AM

Free Cgpa Calculator For Undergraduate Written With Php - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Free Cgpa Calculator For Undergraduate Written With Php (5136 Views)

Free Php Cgpa Calculator For Undergraduate / Designing A Site With Php And Oracle Tutorial (Oracle 10G) / Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: (2) (3) (4)

(1) (Reply)

Free Cgpa Calculator For Undergraduate Written With Php by campusconnects: 10:11pm On Sep 09, 2010
<?php
?>
<form action='<?php echo $_SERVER[PHP_SELF]?>' method='post'>
<table border='0px' style='width:250px;margin-left:auto;margin-right:auto;float:left'>
<tr><td style='width:50px'><select name='rowNumber' style='border:1px solid #666666;width:50px'>
<?php
for ($i=1;$i<=50;$i++)
{
$selected = ((isset($_POST['rowNumber']) && $_POST['rowNumber'] == $i) || (isset($_GET['rowNumber']) && $_GET['rowNumber'] == $i))?"selected":"";
print("<option value='".$i."'$selected>".$i."</option>"wink;
}
?>
</select></td>
<td><input type='submit' name='SpecifyRows' style='width:85px;cursor:pointer' value='Specify rows'/>&nbsp;&nbsp;<input type='submit' style='width:65px;cursor:pointer' name='reset' value='Reset'/></td></tr>
</table>
</form>
<?php

class gpClassic
{
public $_num;
public $_gp;
function __construct($num)
{
$this->_num = $num;
}
function rowNum()
{
echo <<< FORM
<form action='{$_SERVER[PHP_SELF]}?applications=yes&rowNumber={$_GET[rowNumber]}' method='post'>
<table border='0px' style='width:240px;margin-left:auto;margin-right:auto;float:left;clear:both'>
<tr style='background-color:#666666;color:#ffffff;font-size:12px;text-align:center'><th style='width:20px'>S/N</th><th style='width:50px'>Unit</th><th style='width:75px'>Course Code</th><th style='width:60px'>Grade</th></tr>
FORM;
for ($us=1,$gs=1;$us<=$this->_num,$gs<=$this->_num;$us++,$gs++)
{
echo <<< FORM
<tr style='background-color:#cccccc'>
<td style='text-align:center'>{$us}.</td>
<td style='width:50px'><select name='unit{$us}' style='border:1px solid #666666;width:100%'>
<option value=''>Unit</option>
FORM;
for ($uo=1;$uo<=5;$uo++)
{
$selected = (isset($_POST[unit.$us]) && $_POST[unit.$us] == $uo)?"selected":"";
print("<option value='{$uo}' $selected>{$uo}</option>"wink;
}
echo <<< FORM
</select></td>
<td style='text-align:center;width:75px'><input style='width:75px;border:1px solid #666666' type='text' name='courseCode{$us}' value={$_POST[courseCode.$us]} ></td>
<td style='width:60px'><select name='grade{$gs}' style='border:1px solid #666666;width:60px'>
<option value=''>Grade</option>
FORM;

for ($go=5;$go>=0;$go--)
{
$selected = (isset($_POST[grade.$gs]) && $_POST[grade.$gs] == $go && $_POST[grade.$gs] != ""wink?"selected":"";
print("<option value='".$go."'$selected>"wink;
if ($go == 5)
print("A$go"wink;
elseif ($go == 4)
print("B$go"wink;
elseif ($go == 3)
print("C$go"wink;
elseif ($go == 2)
print("grin$go"wink;
elseif ($go == 1)
print("E$go"wink;
elseif ($go == 0)
print("F$go"wink;
print("</option>"wink;
}
print("</select></td>"wink;
print("</tr>"wink;
}
$calc = gpClassic::calc();
echo <<< FORM
<tr><td colspan=4 style='text-align:left'><span style='font-weight:bold'>CGPA: </span>{$calc}</td></tr>
<tr><td colspan=2 style='text-align:left'><input type='submit' name='calculate' style='cursor:pointer' value='Calculate'/></td><td colspan=2 style='text-align:right'><input type='submit' name='add' style='width:55px;cursor:pointer' value='Add'/>&nbsp;&nbsp;<input type='submit' name='rev' style='width:60px;cursor:pointer' value='Remove'/>
</td></tr>
</table>
</form>
FORM;
}

function handleError()
{
if (isset($_POST['calculate']))
{
for ($hg=1;$hg<=$this->_num;$hg++)
{
if (!isset($_POST[unit.$hg]) || $_POST[unit.$hg] == "" || !isset($_POST[courseCode.$hg]) || $_POST[courseCode.$hg] == "" || !isset($_POST[grade.$hg]) || $_POST[grade.$hg] == ""wink
{
return("<span style='color:red;font-family:arial;font-size:12px'>Error has occurred.</span>"wink;
}
if (!preg_match("/^[a-zA-Z]{3}[0-9]{3}$/", $_POST[courseCode.$hg]))
{
return("<span style='color:red;font-family:arial;font-size:12px'>Invalid course code.</span>"wink;
}
}
}
}

function calc()
{
if (isset($_POST['calculate']) && !gpClassic::handleError())
{
for ($tp=0;$tp<=$this->_num;$tp++)
{
$totalPoint[] = $_POST[unit.$tp] * $_POST[grade.$tp];
$totalUnit[] = $_POST[unit.$tp];
}
bcscale(2);
if (array_sum($totalUnit) != 0)
{
$this->_gp = bcdiv(array_sum($totalPoint), array_sum($totalUnit));
$_SESSION['gp'] = $this->_gp;
return($this->_gp);
}
else
{
return("0.00"wink;
}

}
else
{
return(gpClassic::handleError());
}
}

function reward()
{
$gp = $_SESSION['gp'];
if ($gp == 4.50 || $gp > 4.50)
{
return("FIRST CLASS"wink;
}
elseif (($gp == 3.50 || $gp > 3.50) && $gp < 4.50)
{
return("SECOND CLASS UPPER"wink;
}
elseif (($gp == 2.40 || $gp > 2.40) && $gp < 3.50)
{
return("SECOND CLASS LOWER"wink;
}
elseif (($gp == 1.50 || $gp > 1.50) && $gp < 2.40)
{
return("THIRD CLASS"wink;
}
elseif (($gp == 1.00 || $gp > 1.00) && $gp < 1.50)
{
return("PASS"wink;
}
}

}

if (isset($_POST['SpecifyRows']))
{
$_GET['rowNumber'] = $_POST['rowNumber'];
$instance = new gpClassic($_POST['rowNumber']);
$instance->rowNum();
}
else if (isset($_POST['calculate']))
{
$instance = new gpClassic($_GET['rowNumber']);
$instance->rowNum();
}
elseif (isset($_POST['reset']))
{
unset($_SESSION['gp']);
$instance = new gpClassic($_POST['rowNumber']);
$instance->rowNum();
}
else
{
if (isset($_POST['rev']) && $_GET['rowNumber'] >= 2)
{
$_GET['rowNumber'] = $_GET['rowNumber'] - 1;
$instance = new gpClassic($_GET['rowNumber']);
$instance->rowNum();
}
else
{
$_GET['rowNumber'] = $_GET['rowNumber'] + 1;
$instance = new gpClassic($_GET['rowNumber']);
$instance->rowNum();
}
}
?>

(1) (Reply)

Mobile Browsing Overtakes Desktop Browsing In Nigeria / How To Report A High Ranking Blog That Stole Your Content / Moving To Oop Javascript/php Class Module Creation & Instantiation

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.