Friday, March 17, 2017

Sum and Product of Two Numbers in Turbo Pascal

In this article I would like to share with you a sample program that will ask the user to give two numbers and then our program will compute the sum and product of the two given numbers using Turbo Pascal for Windows as our compiler. The code uses function to return the computed value. I hope you will find my work useful. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.







Sample Program Output



Program Listing

Program Square_Number;
Uses WinCrt;

var val_1,val_2, add,multiply  : integer;

Function sum(a,b : integer) : integer;
Begin
   sum := (a+b);
End;

Function product(a,b : integer) : integer;
Begin
   product := (a*b);
End;

Begin
clrscr;
 writeln('SUM AND PRODUCT OF TWO NUMBERS IN PASCAL');
 writeln;
 Write('Enter First Number : ');
 Readln(val_1);

 Write('Enter Second Number : ');
 Readln(val_2);
   
 add := sum(val_1,val_2);

 multiply := product(val_1,val_2);
  
 writeln;
 write('The sum of ',val_1, ' and ' ,val_2, ' is ' ,add,'.');
 writeln;
 write('The product of ',val_1, ' and ' ,val_2, ' is ' ,multiply,'.');
 writeln;
 writeln;
 writeln('  END OF PROGRAM  ');
readln;
End.




Square a Number in Turbo Pascal

Here in this article I would like to share with you a sample program that I wrote using Turbo Pascal for Windows to ask the user to give a number and then our program will compute the square value being provided by our user. The program uses functions in Pascal to square the number by the user given.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing


Program Square_Number;
Uses WinCrt;

var val, solve  : integer;

Function square(a : integer) : integer;
Begin
   Square := (a*a);
End;


Begin
clrscr;
 writeln('SQUARE A NUMBER IN PASCAL');
 writeln;
 Write('Give a Number : ');
 Readln(val);

 solve := square(val);

 writeln;
 write('The Square value of ' ,val, ' is ' ,solve,'.');
 writeln;
 writeln;
 writeln('  END OF PROGRAM  ');
readln;
End.



Sunday, March 12, 2017

Square and Cube Number in C

In this article I would like to share with you a program that uses for loop statement in  C to generate square and cube number values in C. The code is very simple and easy to understand. I am using CodeBlocks as my text editor and Dev C++ as my C and C++ compiler.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing


#include <stdio.h>

int num_value=0;

int main()

{
    printf("\t  SQUARE AND CUBE NUMBER IN C");
    printf("\n\n");
    printf("NUMBER     SQUARE      CUBE\n");
    printf("======     ======      ===== ");
    printf("\n\n");
     for (num_value=1; num_value<=12; num_value++)
     {
         printf("%3d       %4d       %6d\n",num_value,num_value*num_value,num_value*num_value*num_value);
     }
    printf("\n\n");
    printf("\t End of Program ");
    printf("\n\n");
}

Initializer Outside the For Statement in C

In this article I would like to share with you a sample program that will display a series of even numbers using for loop statement in C. The difference in this program is that the initializer is outside the for loop statement in C. The code is very short and easy to understand.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.


My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing


#include <stdio.h>

int main()
{
    int counter=0;
    counter = 2;

    printf("\tInitializer Outside the For Statement in C");
    printf("\n\n");
    for( ; counter <=40; counter = counter +2)
    {
        printf(" %d ",counter);
    }
    printf("\n\n");
    printf("\t End of Program ");
    printf("\n\n");
}




Saturday, March 11, 2017

Addition of Three Numbers in PHP and AJAX

Hi there here is a sample program that will ask the user to give three numbers and then our program will compute the total sum of the three numbers using PHP and AJAX. The code is very simple and easy to understand.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.








Sample Program Output



Program Listing


index.php



<html>
<head>
<title> Addition of Three Number Using PHP and AJAX </title>
</head>
<script language="javascript" src="ajax.js">
</script>
<body>
<style>
body {
background-color:lightgreen;
font-family:arial;
font:12px;
}
</style>
<br>
<h3> Addition of Three Numbers Using PHP and AJAX</h3>
<script>
function clear_all()
{    
   document.getElementById("num1").value= "";
   document.getElementById("num2").value= "";
   document.getElementById("num3").value= "";
}

