Thursday, April 14, 2016

Vowels, Consonants and Numbers Counter in JavaScript

A program that I wrote using JavaScript as my programming language that will ask the user to give a string or a sentence and then our program will count the number of occurrence of vowels, consonants and numbers. The code is very simple and very easy to understand.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
<head>
<title>Vowels, Consonants and Numbers Counter</title>
<style>
body {
     font-family:arial;
font-size:12;
font-weight:bold;
 }
</style>
<script type="text/javascript">
function count_all() {

var str = document.getElementById('txtname').value;

var count = 0, total_vowels="";
var count2=0, total_consonants="";
var count3=0, total_digits="";

for (var i = 0; i < str.length; i++) {
if (str.charAt(i).match(/[a-zA-Z]/) != null) {

if (str.charAt(i).match(/[aeiouAEIOU]/))
{
total_vowels = total_vowels + str.charAt(i);
count++;
}

if (str.charAt(i).match(/[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]/))
{
total_consonants = total_consonants + str.charAt(i);
count2++;
}


}

function retnum(str1) { 
    var num = str1.replace(/[^0-9]/g, ''); 
    return num; 
}

function count_digits(str2) {
  var num2 = str2.replace(/[^0-9]/g,"").length;
  return num2;
}
}
document.getElementById('consonant_counts').value =  count2;
document.getElementById('total_consonants').value = total_consonants;
document.getElementById('vowels').value = total_vowels;
document.getElementById('vcount').value = count;
document.getElementById('digits1').value = count_digits(str);
document.getElementById('digits2').value = retnum(str);
}

function clear_all()
{
document.getElementById('consonant_counts').value ="";
document.getElementById('total_consonants').value ="";
document.getElementById('vowels').value = "";
document.getElementById('vcount').value = "";
document.getElementById('digits1').value ="";
document.getElementById('digits2').value ="";
document.getElementById('txtname').value ="";
document.getElementById('txtname').focus();
}
</script>
</head>
<body>
<br><br>
<div >
<table border="0" cellspacing="0" width="40%" style="background-color:lightgreen; color:blue">
<tr><td colspan="2" align="center"><b>Vowels, Consonants and Numbers Counter</b></td></tr>
<tr> <td>&nbsp;</td></tr>
<tr>
<td>Enter a String </td>
<td><input type='text' id='txtname' size="30" autofocus/></td>
</tr>
<tr> <td>&nbsp;</td></tr>
<tr>
<td>No. of Consonants </td>
<td><input type='text' readonly="readonly" id='consonant_counts'  size="30"/></td>
</tr>
<tr>
<td>List of Consonant(s) </td>
<td><input type='text' readonly="readonly" id='total_consonants'  size="30"/></td>
</tr>
<tr>
<td>No. of Vowels </td>
<td><input type='text' readonly="readonly" id='vcount'  size="30"/></td>
</tr>
<tr>
<td>List of Vowel(s) </td>
<td><input type='text' readonly="readonly" id='vowels'  size="30"/></td>
</tr>
<tr>
<td>No. of Digits </td>
<td><input type='text' readonly="readonly" id='digits1'  size="30"/></td>
</tr>
<td>List of Digit(s) </td>
<td><input type='text' readonly="readonly" id='digits2'  size="30"/></td>
</tr>
<tr> <td>&nbsp;</td></tr>
<tr>
<td></td>
<td><input type='button' value='Ok' title="Click here to process." 
onclick="javascript:count_all();" />
&nbsp;&nbsp;&nbsp;
<input type='button' value='Clear' title="Click here to clear all the text fields."
onclick="javascript:clear_all();" /></td>
</tr>
</table>
</div>
</body>
</html>



Wednesday, April 13, 2016

Factorial Solver in Visual Basic .NET

A factorial program that I wrote using Microsoft Visual Basic .NET to solve for the factorial of the number. The code is very easy to understand I create a function called factorial which uses recursion algorithm to solve the factorial of the given number by our user.

 Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label2.Visible = False
    End Sub
    Private Function Factorial(ByVal inputval As Integer) As Integer
        Dim f As Integer
        Factorial = 1

        For f = 2 To inputval
            Factorial = Factorial * f
        Next
    End Function


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label2.Visible = True
        Dim myNumber1, mynumber2 As Integer
        myNumber1 = Val(TextBox1.Text)
        mynumber2 = Factorial(Val(TextBox1.Text))
        Label2.Text = "The factorial value of " & myNumber1 & _
                      " is " & mynumber2 & "."

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Label2.Visible = False
        TextBox1.Text = ""
        Label2.Text = ""
        Label2.Text = ""
        TextBox1.Focus()

    End Sub
