Saturday, April 21, 2018

Array as Stack in C


A simple program how to implement the concept of array as stack using C language.


I am currently accepting programming work, it project, school programming projects , thesis and capstone projects, IT consulting work and web development work kindly contact me in the following email address for further details. Thank you.

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

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Program Listing

array.c

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

#define MAX 10

struct stack
{
int arr[MAX] ;
int top ;
} ;

void initstack ( struct stack * ) ;
void push ( struct stack *, int item ) ;
int pop ( struct stack * ) ;

void main( )
{
struct stack s ;
int i ;

clrscr( ) ;

initstack ( &s ) ;

push ( &s, 11 ) ;
push ( &s, 23 ) ;
push ( &s, -8 ) ;
push ( &s, 16 ) ;
push ( &s, 27 ) ;
push ( &s, 14 ) ;
push ( &s, 20 ) ;
push ( &s, 39 ) ;
push ( &s, 2 ) ;
push ( &s, 15 ) ;
push ( &s, 7 ) ;

i = pop ( &s ) ;
printf ( "\n\nItem popped: %d", i ) ;

i = pop ( &s ) ;
printf ( "\nItem popped: %d", i ) ;

i = pop ( &s ) ;
printf ( "\nItem popped: %d", i ) ;

i = pop ( &s ) ;
printf ( "\nItem popped: %d", i ) ;

i = pop ( &s ) ;
printf ( "\nItem popped: %d", i ) ;

getch( ) ;
}

/* intializes the stack */
void initstack ( struct stack *s )
{
s -> top = -1 ;
}

/* adds an element to the stack */
void push ( struct stack *s, int item )
{
if ( s -> top == MAX - 1 )
{
printf ( "\nStack is full." ) ;
return ;
}
s -> top++ ;
s -> arr[s ->top] = item ;
}

/* removes an element from the stack */
int pop ( struct stack *s )
{
int data ;
if ( s -> top == -1 )
{
printf ( "\nStack is empty." ) ;
return NULL ;
}
data = s -> arr[s -> top] ;
s -> top-- ;
return data ;
}

Postfix To Infix Conversion in C

In  this article I would like to share with you a sample program written in C to convert postfix to infix format.

I am currently accepting programming work, it project, school programming projects , thesis and capstone projects, IT consulting work and web development work kindly contact me in the following email address for further details. Thank you.

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

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.


Program Listing

postfix.c


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

#define MAX 50

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 ( "\nEnter an expression in postfix form: " ) ;
gets ( expr ) ;

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

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

getch( ) ;
}

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

/* copies given expression to target string */
void setexpr ( struct postfix *p, char *c )
{
strcpy ( p -> target, c ) ;
}

/* adds an expr. to the stack */
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 ) ;
}
}

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

