Sunday, January 10, 2016

Average Grade Solver in JavaScript

A simple program that I wrote in JavaScript to solve the average grade of the student based on the subjects the students taken that program also gives remarks whether the student pass or failed in the average grade. The program is very useful for those who wants to learning JavaScript programming.

If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Program Listing


<html>
<head>
<title>Average Grade Solver in JavaScript </title>
                <h1> Average Grade Solver in JavaScript </h1>
<script language = "Javascript">

function Average(eng,math,theo,sci,his)
{
ave = (eng+math+theo+sci+his)/5;
return(ave);
}
var studname = prompt ("Enter Student Name:","");
var gr_eng = parseInt (prompt ("Enter grade in English:"," "));
var gr_math = parseInt (prompt ("Enter grade in Math:"," "));
var gr_theo = parseInt (prompt ("Enter grade in Theology:"," "));
var gr_sci = parseInt (prompt ("Enter grade in Science:"," "));
var gr_his = parseInt (prompt ("Enter grade in History:"," "));
var ave=Average(gr_eng,gr_math,gr_theo,gr_sci,gr_his);

document.write ("<center><h1> STUDENT GRADE SHEET </h1><hr width='75%' color='blue' size='3'>");
document.write ("<table><tr><td>Student<td>Name:<td><b>",studname,"</b>");
document.write ("<tr><td><b><u>Subject:</b></u><td><br>");
document.write ("<tr><td><br><td> English:<td>",gr_eng);
document.write ("<tr><td><br><td> Math:<td>",gr_math);
document.write ("<tr><td><br><td> Theology:<td>",gr_theo);
document.write ("<tr><td><br><td> Science:<td>",gr_sci);
document.write ("<tr><td><br><td> History:<td>",gr_his);
document.write ("<tr><td>Average<td>Grade:<td><b><p>",ave,"</b>");
if (ave >= 75)
{
status = "Passed";
}
else
{
status = "Failed";
}
document.write ("<tr><td>Status:<td><br><td><b>",status,"</b></table><hr width=75% color='blue' size=3>"); 
</script>
</head>

<body bgcolor = "green" text = "white">

</body>
</html>


Saturday, January 9, 2016

Total Product Cost Solver in C++

This sample program will compute for the total cost of products purchase in a grocery store using C++ as our programming language.

If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Program Listing

#include <iostream>
#include <iomanip>

using namespace std;

main() {

    string products[50];
    int values=0;
    float item_price[50];
    int total_cost=0,paid=0;
    float tax = 0.12,solve=0.00,tax_solve=0.00;
    float final_cost=0.00;
    cout << "\n\t\t ABC Grocery Store";
    cout << "\n\n";
    cout << "How many items : ";
    cin >> values;
     for (int x=1; x<=values; x++)
       {
           cout << setprecision(2) << fixed;
           cout << "\n\n";
           cout << "Item Name  : ";
           cin >> products[x];
           cout << "Item Price : ";
           cin >> item_price[x];
           total_cost+= item_price[x];
           cout << "\n";
           cout << "Sub-Total Cost $ " << total_cost;

       }
      cout << "\n\n";

       tax_solve = ( total_cost * tax);
        final_cost = (total_cost + tax_solve);
      cout << setprecision(2) << fixed;
      cout << "\nVAT 12%     $ " <<tax_solve;
       cout << "\nTotal Cost $ " << final_cost;
       cout << "\n";
       cout << "\nEnter  amount Paid  $ ";
      cin >> paid;
      solve = (paid - final_cost);
      cout << "\n\n";
      cout << "Amount Change $ " << solve;

     cout << "\n\n";
     system("pause");
}

Shell Sort in PHP

A simple program that I wrote in PHP to sort a series of numbers Shell Sort algorithm.

 If you have some questions please send me an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com.  

My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

<?php
error_reporting(0);
$a= $_POST['val_1'];
$b= $_POST['val_2'];
$c= $_POST['val_3'];
$d= $_POST['val_4'];
$e= $_POST['val_5']; 

 if(isset($_POST['clear']))