End Class




Odd and Even Number Checker in Visual Basic NET

Here is a simple program that I wrote using Microsoft Visual Studio 2012 and my language is Visual Basic NET to check if the given number of the user is an odd or even number using the operator MOD. I also include error detection if text field is empty and then the user click the ok button our program will display a message informing the user that the text field needs a value.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.





Sample Program Output

Program Listing


Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label2.Visible = False
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim myNumber As Long
        myNumber = Val(TextBox1.Text)
        Label2.Visible = False


        If myNumber = 0 Then
            MessageBox.Show("Sorry can't be empty.")
            Label2.Visible = False
            Label2.Text = ""

            TextBox1.Focus()
        ElseIf myNumber Mod 2 Then
            Label2.Visible = True
            Label2.Text = "You've entered an odd number."
        Else
        Label2.Visible = True
        Label2.Text = "You've entered an even number."
        End If

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Label2.Visible = False
        TextBox1.Text = ""
        Label2.Text = ""
        Label2.Text = ""
        TextBox1.Focus()

    End Sub
End Class



Sunday, April 10, 2016

Pounds To Kilograms Converter in Visual Basic.NET

A program that I wrote in Visual Basic.NET that will ask the user to give a value in Pounds and then it will convert it into Kilograms equivalent.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label3.Visible = False
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label3.Visible = True

        Dim Kilograms As Decimal

        Dim Pounds As Decimal

        Pounds = Val(TextBox1.Text)

        Kilograms = (Pounds * 0.45359237)

        Label3.Text = Pounds & " Lbs(s) is equivalent to " & Math.Round(Kilograms, 2) & " Kg(s)"

    End Sub

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





Kilograms to Pounds Converter in Visual Basic.NET

A simple program in Visual Basic.NET that will ask the user to give the weight in kilograms and then it will convert it into Pounds equivalent.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label3.Visible = False
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label3.Visible = True

        Dim Kilograms As Decimal

        Dim Pounds As Decimal

        Kilograms = Val(TextBox1.Text)

        Pounds = (Kilograms * 2.20462262)

        Label3.Text = Kilograms & " Kg(s) is equivalent to " & Math.Round(Pounds, 2) & " Lbs(s)"


    End Sub

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



Miles To Kilometers Converter in Visual Basic.NET

A very simple program that I wrote in Visual Basic.NET that will ask the user to give the distance in Miles and then our program will convert the given distance by the user in Miles to Kilometers.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label3.Visible = False
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label3.Visible = True

        Dim Miles As Decimal

        Dim Kilometers As Decimal

        Miles = Val(TextBox1.Text)

        Kilometers = (Miles * 1.609344)

        Label3.Text = Miles & " Mile(s) is equivalent to " & Math.Round(Kilometers, 2) & " Kilometer(s)"


    End Sub

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




Fahrenheit To Celsius Converter in Visual Basic.NET Version 2

Here is the second version of my program that I wrote before in Visual Basic.NET Fahrenheit to Celsius Converter in Visual Basic.NET the code is very simple and easy to understand.


Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing


Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label3.Visible = False
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Label3.Visible = True

        Dim F As Decimal

        Dim C As Decimal

        C = Val(TextBox1.Text)

        F = C * 1.8 + 32
        Label3.Text = "The temperature in Celsius is " & F & Chr(176) & "C"

    End Sub

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

Addition of Two Numbers in Visual Basic.NET

A simple program that I wrote using Visual Basic.NET to add the sum of two numbers. I'm just learning Visual Basic.NET primarily because my experience before in programming in using Visual Basic 6 it is a good learning experience on my part.


Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.





Sample Program Output




Program Listing


Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim sum As Integer
        Dim a As Integer
        Dim b As Integer

        Label4.Visible = True

        If TextBox1.Text = "" Then
            Label4.Visible = False
            MessageBox.Show("Sorry cannot be empty.")
            TextBox1.Focus()
        End If

        a = Val(TextBox1.Text)
        b = Val(TextBox2.Text)
        sum = (a + b)

        Label4.Text = "The sum of " & a & " and " & b & " is " & sum & "."

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label4.Visible = False


    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        Label4.Text = ""

        TextBox1.Focus()
    End Sub
End Class






Saturday, April 9, 2016

Switch and Boolean Statement in C++

Here is a sample program that I wrote a long time ago that demonstrate the use of switch and Boolean statements in C++ language that will check if the age of the person is still a minor or adult already.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


