Sunday, May 22, 2016

Sum of Digits in JavaScript

A simple program that I wrote using JavaScript as my programming language that will ask the user to give a number and then our program will add the sum of digits in a given number by our user. The code is very 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

<!DOCTYPE html>  
<html>   
<head>  
<meta charset=utf-8 />  
<title>Sum of Digits in JavaScript</title>  
<style type="text/css">  
body {
    font-family:arial;
font-size:12;
font-weight:bold;
    background-color:lightgreen;
margin: 30px;
}
</style>   
</head>  
<body>  
<script>

function Sum_of_Digits() {

 var number = document.getElementById("number1").value;
            
  var str = number.toString();
  var sum = 0;

  for (var i = 0; i < str.length; i++) {
    sum += parseInt(str.charAt(i), 10);
  }
document.getElementById("result").innerHTML = sum;

}

</script>
<hr>
<h2>Sum of Digits in JavaScript </h2>
 <hr>

<form>  
Enter a number <input type="text" id="number1"  maxlength="10" size="10"><br>  
<br>
<input type="button" onClick="Sum_of_Digits()" Value="Ok" 
title="Click here to find the total sum of digits of a number." />  &nbsp;
</form>  <br>
<p>The total sum of digits is : 
<span id = "result"></span>  
</p>  
</body>  
</html>  


Sum of Digits in Python

A simple program that I wrote using Python as my programming language that will ask the user to give a number and then our program will add the sum of digits in a given number by our user. The code is very 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

def sum_digits(num):
  result = 0
  base = 10
  pos = 10
  while pos <= num*base:
    prev = pos/base
    result = result + int( (num % pos)/ prev)
    pos = pos*base
  return result

def my_program():
   print()
   print("SUM OF DIGITS IN PYTHON")
   print()
   number = int(input("Enter a Number : "))
   print()
   solve_me = sum_digits(number)
   print("The total sum of digits is " , solve_me, ".")
   print("\n");
   repeat = input('Do you want to continue ? (Y/N) : ')

   if repeat.upper() == "N":
       print("THANK YOU FOR USING THIS SOFTWARE")
       print("\n")
       print("END OF PROGRAM")
       quit
   if repeat.upper() == "Y":
       my_program()

if __name__ == '__main__':
       my_program()




Sunday, May 15, 2016

Power of Given Number in C


This sample program will compute the power of a given number in C language. It will ask the user the base and exponents value of the number and then it will compute the power of the given number.

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

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

int main()
{
  int base=0, exponent=0;
  long long int value=1;
  printf("Power of Given Number in C");
  printf("\n\n");
  printf("Give the Base Value     : ");
  scanf("%d",&base);
  printf("Give the Exponent Value : ");
  scanf("%d",&exponent);

  while (exponent != 0)
  {
      value *= base;
      --exponent;
  }
  printf("\n\n");
  printf("The result is %d.", value);
  printf("\n\n");
  printf("\t End of Program");
  printf("\n\n");
  system("pause");
}



Saturday, May 14, 2016

Fibonacci Number Sequence in JavaScript

A simple program that I wrote in JavaScript to accept a number from the user and then our program will generate the corresponding Fibonacci Number Sequence.

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

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title> Fibonacci Sequence in JavaScript</title>
<style>
body {
  font-family:arial;
  color:blue;
  font-size:18px;
  }
  
 input[type="text"] {
  display: block;
  margin: 0;
  width: 15%;
  font-family: arial;
  font-size: 18px;
  appearance: none;
  border-radius: 2px;
  box-shadow: 10px 10px 7px #888888;
}
input[type="text"]:focus {
  outline: none;
}