/* converts given expr. to infix form */
void convert ( struct postfix *p )
{
while ( p -> target[p -> i] )
{
/* 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 -> str3 ) ;
strcat ( p -> str1, p -> temp1 ) ;
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++ ;
}
}

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

Infix To Postfix Conversion in C

Here is a program that will convert value in infix format into it's postfix format written in C language.

I am currently accepting programming work, it project, school programming projects , thesis and capstone projects, IT consulting work and web development work kindly contact me in the following email address for further details. Thank you.

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

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Program Listing

convert.c

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

#define MAX 50

struct infix
{
char target[MAX] ;
char stack[MAX] ;
char *s, *t ;
int top ;
} ;

void initinfix ( struct infix * ) ;
void setexpr ( struct infix *, char * ) ;
void push ( struct infix *, char ) ;
char pop ( struct infix * ) ;
void convert ( struct infix * ) ;
int priority ( char ) ;
void show ( struct infix ) ;

void main( )
{
    struct infix p ;
char expr[MAX] ;

    initinfix ( &p ) ;

    clrscr( ) ;

    printf ( "\nEnter an expression in infix form: " ) ;
gets ( expr ) ;

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

printf ( "\nThe postfix expression is: " ) ;
show ( p ) ;

    getch( ) ;
}

/* initializes structure elements */
void initinfix ( struct infix *p )
{
p -> top = -1 ;
strcpy ( p -> target, "" ) ;
strcpy ( p -> stack, "" ) ;
p -> t = p -> target ;
p -> s = ""  ;
}

/* sets s to point to given expr. */
void setexpr ( struct infix *p, char *str )
{
p -> s = str ;
}

/* adds an operator to the stack */
void push ( struct infix *p, char c )
{
if ( p -> top == MAX )
printf ( "\nStack is full.\n" ) ;
else
{
p -> top++ ;
p -> stack[p -> top] = c ;
}
}

/* pops an operator from the stack */
char pop ( struct infix *p )
{
if ( p -> top == -1 )
{
printf ( "\nStack is empty.\n" ) ;
return -1 ;
}
else
{
char item = p -> stack[p -> top] ;
p -> top-- ;
return item ;
}
}

/* converts the given expr. from infix to postfix form */
void convert ( struct infix *p )
{
    char opr ;

while ( *( p -> s ) )
{
if ( *( p -> s ) == ' ' || *( p -> s ) == '\t' )
{
p -> s++ ;
continue ;
}
if ( isdigit ( *( p -> s ) ) || isalpha ( *( p -> s ) ) )
{
while ( isdigit ( *( p -> s ) ) || isalpha ( *( p -> s ) ) )
{
*( p -> t ) = *( p -> s ) ;
p -> s++ ;
p -> t++ ;
}
}
if ( *( p -> s ) == '(' )
{
push ( p, *( p -> s ) ) ;
p -> s++ ;
}

if ( *( p -> s ) == '*' || *( p -> s ) == '+' || *( p -> s ) == '/' || *( p -> s ) == '%' || *( p -> s ) == '-' || *( p -> s ) == '$' )
{
if ( p -> top != -1 )
{
opr = pop ( p ) ;
while ( priority ( opr ) >= priority ( *( p -> s ) ) )
{
*( p -> t ) = opr ;
p -> t++ ;
opr = pop ( p ) ;
}
push ( p, opr ) ;
push ( p, *( p -> s ) ) ;
}
else
push ( p, *( p -> s ) ) ;
p -> s++ ;
}

if ( *( p -> s ) == ')' )
{
opr = pop ( p ) ;
while ( ( opr ) != '(' )
{
*( p -> t ) = opr ;
p -> t++ ;
opr =  pop ( p ) ;
}
p -> s++ ;
}
}

while ( p -> top != -1 )
{
char opr = pop ( p ) ;
*( p -> t ) = opr ;
p -> t++ ;
}

*( p -> t ) = '\0' ;
}

/* returns the priority of an operator */
int priority ( char c )
{
if ( c == '$' )
return 3 ;
if ( c == '*' || c == '/' || c == '%' )
return 2 ;
else
{
if ( c == '+' || c == '-' )
return 1 ;
else
return 0 ;
}
}

/* displays the postfix form of given expr. */
void show ( struct infix p )
{
    printf ( " %s", p.target ) ;
}

Saturday, April 14, 2018

Total Salary Computation in JQuery

Here is a simple program that I wrote using JQuery to compute the total salary of the employee's in the company. The code is very easy to understand and use.

I am currently accepting programming work, it project, school programming projects , thesis and capstone projects, IT consulting work and web development work kindly contact me in the following email address for further details. Thank you.

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

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.




Sample Program Output


Program Listing

index.htm

<html>
<head>
<title>Total Salary Computation in JQuery</title>
</head>
<body>
 <style type="text/css">
 
  body {
  font-family: arial;
  size:15px;
  font-weight: bold;
  background-color: lightgreen;
  }
 </style>
 <br>
 <h2> Total Salary Computation in JQuery </h2>
<table cellpadding="5">
<tr>
<td><b>Employee Name</b></td> 
<td><b>Salary</b></td>
</tr>
<tr><td></td> </tr>
<tr>
<td>Allie Pomperada</td>
<td><input type='text' class='salary' /></td>
</tr>
<tr>
<td>Jake Pomperada</td>
<td><input type='text' class='salary' /></td>
</tr>
<tr>
<td>Jacob Samuel Pomperada</td>
<td><input type='text' class='salary' /></td>
</tr>
<tr>
<td>Julianna Rae Pomperada</td>
<td><input type='text' class='salary' /></td>
</tr>

<tr>
<td>Total Salary PHP</td>
<td><input type='text' id='totalSalary' disabled/></td>
</tr>
</table>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js "></script>

<script>
$('.salary').keyup(function () {
    var sum = 0;
    $('.salary').each(function() {
        sum += Number($(this).val());
    });
$('#totalSalary').val(sum.toFixed(2));
});
</script>

</body>
</html>





Friday, April 13, 2018

Sum and Project of Two Numbers Using JQuery

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 automatically compute the sum and product of the two numbers using JQuery.

I am currently accepting programming work, it project, school programming projects , thesis and capstone projects, IT consulting work and web development work kindly contact me in the following email address for further details. Thank you.

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

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.



Sample Program Output




Program Listing

index.htm

<html>
<head>
<title>JQuery Sum & Product of Two Numbers</title>
</head>
<body>
<form name="form">
<table>
<tr>
<td>Number 1:</td>
<td><input type="text" name="num1" id="num1" /></td>
</tr>
<tr>
<td>Number 2:</td>
<td><input type="text" name="num2" id="num2" /></td>
</tr>
<tr>
<td>Sum:</td>
<td><input type="text" name="sum" id="sum" readonly /></td>
</tr>
<tr>
<td>Product:</td>
<td><input type="text" name="subt" id="subt" readonly /></td>
</tr>
</table>
</form>

<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
<script>
$(function() {
    $("#num1, #num2").on("keydown keyup", sum);
function sum() {
$("#sum").val(Number($("#num1").val()) + Number($("#num2").val()));
$("#subt").val(Number($("#num1").val()) * Number($("#num2").val()));
}
});
</script>
</body>
</html>

Display All Record in Java JDBC and MySQL

Here is a code that I wrote using Java and MySQL to display all the records from the database.

I am currently accepting programming work, it project, school programming projects , thesis and capstone projects, IT consulting work and web development work kindly contact me in the following email address for further details. Thank you.

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

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.


Program Listing

DisplayRecords.java

package jdbcdemo;

import java.sql.*;

/**
 * NetBeans IDE 8.2
 * @author Mr. Jake R. Pomperada
 * March 27, 2018  Tuesday
 * Bacolod City, Negros Occidental
 */

public class DisplayRecords {

    static Connection conn;

    static {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            String url = "jdbc:mysql://localhost:3306/persons";
            conn = DriverManager.getConnection(url, "root", "");
        } catch (Exception e) {
            e.printStackTrace();;
        }
    }
    public static void main(String[] args)throws Exception  {
      
     
      try {

          // calling the method selectRecords() to display  
          // all the records from MySQL in our screen.
          selectRecords();           
        
           closeConnection();
        }  catch (SQLException ex) {
            ex.printStackTrace();
        }
     
   
    }
    
 static void closeConnection() {
        try {
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

  private static void selectRecords() 
          throws Exception {
       String selectrecordSQL = "SELECT * FROM users"; 
         
     PreparedStatement statement = conn.prepareStatement(selectrecordSQL);
     
     ResultSet result = statement.executeQuery(selectrecordSQL);
        
         if (result.next()) {
                ResultSetMetaData metaData = result.getMetaData();
                int numberOfColumns = metaData.getColumnCount();
                 System.out.println();
                 System.out.println("\t\t\t ===== LIST OF USER RECORDS =====");
                 System.out.println();
                 System.out.println("\t\t    Created By: Mr. Jake R. Pomperada, MAED-IT");
                 System.out.println();

                for (int i = 1; i <= numberOfColumns; i++) {
                    System.out.printf("%-15s", metaData.getColumnName(i));
                }
                System.out.println();

                do {
                    for (int i = 1; i <= numberOfColumns; i++) {
                        System.out.printf("%-15s", result.getObject(i));
                    }
                    System.out.println();
                } while (result.next());
                
                System.out.println();

            } else {
                System.out.println("No database records found.");
            }

         
    }

}