$a=""; $b=""; $c=""; $d=""; $e="";
$display_original="";  $process_results="";
}

?>
<html>
<head>
<title>Shell Sort in PHP</title>
<style>
body { font-family:arial;}
form { width: 400px; }
label { float: left; width: 95px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }
</style>
</head>
<body>
<h2>Shell Sort in PHP</h2>
<form  action="" method="post">
<label>Value No. 1 : </label> <input type="text" name="val_1" value="<?php echo $a; ?>" size="5" maxlength="5"  autofocus/><br/><br>
<label>Value No. 2 : </label> <input type="text" name="val_2" value="<?php echo $b; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 3 : </label> <input type="text" name="val_3" value="<?php echo $c; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 4 : </label> <input type="text" name="val_4" value="<?php echo $d; ?>"size="5" maxlength="5"/><br/><br>
<label>Value No. 5 : </label> <input type="text" name="val_5" value="<?php echo $e; ?>"size="5" maxlength="5"/><br/>
<br />
<input type="submit" value="Sort" name="bubble"/>
<input type="submit" value="Clear" name="clear" />
</form>

<?php

function shellsort(array $arr)
{
    $n = sizeof($arr);
    $t = ceil(log($n, 2));
    $d[1] = 1;
    for ($i = 2; $i <= $t; $i++) {
        $d[$i] = 2 * $d[$i - 1] + 1;
    }
     
    $d = array_reverse($d);
    foreach ($d as $curIncrement) {
        for ($i = $curIncrement; $i < $n; $i++) {
            $x = $arr[$i];
            $j = $i - $curIncrement;
            while ($j >= 0 && $x < $arr[$j]) {
                $arr[$j + $curIncrement] = $arr[$j];
                $j = $j - $curIncrement;
            }
            $arr[$j + $curIncrement] = $x;
        }
    }
     
    return $arr;
}


    
if(isset($_POST['bubble']))

  $arr = array($a,$b,$c,$d,$e);
  $result = shellsort($arr);

  $original_values = implode(",", $arr);
  $withComma = implode(",", $result);

  $display_original =  "Original Values : " .$original_values."<br><br>";
  $process_results  = "Sorted Values : " .$withComma."<br>";
  
  echo $display_original;
  echo $process_results;

}

?>
</body>
</html>



Selection Sort in PHP

A simple program that I wrote in PHP to sort a series of numbers Selection Sort algorithm.

 If you have some questions please send me an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com.  

My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

<?php
error_reporting(0);
$a= $_POST['val_1'];
$b= $_POST['val_2'];
$c= $_POST['val_3'];
$d= $_POST['val_4'];
$e= $_POST['val_5']; 

 if(isset($_POST['clear']))
$a=""; $b=""; $c=""; $d=""; $e="";
$display_original="";  $process_results="";
}

?>
<html>
<head>
<title>Selection Sort in PHP</title>
<style>
body { font-family:arial;}
form { width: 400px; }
label { float: left; width: 95px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }
</style>
</head>
<body>
<h2>Selection Sort in PHP</h2>
<form  action="" method="post">
<label>Value No. 1 : </label> <input type="text" name="val_1" value="<?php echo $a; ?>" size="5" maxlength="5"  autofocus/><br/><br>
<label>Value No. 2 : </label> <input type="text" name="val_2" value="<?php echo $b; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 3 : </label> <input type="text" name="val_3" value="<?php echo $c; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 4 : </label> <input type="text" name="val_4" value="<?php echo $d; ?>"size="5" maxlength="5"/><br/><br>
<label>Value No. 5 : </label> <input type="text" name="val_5" value="<?php echo $e; ?>"size="5" maxlength="5"/><br/>
<br />
<input type="submit" value="Sort" name="bubble"/>
<input type="submit" value="Clear" name="clear" />
</form>

<?php

