Saturday, June 4, 2016

Sum of First and Last Number in C

A simple program that will ask the user three integer number and then our program will find the sum of the first and the last 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 number=0,first=0,last=0, sum=0;

int main()
{
    system("cls");
    printf("\t SUM OF FIRST AND LAST NUMBER PROGRAM");
    printf("\n\n");
    printf("Give a three digit number : ");
    scanf("%d",&number);

    first = (number/100);
    last = (number%10);

    printf("\n");
    printf("Display Results");
    printf("\n");
    printf("\nThe First Number is %d.",first);
    printf("\nThe Last Number is %d.",last);
    sum = (first+last);
    printf("\n\n");
    printf("The sum of digits is %d.",sum);
    printf("\n\n");
    printf("End of Program");
    printf("\n\n");
    system("pause");
}








Employees Payroll System in C++ using Text File

A simple employees payroll system that I retrieve, process and store information in a text file in C++ that I wrote a long time ago. 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<fstream>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<sstream>
#include<iomanip>

using namespace std;

void append();
void find();
void read();
void whattodo();
void loop();
void about();
void mainfind();

int main()
{
    system("Color 2F");

    cout<<"\t\t\t------------------"<<endl;
    cout<<"\t\t\t* Payroll System *"<<endl;
    cout<<"\t\t\t------------------"<<endl;
    whattodo();
    getch();
    return 0;
}
void whattodo()
{

    int choice;

    loop:



    cout << "\n\t\t Created By: Mr. Jake R.Pomperada, MAED-IT";
    cout << "\n\n";

    cout<<"Type the number of the command you want to perform:"<<endl;
    cout<<endl;
    cout<<"[1] Append Record"<<endl;
    cout<<"[2] Browse all file contents"<<endl;
    cout<<"[3] Find a record"<<endl;
    cout<<"[4] Exit"<<endl;
    cout<<"[5] About"<<endl;
    cout<<""<<endl;

    cin>>choice;

    cout<<""<<endl;
     if (choice==1)
        {
            system("cls");
            append();
            cout<<endl;
            loop();
        }
       else if (choice==2)
        {
            system("cls");
            read();
            cout<<endl;
            loop();
        }
        else if(choice==3)
        {
            system("cls");
            mainfind();
            loop();
        }
        else if(choice==4)
        {
            system("cls");
            cout<<"Goodbye.";
        }
        else if(choice==5)
        {
            system("cls");
            about();
        }
        else
        {
            cout<<"Invalid! Try again."<<endl;
            goto loop;
        }

    system ("cls");
}

void append()
{
     string emp_first, emp_last;
     string id;
     double salary=0.00;
     ofstream fout;
     fout.open("myRecord.txt",ios::app);    // open file for appending



     cout<<"Enter Employee Id: ";
      cin >> id;

      cout << "\n";
     cout<<"Enter Employee Name: ";
     cin >> emp_first >> emp_last;

     cout<<"Enter Employee Salary:";
     cin >> salary;
     fout << setiosflags(ios::fixed | ios :: showpoint)
        << setprecision(2);
            fout<<  id<< ", " << emp_first
                << " " << emp_last << " , " << salary << endl;
            fout << fixed;





     fout.close( );       //close file
   ;

}




