Friday, February 27, 2015

Floyd's Triangle Maker

In this short article I would like to share with you a sample program that I wrote using PHP as our programming language I called this program Floyd's Triangle Maker what this program will do is to ask the user to enter a number and then it will generate the floyd's triangle on our screen. To give you some insights floyd's triangle was developed by an american computer scientist and mathematician named Robert Floyd. 

According to Wikipedia Floyd's Triangle is a right-angled triangular array of natural numbers, used in computer science education. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner.

1
2    3
4    5     6
7     8     9  10
11  12  13  14 15

Sample of Floyd's Triangle

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

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Sample Output of Our Program

Program Listing

<html>
<title> Floyd's Triangle Maker</title>
<style>
body { 
  font-size:20px; 
  font-family:arial;
  color:blue;
  } 
</style>
<?php

$values = $_POST['value'];

 function floyds_triangle($variable) 
{
 $a = 1;   
 for ($i = 1; $i <= $variable; $i++)
  {
    for ($c = 1; $c <= $i; $c++)
    {
      echo " ".$a." ";
      $a++;
    }
  echo '<br><br>';
  }
     
}


if(isset($_POST['check'])) {

$title = "======= FLOYD'S TRIAGLE =======";
    if (ctype_alpha($values)) {
      echo "<script>";  
  echo "alert('PLEASE ENTER A NUMERIC VALUE.');";
  echo "</script>";
  $values="";
  $title=""; 
           $result="";
 }
    else  if ($values=="") {
      echo "<script>";  
  echo "alert('It Cannot Be Empty!!! Please enter a integer value.');";
  echo "</script>";
  $title=""; 
  $values="";
           $result="";
 }
   }  

if(isset($_POST['clear'])) {
  $title=""; 
  $values=" "; 
  $result="";
  
}

?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
  <br> <h1 align="center">Floyd's Triangle Maker</h2>
  <br>
<form action="" method="post">
 Enter a Number : <input type="text" name="value"    value="<?php echo $values; ?>" autofocus  size=5 required/>
   <input type="submit" name="check" value="Find Floyd's Triangle" 
  title="Click here to view the list of Floyd's Triangle Number."/>
  <input type="submit" name="clear" value="Clear" 
  title="Click here to clear text box and values on the screen"/>
</form>

<br> <br>

<?php 

echo $title;
echo "<br><br>";
floyds_triangle($values); 

 ?>
 </body>
</html>



Thursday, February 26, 2015

Calculator Using Radio Buttons in PHP

One of the most enjoying past time that I would like to spend is to write a program it becomes one of my favorite hobbies during my college days. In this article I would like to share with you one of the most common programming problems in PHP how to write a simple calculator using radio buttons in PHP. Some of us think this kind of problem is very simple yes they are for some people who has already learned some experience in PHP programming but for some that are new in PHP problem it can gives us some headache if you don't how to figure it out. Our program will ask the user to enter two number in our text field and then our program will provide four radio buttons addition, subtraction, multiplication and division. Once the user select for example addition and click the solve button it will display the sum of the two numbers. I also added a clear button that enables the user to clear the text field and allows them to enter new values. 

The challenge that I face in writing this program is that I want to keep or retain the value of my selection radio button for example the addition radio button I want to retain its value after i click the solve button. In this program you will know how to accomplish such task with each. I have a great time writing this program I hope you will find my work useful in your quest in learning PHP programming.

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

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Sample Output of Our Program

Program Listing

<head>
<?php
error_reporting(0);

 $first = $_REQUEST['first'];
 $second= $_REQUEST['second'];

 $first2 = (int)$first;
 $second2 = (int)$second;