function Selection_Sort(array $arr)
{
    $n = sizeof($arr);
    for ($i = 0; $i < $n; $i++) {
        $lowestValueIndex = $i;
        $lowestValue = $arr[$i];
        for ($j = $i + 1; $j < $n; $j++) {
            if ($arr[$j] < $lowestValue) {
                $lowestValueIndex = $j;
                $lowestValue = $arr[$j];
            }
        }

        $arr[$lowestValueIndex] = $arr[$i];
        $arr[$i] = $lowestValue;
    }
     
    return $arr;
}


    
if(isset($_POST['bubble']))

  $arr = array($a,$b,$c,$d,$e);
  $result = Selection_Sort($arr);

  $original_values = implode(",", $arr);
  $withComma = implode(",", $result);

  $display_original =  "Original Values : " .$original_values."<br><br>";
  $process_results  = "Sorted Values : " .$withComma."<br>";
  
  echo $display_original;
  echo $process_results;

}

?>
</body>
</html>





Radix Sort in PHP

A simple program that I wrote in PHP to sort a series of numbers Radix Sort algorithm.

 If you have some questions please send me an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com.  

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<?php
error_reporting(0);
$a= $_POST['val_1'];
$b= $_POST['val_2'];
$c= $_POST['val_3'];
$d= $_POST['val_4'];
$e= $_POST['val_5']; 

 if(isset($_POST['clear']))
$a=""; $b=""; $c=""; $d=""; $e="";
$display_original="";  $process_results="";
}

?>
<html>
<head>
<title>Radix Sort in PHP</title>
<style>
body { font-family:arial;}
form { width: 400px; }
label { float: left; width: 95px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }
</style>
</head>
<body>
<h2>Radix Sort in PHP</h2>
<form  action="" method="post">
<label>Value No. 1 : </label> <input type="text" name="val_1" value="<?php echo $a; ?>" size="5" maxlength="5"  autofocus/><br/><br>
<label>Value No. 2 : </label> <input type="text" name="val_2" value="<?php echo $b; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 3 : </label> <input type="text" name="val_3" value="<?php echo $c; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 4 : </label> <input type="text" name="val_4" value="<?php echo $d; ?>"size="5" maxlength="5"/><br/><br>
<label>Value No. 5 : </label> <input type="text" name="val_5" value="<?php echo $e; ?>"size="5" maxlength="5"/><br/>
<br />
<input type="submit" value="Sort" name="bubble"/>
<input type="submit" value="Clear" name="clear" />
</form>

<?php

function RadixSort(&$data, $count) {
for ($shift = 31; $shift > -1; $shift--)
{
$j = 0;

for ($i = 0; $i < $count; $i++)
{
$move = ($data[$i] << $shift) >= 0;

if ($shift == 0 ? !$move : $move)
$data[$i - $j] = $data[$i];
else
$temp[$j++] = $data[$i];
}

for ($i = 0; $i < $j; $i++)
{
$data[($count - $j) + $i] = $temp[$i];
}
}

$temp = null;
}

if(isset($_POST['bubble']))

  $arr = array($a,$b,$c,$d,$e);
  $orig = implode(",", $arr); 
 $result = RadixSort($arr,5);
 $final_sort = implode(",", $arr);

  $display_original =  "Original Values : " .$orig."<br><br>";
  $process_results  = "Sorted Values : " .$final_sort."<br>";
  
  echo $display_original;
  echo $process_results;

}

?>
</body>
</html>



Quick Sort in PHP

A simple program that I wrote in PHP to sort a series of numbers Quick Sort algorithm.

 If you have some questions please send me an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com.  

My mobile number here in the Philippines is 09173084360.


Sample Program Output


Program Listing

<?php
error_reporting(0);
$a= $_POST['val_1'];
$b= $_POST['val_2'];
$c= $_POST['val_3'];
$d= $_POST['val_4'];
$e= $_POST['val_5']; 

 if(isset($_POST['clear']))
$a=""; $b=""; $c=""; $d=""; $e="";
$display_original="";  $process_results="";
}

