Saturday, January 9, 2016

Comb Sort in PHP

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

 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.


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>Comb 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>Comb 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 CombSort(&$data, $count) {
$gap = $count;
$swaps = true;

while ($gap > 1 || $swaps)
{
$gap /= 1.247330950103979;

if ($gap < 1)
$gap = 1;

$i = 0;
$swaps = false;

while ($i + $gap < $count)
{
$igap = $i + $gap;

if ($data[$i] > $data[$igap])
{
$temp = $data[$i];
$data[$i] = $data[$igap];
$data[$igap] = $temp;
$swaps = true;
}

$i++;
}
}
}

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



 $arr = array($a,$b,$c,$d,$e);
  $orig = implode(",", $arr); 
  
 Combsort($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>

Bucket Sort in PHP

A sample program that I wrote to sort a series of numbers using PHP using bucket sort algorithm.

 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.




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>Bucket 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>Bucket 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 BucketSort(&$data)
{
$minValue = $data[0];
$maxValue = $data[0];
$dataLength = count($data);

for ($i = 1; $i < $dataLength; $i++)
{
if ($data[$i] > $maxValue)
$maxValue = $data[$i];
if ($data[$i] < $minValue)
$minValue = $data[$i];
}

$bucket = array();
$bucketLength = $maxValue - $minValue + 1;
for ($i = 0; $i < $bucketLength; $i++)
{
$bucket[$i] = array();
}

for ($i = 0; $i < $dataLength; $i++)
{
array_push($bucket[$data[$i] - $minValue], $data[$i]);
}
$k = 0;
for ($i = 0; $i < $bucketLength; $i++)
{
$bucketCount = count($bucket[$i]);
if ($bucketCount > 0)
{
for ($j = 0; $j < $bucketCount; $j++)
{
$data[$k] = $bucket[$i][$j];
$k++;
}
}
}
}

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


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

 BucketSort($arr);
 $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>



Bubble Sort in PHP

A sample program that I wrote in PHP to perform bubble sort algorithm.

 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.


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>Bubble 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>Bubble 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 Bubble_Sort(array $arr)
{
    $n = sizeof($arr);    
    for ($i = 1; $i < $n; $i++) {
        $flag = false;
        for ($j = $n - 1; $j >= $i; $j--) {
            if($arr[$j-1] > $arr[$j]) {
                $tmp = $arr[$j - 1];
                $arr[$j - 1] = $arr[$j];
                $arr[$j] = $tmp;
                $flag = true;
            }
        }
        if (!$flag) {
            break;
        }
    }
     
    return $arr;
}

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

  $arr = array($a,$b,$c,$d,$e);
  $result = Bubble_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>





Sunday, December 20, 2015

Switch Statement in JavaScript

In this article I would like to share with you guys how to use and declare switch statement in JavaScript as our programming language. Switch statement is another type of conditional statement mainly use to check for conditions based on the values that is being provided by our user of our program. The advantage of using switch statement is that it is easy to understand in terms  of declaration and usage but the problem with switch statement we are not allow to use logical and relational operators that why many of conditional statements are using if - else statement instead of switch statement.

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> Switch Statement in JavaScript</title>
</head>
<body>
<script language = "Javascript">
var v = parseInt (prompt ("Enter a number from 0 - 9 ONLY!!!", " "));
switch (value) {
case 0:
document.write("<b>Number " + v + " is " + "ZERO in word format.");
break;
case 1:
document.write("<b>Number " + v + " is " + "ONE in word format.");
break;
case 2:
document.write("<b>Number " + v + " is " + "TWO in word format.");
break;
case 3:
document.write("<b>Number " + v + " is " + "THREE in word format.");
break;
case 4:
document.write("<b>Number " + v + " is " + "FOUR in word format.");
break;
case 5:
document.write("<b>Number " + v + " is " + "FIVE in word format.");
break;
case 6:
document.write("<b>Number " + v + " is " + "SIX in word format.");
break;
case 7:
document.write("<b>Number " + v + " is " + "SEVEN in word format.");
break;
case 8:
document.write("<b>Number " + v + " is " + "EIGHT in word format.");
break;
case 9:
document.write("<b>Number " + v + " is " + "NINE in word format.");
break;
default:
document.write("<b>Invalid Number!");
}
</script>
</body>
</html>

Search a record in PHP and MySQL

A simple program that I wrote before in PHP and MySQL to search a record from the database. The code is very easy to understand and use in your projects related to PHP and MySQL.

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.



Sample Program Output


Personnel Mailing List System in CakePHP

There are many PHP frameworks in the market today one of the most simple and easiest PHP framework in CakePHP I find easy to learn and understand in this article I would like to share with you an application that I wrote using CakePHP. I called this application Personnel Mailing List System that will store the name, home address, telephone, mobile and email address of a person in a company.

This application is based on the work of my friend and fellow software engineer Mike Dalisay in this website https://www.codeofaninja.com. I am thankful that Mike share his knowledge and skills in CakePHP I learned a lot from it.

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.

Reference:

https://www.codeofaninja.com/2012/04/cakephp-2x-crud-tutorial.html






Sample Program Output










Friday, December 18, 2015

Average of Five Numbers in Python

This is a simple program that I wrote using Python as my programming language that will find the average of five numbers that is being given by the user. I am still learning how to program in Python I find it very easy to write simple program ideal for beginners in Python programming in general sense.

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

My mobile number here in the Philippines is 09173084360.



Sample Program Output

Program Listing

print('\n')
print('\t Average of Five Numbers')
print('\n')
val1 = int(input('Enter first  value : '))
val2 = int(input('Enter second value : '))
val3 = int(input('Enter third  value : '))
val4 = int(input('Enter fourth value : '))
val5 = int(input('Enter fifth  value : '))

average = (val1+val2+val3+val4+val5) /5

print('\n')
print("The average of five numbers is {0}.".format(round(average,2)))
print('\n')
print('Thank you for using this program')





Odd and Even Number in Python

A simple program that I wrote in Python programming language to check if the number given by the user is odd or even number.

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

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

print('\n')
print('\t Odd and Even Number Checker')
print('\n')
number_value = int(input('Enter a Number : '))

if (number_value % 2) == 0:
   print(" The given number {0} is an EVEN number.".format(number_value))
else:
   print("The given number {0} is an ODD number.".format(number_value))

print('\n')
print('Thank you for using this program')





Area of a Circle Solver in Python Version 2

A second version of my program in Python to solve the area of a circle based on the given radius by the user.

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

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

import math

print('\n')
print('\t Area of the Circle Solver')
print('\n')
radius = input('Enter the radius of the circle: ')

area= (radius**2) * math.pi
print('\n')
print('The radius of the circle is {0}.'.format(radius))
print('The area of the circle is {0}. '.format(round(area,2)))
print('\n')
print('Thank you for using this program')



Addition of Three Numbers in Python

This sample program that I wrote using Python programming language  will find the sum of three numbers given by the user. I find Python programming easy to understand and learn I am still a beginner in Python programming so to speak. I hope you will find my work useful in learning Python programming.

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

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing


print('Addition of Three Numbers')
print('\n')
num1 = input('Enter first number: ')
num2 = input('Enter second number: ')
num3 = input('Enter third number: ')

sum = float(num1) + float(num2) + float(num3)

print('\n')
print('The sum of {0},{1} and {2} is {3}'.format(num1, num2,num3,sum))
print('\n')
print('Thank you for using this program')


Tuesday, December 15, 2015

addition of two numbers in java

This sample program that I wrote in Java will compute the total of two numbers using applet as our graphical user interface. I used this code as one of my programming laboratory activities during the time I working as college professor. I hope you will find my work useful in your quest to learn Java programming.

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

My mobile number here in the Philippines is 09173084360.


  

Sample Program Output


Program Listing

    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.awt.Label;

    public class add extends Applet implements ActionListener{
      TextField text1,text2,output;
      Label label1,label2,label3,title;
      Button button,clear;
      public void init(){
        setLayout(null);


          title = new Label("Addition of Two Numbers");
          title.setBounds(80,10,140,20);
          add(title);
          title.setAlignment(title.CENTER);

        label1 = new Label("Enter Number 1: ");
        label1.setBounds(20,50,100,20);
        add(label1);

        text1 = new TextField(5);
        text1.setBounds(150,50,100,20);
        add(text1);

        label2 = new Label("Enter Number 2: ");
        label2.setBounds(20,90,100,20);
        add(label2);

        text2 = new TextField(5);
        text2.setBounds(150,90,100,20);
        add(text2);

        label3 = new Label("Sum of Two Numbers: ");
        label3.setBounds(20,130,130,20);
        add(label3);

        output = new TextField(5);
        output.setBounds(150,130,100,20);
        add(output);

        button = new Button("Sum");
        button.setBounds(150,170,100,20);
        add(button);

        clear = new Button("Clear");
        clear.setBounds(280,170,100,20);
        add(clear);

        button.addActionListener(this);
        clear.addActionListener(this);


        }
        public void actionPerformed(ActionEvent ae){
        int num1=Integer.parseInt(text1.getText());
        int num2=Integer.parseInt(text2.getText());
        int sum=num1+num2;
        output.setText(Integer.toString(sum));
            if(ae.getSource() == clear)
            {
                 text1.setText("");
              text2.setText("");
               output.setText("");
               text1.requestFocus();
    }
}
}