input[type=button] {
padding:12px 31px; 
background:yellow; border:10px;
cursor:pointer;
-webkit-border-radius: 12px;
box-shadow: 10px 10px 7px #888888;
border-radius: 5px; 
font-family: arial;
font-size: 18px;
}
</style>
</head>
<body bgcolor="lightgreen">
<script>
function start_fibonacci() {

   var num, first = 0, second = 1, next, c;
   var value_number = document.getElementById("UserInput").value
   var num = Number(value_number);

  for ( c = 0 ; c < num ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }

 
document.getElementById('result').innerHTML +=  + next + "<br>";
 
}
   
}
function clear_now()
{
document.getElementById('result').innerHTML="";
document.getElementById('userInput').value="";
document.getElementById('userInput').focus();
}  
</script>
<b> Fibonacci Sequence in JavaScript </b> <br><br>
<form name="myform" action="">
<b>Give a Number </b><br><br>
<input type='text' id='UserInput' placeholder="enter number here" value='' size="5" required autofocus/>
<br><br>
<input type='button' onclick='start_fibonacci()' 
title="Click here to generated fibonacci sequence number." value='OK'/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type='button' onclick='clear_now()' title="Click here to clear the textbox." value='CLEAR'/>
</form>
<br><br>
</body>
Fibonacci Sequence Result 
<br><br>
<div id = "result"></div>  
</html>



Palindrome of Number in JavaScript

This sample program will ask the user to give a number and then our program will check and determine whether the given number by the user is a Palindrome or Not a Palindrome. I wrote this program using JavaScript.

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


<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Palindrome of Number in JavaScript</title>
<style>
body {
  font-family:arial;
  color:blue;
  font-size:18px;
  }
  
 input[type="text"] {
  display: block;
  margin: 0;
  width: 15%;
  font-family: arial;
  font-size: 18px;
  appearance: none;
  border-radius: 2px;
  box-shadow: 10px 10px 7px #888888;
}
input[type="text"]:focus {
  outline: none;
}

input[type=button] {
padding:12px 31px; 
background:yellow; border:10px;
cursor:pointer;
-webkit-border-radius: 12px;
box-shadow: 10px 10px 7px #888888;
border-radius: 5px; 
font-family: arial;
font-size: 18px;
}
</style>
</head>
<body bgcolor="lightgreen">
<script>
function start_palindrome() {
   var revStr = "";
   var str = document.getElementById("UserInput").value;
   var i = str.length;

     for(var j=i; j>=0; j--) {
         revStr = revStr+str.charAt(j);
       }
if(str == revStr) {
    document.getElementById("result").innerHTML = "The Number " + str + " is Palindrome.";
   } 
 else {
     document.getElementById("result").innerHTML = "The Number " + str + " is Not a Palindrome.";
     }
}
function clear_now()
{
document.getElementById('result').innerHTML="";
document.getElementById('userInput').value="";
document.getElementById('userInput').focus();
}  
</script>

<b> Palindrome of Number in JavaScript </b> <br><br>
<form name="myform" action="">
<b>Give a Number </b><br><br>
<input type='text' id='UserInput' placeholder="enter number here" value='' size="5" required autofocus/>
<br><br>
<input type='button' onclick='start_palindrome()' 
title="Click here to findout if the number in a palindrome or not." value='OK'/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type='button' onclick='clear_now()' title="Click here to clear the textbox." value='CLEAR'/>
</form>
<br><br>
</body>
<div id = "result"></div>  
</html>


Addition and Subtraction of Two Numbers in JavaScript

Hi there thank you for visiting my website I have  a very busy week in my work that why I was not able to update my blog anyway moving forward. In this sample program will show you how to add and subtract two numbers using HTML forms in JavaScript. The code is very easy to understand for beginners that are new in JavaScript. I hope you will find my work useful.

 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

<!DOCTYPE html>  
<html>   
<head>  
<meta charset=utf-8 />  
<title>Addition and Subtraction of Two Numbers in JavaScript</title>  
<style type="text/css">  
body {
    font-family:arial;
font-size:12;
font-weight:bold;
    background-color:lightgreen;
margin: 30px;
}
</style>   
</head>  
<body>  
<script>
function AdditionBy()  
{  
        num1 = document.getElementById("first").value;  
        num2 = document.getElementById("second").value;  
        document.getElementById("result").innerHTML = Number(num1) + Number(num2);  
}  
  
function SubtractionBy()   
{   
        num1 = document.getElementById("first").value;  
        num2 = document.getElementById("second").value;  
        document.getElementById("result").innerHTML = Number(num1) - Number(num2);  
}  
</script>
<hr>
<h2> Addition and Subtraction of Two Numbers in JavaScript </h2>
 <hr>