?>
<html>
<head>
<title>Quick Sort in PHP</title>
<style>
body { font-family:arial;}
form { width: 400px; }
label { float: left; width: 95px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }
</style>
</head>
<body>
<h2>Quick Sort in PHP</h2>
<form  action="" method="post">
<label>Value No. 1 : </label> <input type="text" name="val_1" value="<?php echo $a; ?>" size="5" maxlength="5"  autofocus/><br/><br>
<label>Value No. 2 : </label> <input type="text" name="val_2" value="<?php echo $b; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 3 : </label> <input type="text" name="val_3" value="<?php echo $c; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 4 : </label> <input type="text" name="val_4" value="<?php echo $d; ?>"size="5" maxlength="5"/><br/><br>
<label>Value No. 5 : </label> <input type="text" name="val_5" value="<?php echo $e; ?>"size="5" maxlength="5"/><br/>
<br />
<input type="submit" value="Sort" name="bubble"/>
<input type="submit" value="Clear" name="clear" />
</form>

<?php

function quicksort(array $arr, $left, $right)
{
    $i = $left;
    $j = $right;
    $separator = $arr[floor(($left + $right) / 2)];
     
    while ($i <= $j) {
        while ($arr[$i] < $separator) {
            $i++;
        }
         
        while($arr[$j] > $separator) {
            $j--;
        }
         
        if ($i <= $j) {
            $tmp = $arr[$i];
            $arr[$i] = $arr[$j];
            $arr[$j] = $tmp;
            $i++;
            $j--;
        }
    }
     
    if ($left < $j) {
        $arr = quicksort($arr, $left, $j);
    }
     
    if ($right > $i) {
        $arr = quicksort($arr, $i, $right);
    }
     
    return $arr;
}

    
if(isset($_POST['bubble']))

  $arr = array($a,$b,$c,$d,$e);
  $result = quicksort($arr, 0, (sizeof($arr)-1));

  $original_values = implode(",", $arr);
  $withComma = implode(",", $result);

  $display_original =  "Original Values : " .$original_values."<br><br>";
  $process_results  = "Sorted Values : " .$withComma."<br>";
  
  echo $display_original;
  echo $process_results;

}

?>
</body>
</html>



Merge Sort in PHP

A simple program that I wrote in PHP to sort a series of numbers Merge Sort algorithm.

 If you have some questions please send me an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com.  

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<?php
error_reporting(0);

$a= $_POST['val_1'];
$b= $_POST['val_2'];
$c= $_POST['val_3'];
$d= $_POST['val_4'];
$e= $_POST['val_5']; 

 if(isset($_POST['clear']))
$a=""; $b=""; $c=""; $d=""; $e="";
$display_original="";  $process_results="";
}
?>
<html>
<head>
<title>Merge Sort in PHP</title>
<style>
body { font-family:arial;}
form { width: 400px; }
label { float: left; width: 95px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }
</style>
</head>
<body>
<h2>Merge Sort in PHP</h2>
<form  action="" method="post">
<label>Value No. 1 : </label> <input type="text" name="val_1" value="<?php echo $a; ?>" size="5" maxlength="5"  autofocus/><br/><br>
<label>Value No. 2 : </label> <input type="text" name="val_2" value="<?php echo $b; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 3 : </label> <input type="text" name="val_3" value="<?php echo $c; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 4 : </label> <input type="text" name="val_4" value="<?php echo $d; ?>"size="5" maxlength="5"/><br/><br>
<label>Value No. 5 : </label> <input type="text" name="val_5" value="<?php echo $e; ?>"size="5" maxlength="5"/><br/>
<br />
<input type="submit" value="Sort" name="bubble"/>
<input type="submit" value="Clear" name="clear" />
</form>