Program Listing


#include <iostream>

using namespace std;

main()
{
      int a=0;
      
      cout << "Enter a your age : ";
      cin >> a;
      
      switch(a >= 18 ? true : false)
      {
               case true : cout << "Your are Adult.";
                                break;
               case false  : cout << "Sorry you are still Minor.";
         }
      cout << "\n\n";
      system("pause");
      }
      




Postfix To Prefix in Converter in C

A simple program that will convert a given expression by the user in postfix and then it will convert it into prefix equivalent in C programming language.


Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Program Listing



#include <stdio.h>
#include <conio.h>
#include <string.h>

#define MAX 100

struct postfix
{
char stack[MAX][MAX], target[MAX] ;
char temp1[2], temp2[2] ;
char str1[MAX], str2[MAX], str3[MAX] ;
int i, top ;
} ;

void initpostfix ( struct postfix * ) ;
void setexpr ( struct postfix *, char * ) ;
void push ( struct postfix *, char * ) ;
void pop ( struct postfix *, char * ) ;
void convert ( struct postfix * ) ;
void show ( struct postfix ) ;

void main( )
{
struct postfix q ;
char expr[MAX] ;

clrscr( ) ;

initpostfix ( &q ) ;
     
        printf ( "\n POSTFIX TO PREFIX CONVERTER IN C " ) ;
        printf("\n\n");
printf ( "\nEnter an expression in postfix form: " ) ;
gets ( expr ) ;

setexpr ( &q, expr ) ;
convert ( &q ) ;

printf ( "\nThe Prefix expression is: " ) ;
show ( q ) ;

getch( ) ;
}


void initpostfix ( struct postfix *p )
{
p -> i = 0 ;
p -> top = -1 ;
strcpy ( p -> target, "" ) ;
}


void setexpr ( struct postfix *p, char *c )
{
strcpy ( p -> target, c ) ;
}


void push ( struct postfix *p, char *str )
{
if ( p -> top == MAX - 1 )
printf ( "\nStack is full." ) ;
else
{
p -> top++ ;
strcpy ( p -> stack[p -> top], str ) ;
}
}

void pop ( struct postfix *p, char *a )
{
if ( p -> top == -1 )
printf ( "\nStack  is empty." ) ;
else
{
strcpy ( a, p -> stack[p -> top] ) ;
p -> top-- ;
}
}


void convert ( struct postfix *p )
{
while ( p -> target[p -> i] != '\0' )
{
/* skip whitespace, if any */
if ( p -> target[p -> i] == ' ')
p -> i++ ;
if( p -> target[p -> i] == '%' || p -> target[p -> i] == '*' ||
p -> target[p -> i] == '-' || p -> target[p -> i] == '+' ||
p -> target[p -> i] == '/' || p -> target[p -> i] == '$' )
{
pop ( p, p -> str2 ) ;
pop ( p, p -> str3 ) ;
p -> temp1[0] = p -> target[ p -> i] ;
p -> temp1[1] = '\0' ;
strcpy ( p -> str1, p -> temp1 ) ;
strcat ( p -> str1, p -> str3 ) ;
strcat ( p -> str1, p -> str2 ) ;
push ( p, p -> str1 ) ;
}
else
{
p -> temp1[0] = p -> target[p -> i] ;
p -> temp1[1] = '\0' ;
strcpy ( p -> temp2, p -> temp1 ) ;
push ( p, p -> temp2 ) ;
}
p -> i++ ;
}
}


void show ( struct postfix p )
{
char *temp = p.stack[0] ;
while ( *temp )
{
printf ( "%c ", *temp ) ;
temp++ ;
}

}

Descending Numbers in C

Here is a sample program that I wrote a very long time a ago in C language that will ask a series of numbers and then it will sort the given numbers into descending order.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Program Listing

#include <stdio.h>
#include <conio.h>

int main()
{
     int arr[100],i,j,element,no,temp;
     clrscr();
     printf("\nEnter the no of Elements: ");
     scanf("%d", &no);
     for(i=0;i<no;i++){
          printf("\n Enter Element %d: ", i+1);
          scanf("%d",&arr[i]);
     }
     for(i=0;i<no;i++){
          for(j=i;j<no;j++){
               if(arr[i] < arr[j]){
               temp=arr[i];
               arr[i]=arr[j];
               arr[j]=temp;
               }
           }
     }
     printf("\nSorted array:");
     for(i=0;i<no;i++){
          printf("\t%d",arr[i]);
     }
     getch();
}