if (isset($_REQUEST['solve'])) {
      
 $op = $_REQUEST['op'];
    
if ($op == 'add') {
 
   $add = $first2 + $second2;
 
 $title .="The sum of ".$first2. " and " .$second2. 
          " is " .$add.".";
     }  
if ($op == 'subtract') {
 
   $subtract = $first2 - $second2;
 
 $title .="The difference between ".$first2. " and " .$second2. 
          " is " .$subtract.".";
$op = ' checked="checked"';
     }    

if ($op == 'times') {
 
   $product = $first2 * $second2;
 
 $title .="The product of ".$first2. " and " .$second2. 
          " is " .$product.".";
     }    
if ($op == 'divide') {
 
   $quotient = $first2 / $second2;
 
 $title .="The quotient of ".$first2. " and " .$second2. 
          " is " .$quotient.".";
     }  
}  
 
    if(isset($_REQUEST['clear'])) {
      $first2 = " ";
      $second2 = " ";
      $result= " ";
   }
?>

<title>Calculator in PHP</title>
</head>
<style>
body {
     background-color: lightgreen;
font-family:arial;
font-style:bold;
font-size:22px; 
     font-family:arial;
     color:blue;
}
  
input
{
  -moz-border-radius: 15px;
    border-radius: 15px;
    border:solid 3px BLUE;
    padding:8px;
}
input {
  display: table-cell;
}

 label{
    display: table-cell;
    text-align: justify;
}
div.row{
    display:table-row;
}

/***FIRST STYLE THE BUTTON***/
button#gobutton{
cursor:pointer; /*forces the cursor to change to a hand when the button is hovered*/
padding:5px 25px; /*add some padding to the inside of the button*/
background:white; /*the colour of the button*/
border:1px solid #33842a; /*required or the default border for the browser will appear*/
/*give the button curved corners, alter the size as required*/
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
border-radius: 6px;
/*give the button a drop shadow*/
-webkit-box-shadow: 0 0 4px rgba(0,0,0, .75);
-moz-box-shadow: 0 0 4px rgba(0,0,0, .75);
box-shadow: 0 0 4px rgba(0,0,0, .75);
/*style the text*/
color:blue;
font-size:1.1em;
}
/***NOW STYLE THE BUTTON'S HOVER AND FOCUS STATES***/
button#gobutton:hover, button#gobutton:focus{
background-color :brown; /*make the background a little darker*/
/*reduce the drop shadow size to give a pushed button effect*/
-webkit-box-shadow: 0 0 1px rgba(0,0,0, .75);
-moz-box-shadow: 0 0 1px rgba(0,0,0, .75);
box-shadow: 0 0 1px rgba(0,0,0, .75);
}

 </style>

<body>

<div style='width:800px;margin:auto'>
<form>
<H2> Calculator in PHP </h2>
<div class="row"><label> FIRST VALUE 
<input type="text" id="first" name="first" placeholder="enter first value"
 value="<?php echo $first; ?>" autofocus required size=10></label></div><br>
<div class="row"> <label> SECOND VALUE
<input type="text" id="second" name="second" placeholder="enter second value"
 value="<?php echo $second; ?>" autofocus required size=10></label> </div>
<br>
<input type="radio" name="op"  value="add" <?php if($_REQUEST['op'] == "add") echo "checked"; ?>>ADDITION
<input type="radio" name="op"  value="subtract"  <?php if($_REQUEST['op'] == "subtract") echo "checked"; ?> >SUBTRACTION
<input type="radio" name="op"  value="times"  <?php if($_REQUEST['op'] == "times") echo "checked"; ?>>MULTIPLICATION
<input type="radio" name="op"  value="divide" <?php if($_REQUEST['op'] == "divide") echo "checked"; ?>>DIVISION
<br><br>
<button id="gobutton" type="submit" name="solve" id="solve" value="answer"
 title="Click here to find the result.">Solve</button>
<button id="gobutton" type="submit" name="clear" id="clear" value="answer"
title="Click here to clear text fields.">Clear</button>
</form>
<br> 
<?php
echo $title;
?>
</body> </div>
</html>



Addition of Three Numbers in Java