void read()
{
    string line;
    ifstream x ("myRecord.txt");

    if (x.is_open())
    {
    while(!x.eof())
    {

    cout<<endl;
    getline(x,line);
    cout<<line<<endl;

    }
    x.close();
    }
    else
    cout<<"Cant open file."<<endl;
}
void find()
{
    ifstream data("myRecord.txt");
    string item,line;
    int x=0;
    int y=0;
    string id;

    cout<<endl;
    cout<<"Enter Employee Id: ";
    cin>>id;
    cout<<""<<endl;

    while(!data.eof())
    {
        getline(data,line);
        string item_array[10];
        stringstream stream(line);
        x=0,y=0;

        while(getline(stream,item,','))
        {
            item_array[x]=item;
            x++;
            item_array[y]=item;
            y++;
        }

        if(item_array[0]==id)
        {
            cout<<setfill('-')<<left<<setw(10)<<"\t\t\tID:   " <<right<<"  "<<item_array[0]<<endl;
            cout<<setfill('-')<<left<<setw(10)<<"\t\t\tName: " <<right<<" "<<item_array[1]<<endl;
            cout<<setfill('-')<<left<<setw(10)<<"\t\t\tRate: " <<right<<" "<<item_array[2]<<endl;
            cout<<""<<endl;
        }
    }
    data.close();
}
void loop()
{
    string choice;
    cout<<""<<endl;
    cout<<"Do you want to make another choice?(yes/no)";
    cin>>choice;
    system("cls");
    cout<<""<<endl;
        if (choice=="yes")
        {
            whattodo();
        }
        else if(choice=="no")
        {
            cout<<"Goodbye.";
        }
}
void about()
{
    cout<<endl;
    cout<<"                    ABC Computer Training Center"<<endl;
    cout<<"                     1st Floor, Victoria Center"<<endl;
    cout<<"                Bacolod City, Philippines Tel.No. 4335081"<<endl;
    cout<<"                          Endterm Exams"<<endl;
    cout<<""<<endl;
    cout<<"                 Professor       : Sir Jake R. Pomperada"<<endl;
    cout<<""<<endl;
    cout<<"                 Project Manager : Juan Dela Cruz"<<endl;
    cout<<""<<endl;
    cout<<"                 Program Designer: Pedro Santa Maria"<<endl;
    cout<<""<<endl;
    loop();
}
void mainfind()
{
    find();

    string id;
    cout<<"Type back to go to main menu."<<endl;
    cout<<"Press any key to find another profile."<<endl;
    cin>>id;
    system("cls");

    if (id=="back")
    {
        whattodo();
    }
    else
    {
        mainfind();
        find();
    }
}


myRecord.txt        Content Records in a Text File

101, Joey Smith, 500.00
102, Lydia Gamboa, 560.34
103, Mark Chua,750.55
104, Lebron James, 850.32
105, Jake R. Pomperada,15000.50                            
106, Allie Pomperada , 12340.50
107, Jacob Samuel Pomperada , 23400.20
108, Julianna Rae Pomperada , 3500.12
109, Kobe Bryant , 781234.40
110, Albrecht Aldaba , 53423.13

Sunday, May 29, 2016

Factorial Solver in JSTL and JSP

A simple program that I wrote that we ask the user to give a number and then the program will compute the factorial value of the number using JSP and JSTL. 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

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title> Factorial Solver  Solver in JSTL and JSP</title>
</head>
<style>
body 
{
font-family:arial;
font-weight:bold; 
size:12px;
color:blue;
}
</style>
<body>
  <h2> Factorial Solver in JSTL and JSP </h2>
  <br>
  <form method="post">
      Enter a number &nbsp; &nbsp;
    <input type="text" name="number"  size="3" value="<c:out value="${param.number}"/>" autofocus/><br>
      <br> <br>
     <input type="submit" value="Compute Factorial"  title="Click here to findout the factorial value." />
     <br />
    </form>
<c:if test="${pageContext.request.method=='POST'}">

         <%!
    int numberfactorial(int number)
    {
        if (number == 1) {
            return number;
        }
        else {
            return number * numberfactorial(number - 1);
        }
    }
    %>
<%int no = Integer.parseInt(request.getParameter("number"));%>
    <%
        out.println("The factorial  of " + no + " is " + numberfactorial(no)+ ".");
    %>
  

</c:if>
</body>
</html>

Area of the Circle Solver in JSTL

A simple program that I wrote using JSTL of Java Server Pages Standard Tag Library that will ask the user to give the radius of the circle and then our program will compute the area of the circle.

 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

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title> Area of the Circle Solver in JSTL</title>
</head>
<style>
body 
{
font-family:arial;
font-weight:bold; 
size:12px;
color:blue;
}
</style>
<body>
  <h2> Area of the Circle Solver in JSTL</h2>
  <br>
  <form method="post">
      Enter the Radius &nbsp; &nbsp;
    <input type="text" name="radius"  size="3" value="<c:out value="${param.radius}"/>" autofocus/><br>
      <br> <br>
     <input type="submit" value="Compute Area"  title="Click here to findout the area of the circle." />
     <br />
    </form>
<c:if test="${pageContext.request.method=='POST'}">
 <c:set var="convert" scope="session" 
 value="${ (param.radius* param.radius) * 3.1416}"/>
 <br>

The area of the circle is <fmt:formatNumber value="${convert}" maxFractionDigits="2"/>.
</c:if>
</body>
</html>

Celsius To Fahrenheit Converter in JSTL

