Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
128 views4 pages

CGP Calculator HTML

The document is a CGPA (cumulative grade point average) calculator that allows users to input their grades and credits for up to 6 classes. It uses a script to retrieve the user's input, assign grade point values to each grade based on a predefined scale, calculate the total grade points and total credits, and divide them to display the user's CGPA. It also includes validation to check that grades are in the expected format and ensures at least one credit is entered.

Uploaded by

Ram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views4 pages

CGP Calculator HTML

The document is a CGPA (cumulative grade point average) calculator that allows users to input their grades and credits for up to 6 classes. It uses a script to retrieve the user's input, assign grade point values to each grade based on a predefined scale, calculate the total grade points and total credits, and divide them to display the user's CGPA. It also includes validation to check that grades are in the expected format and ensures at least one credit is entered.

Uploaded by

Ram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

<html>

<body>
<h2 align="center">CGPA Calculator </h2>
<hr />
<CENTER>
<FORM Name="CgpaCalForm">
<TABLE BORDER=2 CELLPADDING="5" CELLSPACING="2">
<TH></TH>
<TH>Grade</TH>
<TH>Credits</TH>
<TR>
<TD>Class 1</TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="GR1" ALIGN=TOP
MAXLENGTH=5></TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="CR1" ALIGN=TOP
MAXLENGTH=5></TD>
</TR>
<TR>
<TD>Class 2</TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="GR2" ALIGN=TOP
MAXLENGTH=5></TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="CR2" ALIGN=TOP
MAXLENGTH=5></TD>
</TR>
<TR>
<TD>Class 3</TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="GR3" ALIGN=TOP
MAXLENGTH=5></TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="CR3" ALIGN=TOP
MAXLENGTH=5></TD>
</TR>
<TR>
<TD>Class 4</TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="GR4" ALIGN=TOP
MAXLENGTH=5></TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="CR4" ALIGN=TOP
MAXLENGTH=5></TD>
</TR>
<TR>
<TD>Class 5</TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="GR5" ALIGN=TOP
MAXLENGTH=5></TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="CR5" ALIGN=TOP
MAXLENGTH=5></TD>
</TR>
<TR>
<TD>Class 6</TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="GR6" ALIGN=TOP
MAXLENGTH=5></TD>
<TD><INPUT TYPE=TEXT SIZE=5 NAME="CR6" ALIGN=TOP
MAXLENGTH=5></TD>
</TR>
<TR ALIGN=CENTER>
<TD COLSPAN=3><INPUT TYPE="BUTTON" VALUE="Calculate"
NAME="CalcButton" OnClick="gpacalc()"></TD>
</TR>
</TABLE>
<h3 id="response"></h3>
</FORM>
<BR>
<P>
<P>
</CENTER>
<BR>
<p align="center">Note : Please use GRADES in the form of a,a-,b,b+,b-,c,c+,c-,d,f - (Small
Letters) and CREDIT in Numbers (1,2,3,4,5) </p>
</body>
</html>
<SCRIPT>
function gpacalc(){
//define valid grades and their values
var gr = new Array(9); var cr = new Array(9); var ingr = new Array(5); var incr = new
Array(5);
// define valid grades and their values
var grcount = 10;
gr[0] = "a"; cr[0] = 4;
gr[1] = "a-"; cr[1] = 3.66;
gr[2] = "b+"; cr[2] = 3.33;
gr[3] = "b"; cr[3] = 3;
gr[4] = "b-"; cr[4] = 2.66;
gr[5] = "c+"; cr[5] = 2.33;
gr[6] = "c"; cr[6] = 2;
gr[7] = "c-"; cr[7] = 1.66;
gr[8] = "d"; cr[8] = 1;
gr[9] = "f"; cr[9] = 0;
// retrieve user input
ingr[0] = document.CgpaCalForm.GR1.value;
ingr[1] = document.CgpaCalForm.GR2.value;
ingr[2] = document.CgpaCalForm.GR3.value;
ingr[3] = document.CgpaCalForm.GR4.value;
ingr[4] = document.CgpaCalForm.GR5.value;
ingr[5] = document.CgpaCalForm.GR6.value;
incr[0] = document.CgpaCalForm.CR1.value;
incr[1] = document.CgpaCalForm.CR2.value;
incr[2] = document.CgpaCalForm.CR3.value;
incr[3] = document.CgpaCalForm.CR4.value;
incr[4] = document.CgpaCalForm.CR5.value;
incr[5] = document.CgpaCalForm.CR6.value;
// Calculate GPA
var allgr =0; var allcr = 0; var gpa = 0;
for (var x = 0; x < 5 + 1; x++)
{
if (ingr[x] == "") break;
var validgrcheck = 0;
for (var xx = 0; xx < grcount; xx++)
{
if (ingr[x] == gr[xx])
{
allgr = allgr + (parseInt(incr[x],10) * cr[xx]);
allcr = allcr + parseInt(incr[x],10);
validgrcheck = 1;
break;
}
}
if (validgrcheck == 0)
{
alert("Error- Could not recognize the grade entered for Class " + eval(x + 1) + ". Please use
standard college grades in the form of A A- B+ ...F.");
return 0;
}
}
if (allcr == 0)
{
alert("Error- You did not enter any credit values! GPA = N/A");
return 0;
}
gpa = allgr / allcr;
//alert("CGPA = " + eval(gpa));
document.getElementById('response').innerHTML = "<h3 style='color:green;'>CGPA is : "
+ eval(gpa);
return 0;
}
</SCRIPT>

You might also like