Sunday, June 7, 2015

Selecting a Value in PHP and XML

In this sample program I will show you how to select a value from a drop down menu in HTML and extract the data in an XML file. This will be my first time to write a program that uses XML and PHP. According to Wikipedia.org XML is defined as Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format which is both human-readable and machine-readable. It is defined by the W3C's XML 1.0 Specification and by several other related specifications, all of which are free open standards.

The code is very easy to follow and understand I hope you will find my work useful in your programming projects and assignments. If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines can contact me at my mobile number 09173084360.

Thank you very much and Happy Programming.




Program Listing

index.php

<!-- Selecting a value in PHP and XML           -->
<!-- June 7, 2015   Sunday                      -->
<!-- Written By: Mr. Jake R. Pomperada, MAED-IT -->
<!-- Email Address: jakerpomperada@gmail.com    -->
<!--              : jakerpomperada@yahoo.com    -->
<html>
<title>Selecting a value in PHP and XML
</title>
<style>
h1 {
    font-family:arial;
color:blue;
};

</style>
<body bgcolor="lightgreen">
<br><br>
<h1>
SELECTING A VALUE IN PHP AND XML
</h1>
<form method="post" action="">
<select id="select" class="select" name="filter1" style="text-align:center;">
<option value="1" <?php if(@$_POST['filter1'] == '1') { echo 'selected = \"selected\"'; } ?>>First Record</option>
<option value="2"  <?php if(@$_POST['filter1'] == '2') { echo 'selected = \"selected\"'; } ?>>Second Record</option>
<option value="3" <?php if(@$_POST['filter1'] == '3') { echo 'selected = \"selected\"'; } ?> >Third Record</option>
<option value="4" <?php if(@$_POST['filter1'] == '4') { echo 'selected = \"selected\"'; } ?>>Fourth Record</option>
</select>
<input type="submit" id="submit" name="submit" value="ok" title="Click here to select your choice.">
</form>
<br>
<?php 
if(isset($_POST['submit'])){
if($_POST['filter1'] == "1")
{
$users = simplexml_load_file("1.xml");

            foreach ($users->person as $item)
              {
   
                if ($item->id == 1)  {
                  echo "<font color='blue' face='arial' size='5'>Title   : ".$item->title."<br />";
                  echo "Name    : ".$item->name." <br />";
        echo "Address : ".$item->address." <br /> </font>";
                }
             }
        }
else if ($_POST['filter1'] == "2")
{
$users = simplexml_load_file("1.xml");

            foreach ($users->person as $item)
              {
   
                if ($item->id == 2)  {
                  echo "<font color='blue' face='arial' size='5'>Title   : ".$item->title." <br />";
                  echo "Name    : ".$item->name." <br />";
         echo "Address : ".$item->address." <br /> </font>";
                }
             }
  }
else if ($_POST['filter1'] == "3")
{
    $users = simplexml_load_file("1.xml");

            foreach ($users->person as $item)
              {
   
                if ($item->id == 3)  {
                  echo "<font color='blue' face='arial' size='5'> Title   : ".$item->title." <br />";
                  echo "Name    : ".$item->name." <br />";
         echo "Address : ".$item->address."</font> <br />";
                }
             }
 }  
else if ($_POST['filter1'] == "4")
{
 $users = simplexml_load_file("1.xml");
       foreach ($users->person as $item)
              {
   
                if ($item->id == 4)  {
                  echo "<font color='blue' face='arial' size='5'> Title   : ".$item->title." <br />";
                  echo "Name    : ".$item->name." <br />";
         echo "Address : ".$item->address."</font> <br />";
                }
             }
 
  } 
else {
     echo "No Selected Records.";
}

 }
?>

</body>
</html>

1.xml

<?xml version="1.0"?>
<information>
   <person>
     <id> 1 </id>
     <title> First Record </title>
<name> Ana Maria Tan </name>
<address> Cubao, Quezon City </address>
   </person>

  <person>
     <id> 2 </id>
     <title> Second Record </title>
<name> David Smith </name>
<address> Washington Street, Iloilo City </address>
   </person>
   
   
  <person>
    <id> 3</id>
     <title> Third Record </title>
<name> Linda Lee </name>
<address> Hongkong, China </address>
   </person>
   
  
  <person>
     <id> 4 </id>
     <title> Fourth Record </title>
<name> Adam Stone </name>
<address> West Avenue, United Kingdom </address>
   </person>
 </information>


Sunday, May 31, 2015

Reverse a Word in Turbo Pascal

In this article I will share a code that I wrote during my college days using Turbo Pascal I called this program reverse a word. What does this program will do is to ask the user a word or string and then it will display the word in reverse order.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines can contact me at my mobile number 09173084360.

Thank you very much and Happy Programming.




Sample Program Output

Program Listing


Program Reverse;
Uses Crt;
Var  InpStr : String;
     OutStr : String;
     Size, I : Integer;


Begin
  Clrscr;
  Write('REVERSE A WORD');
  Writeln; Writeln;
  Write('Please Enter A String :=> ');
  Readln(InpStr);
  Size := Length(InpStr);
  For I := 1 To Size Do
   Begin
    OutStr[I] :=  InpStr[Size - (I - 1)];
    OutStr[0] := Chr(Size);
   End;
   Writeln;
   Writeln;
   Write('The Reversed String is ' ,OutStr,'.');
   Readln;