<?php
function Merge(&$data, $left, $mid, $right) {
$n1 = $mid - $left + 1;
$n2 = $right - $mid;

for ($i = 0; $i < $n1; $i++)
$L[$i] = $data[$left + $i];

for ($j = 0; $j < $n2; $j++)
$R[$j] = $data[$mid + 1 + $j];

$i = 0;
$j = 0;
$k = $left;

while ($i < $n1 && $j < $n2)
{
if ($L[$i] <= $R[$j])
{
$data[$k] = $L[$i];
$i++;
}
else
{
$data[$k] = $R[$j];
$j++;
}

$k++;
}

while ($i < $n1)
{
$data[$k] = $L[$i];
$i++;
$k++;
}

while ($j < $n2)
{
$data[$k] = $R[$j];
$j++;
$k++;
}

$L = null;
$R = null;
}

function MergeSort(&$data, $count) {
for ($currentSize = 1; $currentSize <= $count - 1; $currentSize = 2 * $currentSize)
{
for ($leftStart = 0; $leftStart < $count - 1; $leftStart += 2 * $currentSize)
{
$mid = $leftStart + $currentSize - 1;
$rightEnd = min($leftStart + 2 * $currentSize - 1, $count - 1);

Merge($data, $leftStart, $mid, $rightEnd);
}
}
}


if(isset($_POST['bubble']))


 $arr = array($a,$b,$c,$d,$e);
  $orig = implode(",", $arr); 

 MergeSort($arr,5);
 $final_sort = implode(",", $arr);

  $display_original =  "Original Values : " .$orig."<br><br>";
  $process_results  = "Sorted Values : " .$final_sort."<br>";
  
  echo $display_original;
  echo $process_results;

}

?>
</body>
</html>





Insertion Sort in PHP

A simple program that I wrote in PHP to sort a series of numbers Insertion Sort algorithm.

 If you have some questions please send me an email at jakerpomperada@gmail.comand jakerpomperada@yahoo.com.  

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<?php
error_reporting(0);

$a= $_POST['val_1'];
$b= $_POST['val_2'];
$c= $_POST['val_3'];
$d= $_POST['val_4'];
$e= $_POST['val_5']; 

 if(isset($_POST['clear']))
$a=""; $b=""; $c=""; $d=""; $e="";
$display_original="";  $process_results="";
}


?>
<html>
<head>
<title>Insertion Sort in PHP</title>
<style>
body { font-family:arial;}
form { width: 400px; }
label { float: left; width: 95px; }
.clear { clear: both; height: 0; line-height: 0; }
.floatright { float: right; }
</style>
</head>
<body>
<h2>Insertion Sort in PHP</h2>
<form  action="" method="post">
<label>Value No. 1 : </label> <input type="text" name="val_1" value="<?php echo $a; ?>" size="5" maxlength="5"  autofocus/><br/><br>
<label>Value No. 2 : </label> <input type="text" name="val_2" value="<?php echo $b; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 3 : </label> <input type="text" name="val_3" value="<?php echo $c; ?>" size="5" maxlength="5"/><br/><br>
<label>Value No. 4 : </label> <input type="text" name="val_4" value="<?php echo $d; ?>"size="5" maxlength="5"/><br/><br>
<label>Value No. 5 : </label> <input type="text" name="val_5" value="<?php echo $e; ?>"size="5" maxlength="5"/><br/>
<br />
<input type="submit" value="Sort" name="bubble"/>
<input type="submit" value="Clear" name="clear" />
</form>

<?php
function InsertionSort($array) {

    $sortedArray = array();

    for ($i = 0 ; $i < count($array); $i++) {

        $element = $array[$i];
        $j = $i;

        while($j > 0 && $sortedArray[$j-1] > $element) {

            $sortedArray[$j] = $sortedArray[$j-1];
            $j = $j-1;
        }
        $sortedArray[$j] = $element;
    }
    return $sortedArray;
}

if(isset($_POST['bubble']))


 $arr = array($a,$b,$c,$d,$e);
  $orig = implode(",", $arr); 
  
 $a =InsertionSort($arr);
 $final_sort = implode(",", $a);

  $display_original =  "Original Values : " .$orig."<br><br>";
  $process_results  = "Sorted Values : " .$final_sort."<br>";
  
  echo $display_original;
  echo $process_results;

}

?>
</body>
</html>