</script>
<form action="javascript:add(document.getElementById('frm'));" name="frm" id="frm">
<table>
<tr>
<td>First Value</td>
<td>&nbsp;&nbsp;&nbsp;<input id="num1" type="text" autofocus required/></td>
</tr>
<tr>
<td>Second Value</td>
<td>&nbsp;&nbsp;&nbsp;<input id="num2" type="text" required/></td>
</tr>
<tr>
<td>Third Value</td>
<td>&nbsp;&nbsp;&nbsp;<input id="num3" type="text" required/></td>
</tr>
<tr>
<td colspan="2">
<br>
<input type="submit" name="button" value="Solve">
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
<input type="submit" name="button" value="Clear" onClick="clear_all();">
</td>
</tr>
</table>
</form>
<div name="txt" id="txt"></div>
</body>
</html> 


ajax.js


function add(obj)
{

var XMLHttpRequestObject=false;
if(window.XMLHttpRequest)
{
XMLHttpRequestObject=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
XMLHttpRequestObject=new ActiveXObject("Microsoft.XMLHTTP");
}

var str1="&num1=" + document.getElementById("num1").value;
var str2="&num2=" + document.getElementById("num2").value;
var str3="&num3=" +document.getElementById("num3").value;

XMLHttpRequestObject.onreadystatechange = show;
XMLHttpRequestObject.open('POST', 'value.php', true);
XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

XMLHttpRequestObject.send(str1+str2+str3);

function show()
{
if (XMLHttpRequestObject.readyState == 4)
{
if (XMLHttpRequestObject.status == 200)
{
result = XMLHttpRequestObject.responseText;
document.getElementById('txt').innerHTML = result;
}
}
}



value.php

<?php
error_reporting(0);
$num1=$_POST['num1'];
$num2=$_POST['num2'];
$num3=$_POST['num3'];
$sum=$num1+$num2+$num3;
echo "The total sum of $num1, $num2 and $num3 is $sum.";
?>







Product of Two Numbers in PHP and AJAX

Hi there in this article I would like to share with you how to you AJAX and PHP together to accept two numbers from the user and then our program will compute the product of the two numbers. The code is written in PHP, JavaScript and AJAX. It is very simple to understand and follow. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.








Sample Program Output


Program Listing

index.php

<html>
<head>
<title> Product of Two Numbers Using PHP and AJAX </title>
</head>
<script language="javascript" src="ajax.js">
</script>
<body>
<style>
body {
background-color:lightgreen;
font-family:arial;
font:12px;
}
</style>
<br>
<h3> Product of Two Numbers Using PHP and AJAX</h3>
<script>
function clear_all()
{    
   document.getElementById("num1").value= "";
   document.getElementById("num2").value= "";
}
</script>
<form action="javascript:product(document.getElementById('frm'));" name="frm" id="frm">
<table>
<tr>
<td>First Value</td>
<td>&nbsp;&nbsp;&nbsp;<input id="num1" type="text" autofocus required/></td>
</tr>
<tr>
<td>Second Value</td>
<td>&nbsp;&nbsp;&nbsp;<input id="num2" type="text" required/></td>
</tr>
<tr>
<td colspan="2">
<br>
<input type="submit" name="button" value="Solve">
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
<input type="submit" name="button" value="Clear" onClick="clear_all();">
</td>
</tr>
</table>
</form>
<div name="txt" id="txt"></div>
</body>
</html> 

ajax.js


function product(obj)
{

var XMLHttpRequestObject=false;
if(window.XMLHttpRequest)
{
XMLHttpRequestObject=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
XMLHttpRequestObject=new ActiveXObject("Microsoft.XMLHTTP");
}

var str1= "num1=" + document.getElementById("num1").value;
var str2="&num2=" +document.getElementById("num2").value;

XMLHttpRequestObject.onreadystatechange = show;
XMLHttpRequestObject.open('POST', 'value.php', true);
XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

XMLHttpRequestObject.send(str1+str2);

function show()
{
if (XMLHttpRequestObject.readyState == 4)
{
if (XMLHttpRequestObject.status == 200)
{
result = XMLHttpRequestObject.responseText;
document.getElementById('txt').innerHTML = result;
}
}
}



value.php

<?php
$num1=$_POST['num1'];
$num2=$_POST['num2'];
$num3=$num1*$num2;
echo "The product of $num1 and $num2 is $num3.";
?>


Wednesday, March 8, 2017

Square Root Solver in Visual Basic 6

Hi here is a sample program that will ask the user to give a number in integer and then our program will solve for it's square root equivalent of the given number by the user. The code is very short and easy to understand for beginners that are very new in Visual Basic 6 programming. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.






Sample  Program Output


Program Listing


Function Square_Root_Solver(b As Integer)
Dim num As Integer
num = b
num = num ^ (1 / 2)
Label2.Caption = "The square root value of " & b & _
" is " & num & "."
End Function


Private Sub Command1_Click()
Dim a As Integer

a = Val(Text1.Text)

Call Square_Root_Solver(a)

End Sub

Private Sub Command2_Click()
Label2.Caption = ""
Text1.Text = ""
Text1.SetFocus
End Sub


Square a Number in Visual Basic 6

Hi there in this article I would like to share with you a sample program that will ask you to give a number and then it will compute the square value of the given number the code is very simple and easy to understand.  I hope it will help you understand how to use visual basic 6.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.







Sample Program Output


Program Listing


Private Sub Command1_Click()
Dim a As Integer

a = Val(Text1.Text)
square = a * a

Label2.Caption = "The square value of " & a & _
" is " & square & "."

End Sub

Private Sub Command2_Click()
Label2.Caption = ""
Text1.Text = ""
Text1.SetFocus
End Sub




Sunday, March 5, 2017

Arrays and Pointers in C++

Hi there here is a sample program that shows you how to use one dimensional array and pointers in C++ this code I used it before in my programming class in C++ in college. The code is very short and easy to understand. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Program Listing


#include <iostream>

using namespace std;

int add(int &a,int &b, int &c, int &d)
{
    return(a+b+c+d);
}

main() {
    int val[4];
    val[0] = 2;
    val[1] = 4;
    val[2] = 6;
    val[3] = 8;

    cout << "The sum of "
       << val[0] <<  ","
      << val[1] <<  ","
      << val[2] <<  ","
      << val[3] <<  " is "
      << add(val[0],val[1],val[2],val[3])
      << ".";
      cout << "\n\n";
      system("pause");
}


Palindrome Checker in Visual Basic NET

Here is another simple program that I wrote using Visual Basic NET to ask the user to give a string and then our program will check and determine if the given string is a Palindrome or Not a Palindrome. The code is very simple and easy to understand. I hope you will learn from this one. Thank  you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing


Public Class Form1

    Public Function StrPalindrome(ByVal sSource As String) As String
        Dim s1 As String
        Dim s2 As String
        s1 = TextBox1.Text
        s2 = StrReverse(s1)
        If (s1 = s2) Then
            MessageBox.Show("The give word " & UCase(TextBox1.Text) & " is a Palindrome.")
        Else
            MessageBox.Show("The give word " & UCase(TextBox1.Text) & " is Not a Palindrome.")
        End If
    End Function


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        End
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim str_word As String

        str_word = StrPalindrome(TextBox1.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        TextBox1.Focus()
    End Sub
End Class



Palindrome Checker in Visual Basic 6

Here is another simple program that I wrote using Visual Basic 6 to ask the user to give a string and then our program will check and determine if the given string is a Palindrome or Not a Palindrome. The code is very simple and easy to understand. I hope you will learn from this one. Thank  you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

Private Sub Command1_Click()
Dim str_word As String

str_word = StrPalindrome(Form1.Text1.Text)
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
Form1.Show
End Sub
Public Function StrPalindrome(ByVal sSource As String) As String
    Dim l As Long, strRev As String
    Dim ab() As Byte
    ab = StrConv(sSource, vbFromUnicode)
    For l = UBound(ab) To 0 Step -1
        strRev = strRev & Chr$(ab(l))
    Next l
    If strRev = sSource Then
        MsgBox "The give word " & UCase(Text1.Text) & " is a Palindrome."
    Else
         MsgBox "The give word " & UCase(Text1.Text) & " is Not a Palindrome."
    End If
End Function