In this short tutorial I would like to share with you a simple program that I wrote in Java how to add three numbers. What this program will do is very simple it will ask the user to enter three integer number and then our program will find the some of the three numbers given by our user. I also added a function that will ask the user if the user want to continue run the program again by asking the user do you want to continue. I am using Textpad as my text editor for Java and java scanner library class for input and output function in our program. I hope my simple program will help you understand basic programming concepts using Java.

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

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Sample Output of Our Program


Program Listing

import java.util.Scanner;

class addition
{

  public static  int add(int a,int b, int c)
   {
  return(a+b+c);
    }

public static void main(String args[])
{
  Scanner in = new Scanner(System.in);
   char a;
do
 {

 int num1=0,num2=0,num3=0,solve_addition=0;

 System.out.print("\n");
 System.out.println("==============================================");
 System.out.println("||    <<< ADDITION OF THREE NUMBERS  >>>    ||");
 System.out.println("==============================================");
     System.out.print("\n");
     System.out.print("Enter First  Number :=> ");
          num1 = in.nextInt();
          System.out.print("Enter Second Number :=> ");
          num2 = in.nextInt();
          System.out.print("Enter First Number  :=> ");
          num3 = in.nextInt();
          int result = add(num1,num2,num3);
     System.out.println("\n");
 System.out.println("=======================");
 System.out.println("||  DISPLAY RESULT   ||");
 System.out.println("=======================");
 System.out.println("\n");
 System.out.print("The sum of " +num1 + " , " + num2 + " and "
                   + num3 + " is " + result + ".");

          System.out.println("\n\n");
          System.out.print("Do you Want To Continue (Y/N) :=> ");
           a=in.next().charAt(0);

   } while(a=='Y'|| a=='y');
          System.out.println("\n");
          System.out.println("\t ===== END OF PROGRAM ======");
         System.out.println("\n");
}
}


Tuesday, February 24, 2015

Reverse a Number Program in Java


In this tutorial I would like to share with you a simple program that I wrote in Java that will ask the user to enter a number in integer format then it will reverse the arrangement of numbers. The code is very straight forward to follow and understand it will serve as a basis for anyone that are new in Java programming.

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

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Sample Output of Our Program

Program Listing

import java.lang.*;
import java.util.Scanner;

class rev
{

public static void main(String args[])
{
  Scanner in = new Scanner(System.in);
   char a;
do
 {
    int num1=0,r=0;
    int solve_value=0;
 System.out.println("==============================================");
 System.out.println("||    <<< REVERSE A NUMBER PROGRAM >>>      ||");
 System.out.println("==============================================");
     System.out.print("\n");
     System.out.print("Enter a Number :=>");
          num1 = in.nextInt();
     System.out.println("\n");
 System.out.println("=======================");
 System.out.println("||  DISPLAY RESULT   ||");
 System.out.println("=======================");
 System.out.println("\n");
 System.out.println("Original Number Arrangement :=> " +num1 +".");
while(num1>0)
  {
r=num1%10;
solve_value=(solve_value*10)+r;
num1=num1/10;
          }
       System.out.println("Reverse of number result    :=> " +solve_value +".");
       System.out.println("\n");
       System.out.print(" Do you Want To Continue(Y/N) :=> ");
       a=in.next().charAt(0);

   } while(a=='Y'|| a=='y');
       System.out.println("\n");
       System.out.println("\t ===== END OF PROGRAM ======");
       System.out.println("\n");
}
}


Monday, February 23, 2015

Count Letters,Numbers and Spacing Program in Java

In this simple article I would like to share with you my avid reader a program that I wrote in Java as my programming language I called this program Count Letters, Numbers and Spacing Program. What this program will do is to ask the user to enter a sentence and then our program will count how many capital letters, lowercase letters, digits and spacing in our given sentence. I am using ASCII decimal values for letters, numbers and spacing in my program. I hope you will my work useful in your learning in Java programming.

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

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Sample Output of Our Program


Program Listing

import java.util.Scanner;

public class count {