End.




Finding the Area of a Circle Using BASH

In this article I would like to share with you a sample program that I wrote using Bourne Again Shell or BASH scripting language that is being used in UNIX and LINUX operating system. What does the program will do is to ask the user to enter the radius of the circle and then our program will compute the area of the circle.

The script is very simple and short is very easy to understand and read. If you have some questions regarding about my works feel free to send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippine who wish to contact me can reach me through my mobile number 09173084360.

Thank you very much and Happy Programming.




Sample Program Output


Program Listing


#!/bin/bash

echo -e "\n\n"
echo -e "\t\t FINDING THE AREA OF THE CIRCLE IN BASH"
echo -e "\n"
read -p  "Kindly give the radius of a circle :=> " radius
echo -e "\n"

area=$(echo "scale=2;3.14159 * ($radius * $radius)" | bc)

printf "The area of the circle is %0.2f." $area
echo -e "\n"
echo -e "Thank you for using this program."




Payroll Database System in C++

In this article I will share with you a program that I wrote in C++ that will manage the payroll system of the employees in the company I called this program Payroll Database System in C++ that uses text file to save the records of the employees. In this program I am using CodeBlocks as my text editor and Dev C++ as my C++ compiler that is very available over the Internet for free because it is an open source.

If you have some questions regarding about my work please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines who wish to contact me can reach me thru my mobile number at 09173084360.

Thank you and Happy Programming.



Sample Program Output

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();
    }
}




Payroll System Using Text File in C++

One of the most interesting aspect of computer programming is how to store or save the information that we process in a text file or database for future reference. In this article I would like to share with you a program that I wrote a long time ago in my class to teach my students in C++ programming how to store the processed information in a text file in C++. The code is very straight forward and easy to understand.  I hope many people will able to use this code as their basis in their learning how to program in C++.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me thru my mobile number 09173084360.

Thank you very much and Happy Programming.


Sample Program Output

Program Listing

#include <iostream>
#include <fstream>

 using namespace std;

 struct employee {
     string name,job;
     int age, rate, days;
     int solve_salary;
 };


 main() {
     employee user;
     ofstream myfile("result.txt");
     cout << "\t\t XYZ Payroll System";
     cout << "\n\n";
     cout << "Enter Name : ";
     getline(cin,user.name);
     cout << "Enter Job : ";
     getline(cin,user.job);
     cout << "Enter Age : ";
     cin >> user.age;
     cout << "Enter Rate Per Day : ";
     cin >> user.rate;
     cout << "Enter No. of Days Work : ";
     cin >> user.days;

      user.solve_salary = (user.days * user.rate);

       myfile << "\n=========================";
       myfile << "\t\n  XYZ PAYROLL SYSTEM ";
       myfile << "\n=========================";
       myfile << "\n Name    : " << user.name;
       myfile << "\n Job     : " << user.job;
       myfile << "\n Age     : " << user.age;
       myfile << "\n Salary  : $" << user.solve_salary;
       myfile.close();
       cout << "\n\n";
       system("pause");
 }




Passed and Failed Grades Counter in C++

In this article I would like to share with you a program that I wrote a long time that will ask the user to enter ten grades and then our program will count how many passed and failed grades given by our user of our program. The code is very simple enough it uses one dimensional array as its basic data structure and if - else statement for conditions.

If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines who wish to contact me can reach me thru my mobile number 09173084360.

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

// Pass and Failed Grades Counter
// Author : Mr. Jake Rodriguez Pomperada, MAED - Instructional Technology
// Date : November 13, 2009 Friday 10:22 PM
// Email : jakerpomperada@yahoo.com
// Tool  : Code Blocks
// Language : C++

#include <iostream>

using namespace std;

main() {
    int list=0,pass=0,fail=0, grades[10];

     cout << "\n\t\tPASS AND FAILED GRADES COUNTER";
     cout << "\n\t Created By: Mr. Jake R. Pomperada,MAED-IT";
     cout << "\n\n";
    for (list=0; list < 10; list++) {
        cout << "Enter Grade No " << list+1 <<  " :" ;
        cin >> list[grades];
    }

        for (list=0; list < 10; list++) {

      if (list[grades] >= 75) {

         pass++;

     }

     else {
         fail++;
       }
    }

// display pass grades and failed grades
  cout << "\n";
  cout << "\n==============================";
  cout << "\n====== Generated Report ======";
  cout << "\n==============================";
  cout << "\n";
  cout << "Passed Grades => ";

        for (list=0; list < 10; list++)

        {

      if (list[grades] >= 75) {

      cout << " " <<  list[grades] << " ";
     }

    }
 cout << "\n";

cout << "Failed Grades => ";5

        for (list=0; list < 10; list++)
        {

      if (list[grades] < 75) {

      cout << " " <<  list[grades] << " ";
     }

    }

    cout << "\n";
    cout << "\nNumber of Passed Grades => " << pass << ".";
    cout << "\nNumber of Failed Grades => " << fail << ".";
    cout << "\n\n";
    system("pause");
}
  // End of Code