Friday, August 5, 2016

Positive and Negative Numbers in Perl CGI

A simple program that I wrote in Perl CGI to display the list of positive and negative numbers in the web page of the web browser. The code is very easy to understand and use.

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

positive.cgi


#!"C:\xampp\perl\bin\perl.exe"


print "Content-type:text/html\n\n";
print "<font size='3'>";
printf "<font color='blue'>";
print "Positive and Negative Numbers in Perl";
print "<br><br>";

for (my $i=-10; $i <= 10; $i++) {
print "<font size='4'>";
printf "<font color='blue'>";
if ($i < 0) {
print "$i is a Negative Number";
print "<br />";
}
else {
  print "$i is a Positive Number";
print "<br />";
}
printf "</font> </font></font> </font>";

}




Odd and Even Numbers in Perl CGI

A simple program that I wrote in Perl CGI to display the odd and even numbers on the web browser.

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

#!"C:\xampp\perl\bin\perl.exe"

print "Content-type:text/html\n\n";
print "ODD AND EVEN Numbers";
print "<br><br>";
for (my $i=0; $i <= 10; $i++) {
if ($i % 2 == 0) {
print "$i is an EVEN Number";
print "<br />";
}
else {
  print "$i is an ODD Number";
print "<br />";
}

}


Running Sum of Numbers in C++

A simple program that I wrote in C++ that will perform running sum of values provided by the user. The code is very easy to understand and use.

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 <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int values[3][2], running_sum=0;
    
     cout << "\t\t RUNNING SUM VERSION 1.0";
     cout << "\n";
     cout << "\tCreated By: Mr. Jake R. Pomperada, MAED-IT"; 
          cout << "\n";
      for (int row=0; row< 3; row++) {
           for (int col=0; col< 2; col++) {

            cout << "\nEnter a Number :=> ";
            cin >> values[row][col];
          
            running_sum+=values[row][col];
            cout << "\nThe running sum is " <<       
                    running_sum << ".";
             }
             }
         cout << "\n\n";                     
    system("PAUSE");
    return EXIT_SUCCESS;
}


Roman Numeral To Decimal in PHP

A simple program that will convert the roman number into decimal equivalent in PHP.

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>
<title>Roman Numeral To Decimal in PHP</title>
<style>
  body {
   font-family: arial;
   font-size: 18px;
   font-weight: bold;
 };
</style>
<body>
  <?php
   error_reporting(0);
  $input_A = $_POST['inputFirst'];

  if(isset($_POST['ClearButton'])){
  $input_A="";

  $display_result="";
  }

   ?>
   <br>
  <h2>Roman Numeral To Decimal in PHP </h2>
<form action="" method="post">
   Enter Roman Numeral
  <input type="text" name="inputFirst"
  value="<?php echo $input_A; ?>" size="5" autofocus required/>

  <br><br>

  <input type="submit" name="SubmitButton" value="Ok"/>
   &nbsp;&nbsp;&nbsp;
  <input type="submit" name="ClearButton" value="Clear"/>
</form>
<?php

function roman_convert($input_roman){
  $di=array('I'=>1,
            'V'=>5,
            'X'=>10,
            'L'=>50,
            'C'=>100,
            'D'=>500,
            'M'=>1000);
  $result=0;
  if($input_roman=='') return $result;
    for($i=0;$i<strlen($input_roman);$i++){
    $result=(($i+1)<strlen($input_roman) and
          $di[$input_roman[$i]]<$di[$input_roman[$i+1]])?($result-$di[$input_roman[$i]])
                                                        :($result+$di[$input_roman[$i]]);
   }
 return $result;
}


if(isset($_POST['SubmitButton'])){

$original = $input_A;
$value = roman_convert($input_A);

  echo "<br>";
  $display_result = "The Decimal equivalent of " .$original. " is "
                    .$value.".";

  echo $display_result;
  echo "<br>";
 }
?>

</body>
</html>


Strong Number Checker in PHP

A simple program that I wrote in PHP to check if the given number of the user in strong number or not. 

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>
<title> Strong Number Checker in PHP </title>
<style>
  body {
   font-family: arial;
   font-size: 18px;
   font-weight: bold;
 };
</style>
<body>
  <?php
   error_reporting(0);
  $input = $_POST['inputNumber'];
  if(isset($_POST['ClearButton'])){
  $input="";
  $display_result="";
  }

   ?>
   <br>
  <h2> Strong Number Checker in PHP </h2>
<form action="" method="post">
  Give a number
  <input type="text" name="inputNumber"
  value="<?php echo $input; ?>" size="5" autofocus required/>
  <br><br>
  <input type="submit" name="SubmitButton" value="Ok"/>
   &nbsp;&nbsp;&nbsp;
  <input type="submit" name="ClearButton" value="Clear"/>
</form>
<?php
//Strong number
//Strong numbers are the numbers whose sum of factorial of digits is equal to the number. For Example: 145 is a strong number
//Since 1! + 4! + 5! = 145
// 1,2,145 and 40585 are examples of strong numbers

function CheckStrongNumber($number)
{
$fact;
$num = $number;
$sum = 0;

while ($number != 0)
{
$fact = 1;

for ($i = 1; $i <= $number % 10; $i++)
$fact *= $i;

$sum += $fact;

$number = (int)($number / 10);
}

return $sum == $num;
}


if(isset($_POST['SubmitButton'])){
$value = CheckStrongNumber($input);

if ($value == True)
 {
  echo "<br>";
  $display_result = $input. " is a strong number.";
  echo $display_result;
  echo "<br>";
 }
 else {
   echo "<br>";
   $display_result = $input. " is a not strong number.";
   echo $display_result;
   echo "<br>";
 }
}
?>