<form>  
Give 1st Number : <input type="text" id="first"  maxlength="4"/ size="4"><br>  
Give 2nd Number : <input type="text" id="second"  maxlength="4" size="4" />
<br><br>
<input type="button" onClick="AdditionBy()" Value="Addition" 
title="Click here to find the sum of the two numbers." />  &nbsp;
<input type="button" onClick="SubtractionBy()" 
title="Click here to find the differece of the two numbers." 
Value="Subtraction" />  
</form>  <br><br>
<p>The Final Result is : 
<span id = "result"></span>  
</p>  
</body>  
</html>  






Saturday, May 7, 2016

OOP Payroll System in C++

A simple object oriented payroll system that I wrote in C++ before that I would like to share to my fellow programmers, students and persons who likes programming. I hope you will find my work useful.

 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>
#include <iomanip>

using namespace std;


class payroll {

    private:

    string name;
    int days_work;
    float rate;
    float solve;

    public :

      int get_info();
      void display_info();
};

 int payroll :: get_info()
 {
     cout << "\t\t Simple Payroll System Using OOP in C++";
     cout << "\n\n";
     cout << "Enter Employees Name     : ";
     getline(cin,name);
     cout << "Enter No. of Days Worked : ";
     cin >> days_work;
     cout << "Enter Daily Rate         : ";
     cin >> rate;
     cout << fixed << setprecision(2);
     solve = (days_work * rate);
 }

 void payroll ::display_info()
    {

     cout << "\n\n";
     cout << "==== DETAILED REPORT =====";
     cout << "\n\n";
     cout << "\nEmployees Name     : " << name;
     cout << "\nEmployees Salay is : $" << solve;
     cout << "\n\n";
     system("pause");
    }


    main() {
        payroll emp;
        emp.get_info();
        emp.display_info();

    }


Odd and Even Numbers in C++ using Structure

A simple program that I wrote a long time ago that will check if the give number is odd or even using structure in C++.

 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>
#include <iomanip>

using namespace std;



struct odd {

int n;

  int odd_even() {

  if (n % 2 == 0)
        {
                 cout << n <<" Number is even!\n";
        }
        else
        {
                 cout << n << " Number is odd!\n";
        }
   return(n);

  }

};

main() {

    odd value;

   cout << "\t\t ODD and Even Number Determiner";
   cout << "\n\n";
   cout << "Enter a Number :";
   cin >> value.n;
   cout << "\n\n";
   cout << value.odd_even();
   cout << "\n\n";
   system("pause");


}


Payroll System in Java


A simple payroll system that I wrote using Java programming language a long time ago.

 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


import java.io.*;
import java.text.*;

public class payroll_program{


    static BufferedReader in =  new BufferedReader(new InputStreamReader(System.in));