A simple program that I wrote using JSTL or Java Server Pages Standard Tag Library that will ask the user to give a temperature in Celsius and then it will convert in Fahrenheit temperature. 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

celsius.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title> Celsius To Fahrenheit Converter in JSTL</title>
</head>
<style>
body 
{
font-family:arial;
font-weight:bold; 
size:12px;
color:blue;
}
</style>
<body>
  <h2> Celsius To Fahrenheit Converter in JSTL</h2>
  <br>
  <form method="post">
     Give temperature in Celsius &nbsp; &nbsp;
    <input type="text" name="cel"  size="3" value="<c:out value="${param.cel}"/>" autofocus/><br>
      <br> <br>
     <input type="submit" value="Find Celsius"  title="Click here to findout the temperature in fahrenheit." />
     <br />
    </form>
<c:if test="${pageContext.request.method=='POST'}">
 <c:set var="convert" scope="session" 
 value="${ (9/5) * param.cel  + 32}"/>
 <br>

The Temperatue in Fahrenheit is <fmt:formatNumber value="${convert}" maxFractionDigits="2"/> &degF.
</c:if>
</body>
</html>

Fahrenheit To Celsius Converter in JSTL

A simple program that I wrote using JSTL or Java Server Pages Standard Tag Library that will ask the user to give a temperature in Fahrenheit and then it will convert in Celsius temperature. 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


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>Fahrenheit To Celsius Converter in JSTL</title>
</head>
<style>
body 
{
font-family:arial;
font-weight:bold; 
size:12px;
color:blue;
}
</style>
<body>
  <h2> Fahrenheit To Celsius Converter in JSTL</h2>
  <br>
  <form method="post">
     Give temperature in Fahrenheit &nbsp; &nbsp;
    <input type="text" name="fah"  size="3" value="<c:out value="${param.fah}"/>" autofocus/><br>
      <br> <br>
     <input type="submit" value="Find Celsius"  title="Click here to findout the temperature in celsius." />
     <br />
    </form>
<c:if test="${pageContext.request.method=='POST'}">
 <c:set var="convert" scope="session" 
 value="${ ((param.fah - 32) * 5)/9}"/>
 <br>

The Temperatue in Celsius is <fmt:formatNumber value="${convert}" maxFractionDigits="2"/>.
</c:if>
</body>
</html>



Average Grade Solver in JSTL

A simple program that I wrote using JSTL or Java Server Pages Standard Tag Library that will ask the user to give the grades in different subjects and then our program will compute the average of the five grades and determine whether the student pass or failed in their overall grades. 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

grade.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>Average Grade Solver in JSTL</title>
</head>
<style>
body 
{
font-family:arial;
font-weight:bold;
size:12px;
color:blue;
}
</style>
<body>
  <h2> Average Grade Solver in JSTL</h2>
  <br>
  <form method="post">
     Enter Grade in Math &nbsp; &nbsp;
    <input type="text" name="one"  size="3" value="<c:out value="${param.one}"/>" autofocus/><br>
    Enter Grade in Science &nbsp; &nbsp;
    <input type="text" name="two"  size="3" value="<c:out value="${param.two}"/>"/> <br>
     Enter Grade in Physical Education &nbsp; &nbsp;
    <input type="text" name="three"  size="3" value="<c:out value="${param.three}"/>"/><br>
     Enter Grade in History &nbsp; &nbsp;
    <input type="text" name="four"  size="3" value="<c:out value="${param.four}"/>"/><br>
     Enter Grade in English &nbsp; &nbsp;
    <input type="text" name="five"  size="3" value="<c:out value="${param.five}"/>"/>
   <br> <br>
     <input type="submit" value="Find Average"  title="Click here to findout the average grade." />
     <br />
    </form>
<c:if test="${pageContext.request.method=='POST'}">
 <c:set var="average" scope="session" 
 value="${ (param.one + param.two + param.three + param.four + param.five) /5}"/>
 <br>
Your average grade is <fmt:formatNumber value="${average}" maxFractionDigits="0"/>.
</c:if>
<c:choose>
  <c:when test="${average >= 75}">
    <br> <font color="green">
    <h3>You have a Passing Average Grade.</h3> </font>
  </c:when>
    <c:otherwise>
    <font color="red">
  <h3>You have a Failing Average Grade.</h3> </font>
  </c:otherwise>
</c:choose>
</body>
</html>