Friday, August 5, 2016

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










Grade Brackets in C++

In this article  I would like to share with you a sample program that I wrote for my class in C++ programming 6 years ago to check and determine the grade brackets of the students using two dimensional array in C++. The code is very simple and easy to understand 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>

using namespace std;

 main()
{
    double grades[5][2];
    int row=0,col=0, count=0, count2=0;
    int count3=0, count4=0;
    cout << "\t Grade Bracket Version 1.0 ";
    cout << "\n\n";
    // Ask for 10 grades
    for(row= 0 ; row < 5 ; row++){
     for (col=0; col <2; col++) {
       cout<< "Enter grades :=>";
       cin >> grades[row][col];
    }
    }
   for(row= 0 ; row < 5 ; row++){
     for (col=0; col <2; col++) {
      if(grades[row][col] >= 90){
         count++;
      }
      if(grades[row][col] >= 80 && grades[row][col] <90)
       {
        count2++;
       }
    if(grades[row][col] >= 75 && grades[row][col] < 80)
       {
        count3++;
       }
   if(grades[row][col] < 75)
      {
       count4++;
      }
    }
   }
    //display
    cout << "\n====================";
    cout << "\n     RESULTS        ";
    cout << "\n====================";
    cout << "\n\n";
    cout<<"\nGrades >=90    is: " <<count;
    cout<<"\nGrades 80 - 89 is: " <<count2;
    cout<<"\nGrades 75 - 80 is: " <<count3;
    cout<<"\nGrades < 75    is: " <<count4;
    cout << "\n\n";
    system("pause");

}










Days of the Week in PHP

In this article I would like to give you a sample program that will ask the user to give the year, month and day and then our program will determine what is the day in that given date using PHP. 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 of the Week 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'];
  $input_C = $_POST['inputDay'];
  if(isset($_POST['ClearButton'])){
  $input_A="";
  $input_B="";
  $input_C="";
  $display_result="";
  }

   ?>
   <br>
  <h2>Days of the Week 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>
  What is the day?
  <input type="text" name="inputDay"
  value="<?php echo $input_C; ?>" 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 dateName($date) {

       $result = "";
       $convert_date = strtotime($date);
       $month = date('F',$convert_date);
       $year = date('Y',$convert_date);
       $name_day = date('l',$convert_date);
       $day = date('j',$convert_date);
       $result = $name_day;

       return $result;
   }


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

  $dateValue = $input_A.$input_B.$input_C;
  $day1 = dateName($dateValue);
  echo "<br>";
  $display_result = "The day is ".$day1.".";
  echo $display_result;
  echo "<br>";
 }

?>
</body>
</html>


Greatest Common Divisor in PHP

Hi there in this article I would like to share with you a program that I wrote in PHP to compute for the Greatest Common Divisor. What does our program will do is to ask the user to give two numbers and then it will compute it greatest common divisor equivalent.

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>  Greatest Common Divisor Solver in PHP  </title>
<style>
  body {
   font-family: arial;
   font-size: 18px;
   font-weight: bold;
 };
</style>
<body>
  <?php
   error_reporting(0);
  $input_A = $_POST['inputFirst'];
  $input_B = $_POST['inputSecond'];
  if(isset($_POST['ClearButton'])){
  $input_A="";
  $input_B="";
  $display_result="";
  }

   ?>
   <br>
  <h2> Greatest Common Divisor Solver in PHP </h2>
<form action="" method="post">
  Give first number
  <input type="text" name="inputFirst"
  value="<?php echo $input_A; ?>" size="5" autofocus required/>
<br><br>
  Give second number
  <input type="text" name="inputSecond"
  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 GCD($a, $b)
{
if ($a == 0)
return $b;

while ($b != 0)
{
if ($a > $b)
$a -= $b;
else
$b -= $a;
}

return $a;
}


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

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

  echo "<br>";
  $display_result = "The Greatest Common Divisor between "
                    .$input_A. " and  ".$input_B. " is "
                    .$value.".";

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

?>
</body>
</html>



Saturday, July 30, 2016

Pass or Fail Grade Checker Using Ternary Operator in C++

Here is a sample program that I wrote in C++ to check if the given grade of the student is pass or failed using ternary operator 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>

 using namespace std;

main() {

    int grade=0;

    cout << " Conditional Operator Demo (?:) ";
    cout << "\n\n";
    cout << "Enter your grade : ";
    cin >> grade;
    cout << "\n\n";
    cout << (grade >= 75 ? "You Passed." : "You Failed.");
    cout << "\n\n";
     if (grade >= 75) {
         cout << "You Passed.";
     }
     else {
         cout << "You Failed.";
     }
    cout << "\n\n";
    system("pause");
}