</body>
</html>




Days in a Month in PHP

A simple program that I wrote in PHP that will ask the user to give the year and month and then our program will give how many days in the given month and year to the user. 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

<html>
<title>Days in Month in PHP</title>
<style>
  body {
   font-family: arial;
   font-size: 18px;
   font-weight: bold;
 };
</style>
<body>
  <?php
   error_reporting(0);
  $input_A = $_POST['inputYear'];
  $input_B = $_POST['inputMonth'];
  if(isset($_POST['ClearButton'])){
  $input_A="";
  $input_B="";
  $display_result="";
  }

   ?>
   <br>
  <h2>Days in Month in PHP </h2>
<form action="" method="post">
  What is the year?
  <input type="text" name="inputYear"
  value="<?php echo $input_A; ?>" size="5" autofocus required/>
<br><br>
  What is the month?
  <input type="text" name="inputMonth"
  value="<?php echo $input_B; ?>" size="5" required/>
  <br><br>

  <input type="submit" name="SubmitButton" value="Ok"/>
   &nbsp;&nbsp;&nbsp;
  <input type="submit" name="ClearButton" value="Clear"/>
</form>
<?php
function IsLeapYear($year) {
return ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0));
}

function GetDaysInMonth($year, $month) {
$daysInMonth = 0;

if ($month == 4 || $month == 6 || $month == 9 || $month == 11)
{
$daysInMonth = 30;
}
else if ($month == 2)
{
if (IsLeapYear($year))
{
$daysInMonth = 29;
}
else
{
$daysInMonth = 28;
}
}
else
{
$daysInMonth = 31;
}

return $daysInMonth;
}


if(isset($_POST['SubmitButton'])){

$value = GetDaysInMonth($input_A,$input_B);

  echo "<br>";
  $display_result = "The number of days in the given year "
                    .$input_A. " and month ".$input_B. " is "
                    .$value." days.";

  echo $display_result;
  echo "<br>";
 }

?>

</body>
</html>



Grade Evaluator in C++

Here is another example of my work in C++ to compute and evaluate the grades of the student whether the student, pass or failed in the subject. The code using two dimensional array as its data structure and looping statements. I hope you will find my work useful in learning C++ programming.

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;

main() {
     int grades[5][1],pass=0,failed=0,out_range=0;
     int row=0, col=0;
     string remarks;
     char letter_grade;

     cout << "\t Grades Evaluator Version 1.0";
     cout << "\n\n Created By: Mr. Jake Rodriguez Pomperada,MAED-IT";
     cout << "\n\n";
     
     for ( row=0; row < 5; row++) {
       for  (col=0; col < 1; col++) {
         cout << "Enter grade : " ;
         cin >> grades[row][col];
     }
}
    
  // Code to check for remarks
cout <<"\n" << setw(5) << "GRADES" <<
               setw(7) << " EQUIV " <<
               setw(10) << "REMARKS";
    cout << "\n\n";

     for ( row=0; row < 5; row++) {
       for (col=0; col < 1; col++) {

         if (grades[row][col] >= 75) {
             remarks = "PASSED";
             pass++;
         }
         else if (grades[row][col] < 50)
         {
           remarks= " Error Out of Range ";
           out_range++;
         }

         else  if (grades[row][col] < 75){
                 remarks = "FAILED";
                 failed++;
         }
 


  // Letter Grade Equivalent

     if (grades[row][col] >= 90 &&  grades[row][col] <= 100  ) {
           letter_grade = 'A';
         }
         else if (grades[row][col] >= 80 && grades[row][col] <= 89  ) {
           letter_grade = 'B';
         }
         else if (grades[row][col] >= 70 && grades[row][col] <= 79  ) {
           letter_grade = 'C';
         }
         else if (grades[row][col] >= 60 && grades[row][col] <= 69  ) {
           letter_grade = 'D';
         }
        else if (grades[row][col] >= 50 && grades[row][col] <= 59  ) {
           letter_grade = 'F';
         }
        else if (grades[row][col] < 50) {
            letter_grade = 'X';

         }

        cout <<"\n" << setw(5) << grades[row][col]
              << setw(6) << letter_grade << setw(12)
              << remarks;  
     } 
 }
      
     cout << "\n\n";
     cout << "\nNumber of Passed Grades " << pass << ".";
     cout << "\nNumber of Failed Grades " << failed << ".";
     cout << "\nNumber of Out of Range Grades "<< out_range << ".";
     cout << "\n\n";
     system("PAUSE"); 
 
}

Simple Grade Solver in C++

A simple grade solver that will solve the prelim, midterm and final grade of the student using C++ as my programming language. I used this sample program in my programming class before in college as an example prior I worked here in the IT industry. I hope you will find my work useful and interesting.

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()
 {
     string grading[3] = {"Prelim","Midterm","Endterm"};
      int grade[3][1];
     int add=0, solve=0;
     bool remarks;
     cout << "Simple Grade Solver 1.0";
     cout << "\n\n";
     for (int a=0; a<3; a++) {
       for (int b=0; b<1; b++)
       {

        cout << "Enter " <<grading[a]
         << " grade : ";
        cin >> grade[a][b];
        add+=grade[a][b];
       }
     solve= add/3;
     }
    cout << "You grade is " << solve;
    cout << "\n\n";
    if (solve >= 75)
    {
        remarks = true;
    }
    else {
        remarks = false;

    }

    switch (remarks) {

        case 1 : cout << "You Pass";
                  break;
        default : cout << "You Failed";
    }
    cout << "\n\n";
    system("pause");
 }