    public static void main(String [] args) throws IOException {

        String EmpCode = “”;

        while(!EmpCode.equals(“0?)) {

            System.out.print(“Enter Employee Code: “);
            EmpCode = in.readLine();

            String EmpInfo[] = getInfo(EmpCode);

            double basicsalary =  Double.parseDouble(EmpInfo[3]);

         
            System.out.println(” NEW MEGA ENTERPRISES PAYROLL SYSTEM“);
            System.out.println(”\n\n“);

            System.out.println(“READ ME FIRST : ****************************”);
            System.out.println(” * Input for Regular Hours  — > 8:00 – 17:00 “);
            System.out.println(” * Input for OT Hours — > 17:30 – 20:30 “);
            System.out.println(” * OT Income = ( Basic Salary / 8 ) * 1.1 “);
            System.out.println(” * Holiday = ( Basic Salary / 8 ) * 1.1 “);
            System.out.println(“*******************************************”);
            System.out.println(“============= Employee Information ==========”);
            System.out.println(“Employee Code: ” + EmpInfo[0]);
            System.out.println(“Employee Name: ” + EmpInfo[1]);
            System.out.println(“Employee Position: ” + EmpInfo[2]);
            System.out.println(“Employee  Basic Salary: ” + EmpInfo[3]);
            System.out.println(“=======================================”);

            String days[] = {“Monday”,”Tuesday”,”Wednesday”,”Thursday”,”Friday”};

            double timeInOut[][] =  new double[2][5];
            double otInOut[][] =  new double[2][5];

            String strTemp = “”;
            String tmpTime[] = new String[2];

            double tmpHours, totalHours = 0, tmpRegIncome = 0, totalRegIncome = 0,
            tmpOTHours,totalOTHours = 0, tmpOTIncome, totalOTIncome = 0;

            for(int i = 0; i < 5; i++){

                System.out.print(“Time In for ” + days[i] + “: “);
                strTemp = in.readLine();
                tmpTime = strTemp.split(“:”);
                timeInOut[0][i] = Double.parseDouble(tmpTime[0]) + (Double.parseDouble(tmpTime[1]) / 60);

                System.out.print(“Time Out for ” + days[i] + “: “);
                strTemp = in.readLine();
                tmpTime = strTemp.split(“:”);
                timeInOut[1][i] = Double.parseDouble(tmpTime[0]) + (Double.parseDouble(tmpTime[1]) / 60);

                System.out.print(“is ” + days[i] + ” Holiday?: “);
                String isHoliday =  in.readLine();

                System.out.print(“OT Time In for ” + days[i] + “: “);
                strTemp =  in.readLine();
                tmpTime = strTemp.split(“:”);
                otInOut[0][i] = Double.parseDouble(tmpTime[0]) + (Double.parseDouble(tmpTime[1]) / 60);

                System.out.print(“OT Time Out for ” + days[i] + “: “);
                strTemp = in.readLine();
                tmpTime = strTemp.split(“:”);
                otInOut[1][i] = Double.parseDouble(tmpTime[0]) + (Double.parseDouble(tmpTime[1]) / 60);

                if(timeInOut[0][i] < 8)timeInOut[0][i] = 8;
                if(timeInOut[1][i] > 17)timeInOut[1][i] = 17;
                if(otInOut[0][i] < 17.5 && otInOut[0][i] != 0)otInOut[0][i] = 17.5;
                if(otInOut[1][i] > 20.5)otInOut[1][i] = 20.5;

                tmpHours = timeInOut[1][i] – timeInOut[0][i];
                tmpOTHours = otInOut[1][i] – otInOut[0][i];

                if(tmpHours > 4)tmpHours–;

                if(isHoliday.equals(“Yes”)){
                    totalOTHours += tmpHours;
                    totalOTIncome += tmpHours * ((basicsalary / 8) * 1.1);
                    totalHours += tmpHours;
                    tmpRegIncome = tmpHours * (basicsalary / 8);
                }else{
                    totalHours += tmpHours;
                    tmpRegIncome = tmpHours * (basicsalary / 8);
                }

                    totalOTHours += tmpOTHours;
                    totalOTIncome += tmpOTHours * ((basicsalary / 8) * 1.1);
                    totalRegIncome += tmpRegIncome;

            }
                    double grossincome =  totalRegIncome + totalOTIncome;

                    DecimalFormat df = new DecimalFormat(“#.##”);

                    System.out.println(“=========== Total Output ==============”);
                    System.out.println(“Total work hours: ” + df.format(totalHours));
                    System.out.println(“Total regular income: ” + df.format(totalRegIncome));
                    System.out.println(“Total OT hours: ” + df.format(totalOTHours));
                    System.out.println(“Total OT Income: ” + df.format(totalOTIncome));
                    System.out.println(“Gross Income: ” + df.format(grossincome));
                    System.out.println(“=====================================”);
                    System.out.println(" THANK YOU FOR USING THIS PROGRAM");

        }

    }

    static String[] getInfo(String EmpCode){

        String getInfo[] = new String [4];
        String strLine;
        int ctr =0;
        boolean isFound = false;

        try{

            FileInputStream fstream =  new FileInputStream(“payroll.txt”);
            DataInputStream dstream  =  new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(dstream));

            while((strLine = br.readLine()) != null && ctr < 4){
                if(strLine.equals(EmpCode))isFound = true;
                if(isFound){
                    getInfo[ctr] =  strLine;
                    ctr++;

                }

            }

            br.close();

        }catch(IOException e){

            System.out.println(“Error: ” + e.getMessage());
        }

        return getInfo;

    }

}