    public static void main(String[] args)
      {
        char ch;
        String str;

        int uppercase=0,lowercase=0, digits=0,space=0;

        Scanner in = new Scanner(System.in);

        System.out.println("==============================================");
        System.out.println("||Count Letters,Numbers and Spacing Program ||");
        System.out.println("==============================================");
        System.out.print("\n");
System.out.print("Enter a Sentence :=>");
        str = in.nextLine();
        for(int i=0;i<str.length();i++)
        {
            ch = str.charAt(i);
            int asciivalue = (int)ch;

          if(asciivalue >=65 && asciivalue <=90){
                uppercase++;
            }
            else if(asciivalue >=97 && asciivalue <=122){
                lowercase++;
            }
            else if(asciivalue >=48 && asciivalue <= 57){
    digits++;
            }
            else if(asciivalue >=32){
    space++;
            }
        }
       System.out.println("\n\n");
       System.out.println("=======================");
       System.out.println("||  DISPLAY RESULT   ||");
       System.out.println("=======================");
       System.out.println("\n");
       System.out.println("Number of UpperCase Letter(s) : " + uppercase + ".");
       System.out.println("Number of LowerCase Letter(s) : " + lowercase + ".");
       System.out.println("Number of Digit(s)            : " + digits + ".");
       System.out.println("Number of Spacing             : " + space + ".");
       System.out.println("\n");
       System.out.println("\t ===== END OF PROGRAM ======");
       System.out.println("\n");
    }
}

Capital, Small Letters and Digits Counter in C++

In this short tutorial I would like to share with you a sample program in C++ that will ask the user to enter a sentence and then our program will count the number of occurrence of capital, small and digits in a given sentence in C++. The code is very short and easy to understand it uses while loop and one dimensional array in our program.

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

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Sample Output of Our Program

Program Listing

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;


 int main() {

   int upper = 0, lower = 0, digits=0;

   char ch[120];   int i=0;

   cout << "===========================================\n";
   cout << " Capital, Small Letters and Digits Counter";
   cout << "\n";
   cout << "===========================================\n";
   cout << "\n\n";
   cout << "Enter A Sentence :=> ";
   gets(ch);

   while (ch[i] != '\0') {

      if (ch[i] >= 'A' && ch[i] <= 'Z')
         upper++;
      if (ch[i] >= 'a' && ch[i] <= 'z')
         lower++;
      if (ch[i] >= '0' && ch[i] <= '9')
         digits++;
      i++;
   }

   cout <<"\n==============================";
   cout << "\n";
   cout << "======= Display Result ======= ";
   cout << "\n==============================";
   cout << "\n";
   cout << "\n Number of  Uppercase Letters : " << upper;
   cout << "\n Number of Lowercase Letters  : " << lower;
   cout << "\n Number of Digits             :  " << digits;
   cout << "\n\n";
  system("pause");
}

DOWNLOAD SOURCE CODE HERE


Saturday, February 21, 2015

Count Capital and Small Letters in C

In this article I would like to share with you a code that I wrote using C language what this program will do is to ask the user to type a word or a sentence and then our program will count the number of occurrence of capital and small letters from the word or sentence being type or provided by our user of our program.
If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360


Sample Output of Our Program
 
 
Program Listing
 
#include <stdio.h>

 
int main() {
   int upper = 0, lower = 0;
   char ch[80];
   int i=0;
   printf("\t Count Capital and Small Letters in C ");
   printf("\n\n");
   printf("\nEnter a sentence :=> ");
   gets(ch);

   while (ch[i] != '\0') {
        
      if (ch[i] >= 'A' && ch[i] <= 'Z')
         upper++;
      if (ch[i] >= 'a' && ch[i] <= 'z')
         lower++;
      i++;
   }

   printf("\n==============================");
   printf("\n");
   printf("======= Display Result ======= ");
   printf("\n==============================");
   printf("\n\n");
   printf("\n Number of  Uppercase Letters : %d", upper);
   printf("\n Number of Lowercase Letters : %d", lower);
   printf("\n\n");
  system("pause");
}