Sunday, July 12, 2015

Student Grading System in PHP and MySQL

Most of my career as programmer spend developing programs using PHP and MySQL. In this article I would like to share my program that I wrote a long time ago I called this program Student Grading System in PHP and MySQL. This program will compute and store the grades of the student in MySQL.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

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

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

grade.php


<?php
  /* Student Grade System
     Author : Jake R. Pomperada
Date   : October 5, 2011 Wednesday
Tool   : PHP/MySQL
 */  

  // Block any possible error from the browser
  error_reporting(0);
?>
<?php 
   
     $name =$_REQUEST['name']; 
$course = $_REQUEST['course']; 
$sex = $_REQUEST['sex'];
$department = $_REQUEST['department'];   
$subject =$_REQUEST['subject']; 
$contact =  $_REQUEST['contact']; 
       
   
  if (isset($_REQUEST['solve']))
       {
  
  $prelim = $_REQUEST['prelim'];
  $midterm = $_REQUEST['midterm'];
       $final = $_REQUEST['final']; 
  
   $solve1 = ($_REQUEST['prelim'] * 0.2);
$solve2 = ($_REQUEST['midterm'] * 0.3);
$solve3 = ($_REQUEST['final'] * 0.5);
$add = ($solve1 + $solve2 + $solve3);
$endterm = round($add);
if ($add >= 75) 
  {
          $remarks = "PASSED";
        }
       else {
           $remarks = "FAILED";
       }
}
if (isset($_REQUEST['clear']))
       {
  $name = ""; 
  $course = ""; 
    $subject="";
  $department = ""; 
  $contact =  "";  
  $prelim = "";
  $midterm = "";
       $final = ""; 
       $endterm = "";
  $remarks = ""; 
       }
  
if (isset($_REQUEST['save']))
       {
 
$name = strtoupper($_REQUEST['course']);
$course = strtoupper($_REQUEST['course']);
$deparment = strtoupper($_REQUEST['department']);
$sex = strtoupper($_REQUEST['sex']);
$contact = $_REQUEST['contact'];
$prelim = $_REQUEST['prelim'];
$midterm = $_REQUEST['midterm'];
$final = $_REQUEST['final'];
$endterm = $_REQUEST['endterm'];
$remarks = strtoupper($_REQUEST['remarks']);

//CONNECT TO DATABASE--------------------
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("grade", $con);
 
/*
 *  Specify the field names that are in the form. This is meant 
 *  for security so that someone can't send whatever they want 
 *  to the form.
 */
$allowedFields = array(
'name',
'course',
'subject',
'department',
'contact',
'prelim',
'midterm',
'final',
'endterm',
'remarks'
);
// Specify the field names that you want to require...
$requiredFields = array(
'name',
'course',
'subject',
'department',
'contact',
'prelim',
'midterm',
'final'
);

$errors = array();
foreach($_POST AS $key => $value)
{
// first need to make sure this is an allowed field
if(in_array($key, $allowedFields))
{
$$key = $value;
// is this a required field?
if(in_array($key, $requiredFields) && $value == '')
{
$errors[] = "The field $key is required.";
}
}
}

// were there any errors?
if(count($errors) > 0)
{
$errorString = '<p>There was an error processing the form.</p>';
$errorString .= '<ul>';
foreach($errors as $error)
{
$errorString .= "<li>$error</li>";
}
$errorString .= '</ul>';

echo  $errorString;
  }
  else {
  $sql = "INSERT INTO info ";
  $sql .= " (name,course,subject,department,gender,contact,prelim";
  $sql .= "  ,midterm,final,endterm,remarks)";
  $sql .= "VALUES";
  $sql .= "('$name', '$course', '$subject', '$department', '$sex'";
  $sql .= " ,'$contact','$prelim','$midterm','$final','$endterm','$remarks')";
  
if(!$b=mysql_query($sql)){
echo mysql_error();
}
else {
   echo "<center>";
echo "<h4> Record is Successfully added in the Database.</h4>";
echo "</center>";
   }
    }
  }
?>
 
<html>
<head>
 <STYLE type="text/css">
     
      h2 { 
        text-align:center;
color: white;                /* text color is white */ 
        background: green;            /* Content, padding will be blue */
        margin: 12px 12px 12px 30px;
        padding: 12px 0px 12px 12px; /* Note 0px padding right */
        list-style: none             /* no glyphs before a list item */
                                     /* No borders set */
      }
     
    </STYLE>
</head>
<body>
<h2> <marquee direction=left behavior=alternate>
 ABC College Student Grading System </marquee> </h2>
<br>
<FORM NAME="form1" METHOD="POST" ACTION="">
<TABLE BORDER="0">
  <tr> </tr> <tr> </tr>
  <TR>
    <TD>Student Name</TD>
    <TD>
      <INPUT TYPE="TEXT" NAME="name" SIZE="30"MAXLENGTH=30
   value="<?php echo $name; ?>">
 
 
      <TD>  Course</TD>
    <TD>
      <INPUT TYPE="TEXT" NAME="course" SIZE="33" MAXLENGTH=35
 value="<?php echo $course; ?>">
 </TD>
    </TR>
    <tr> </tr> <tr> </tr>
<tr> </tr> <tr> </tr>
  
  <TR>
    <TD>Prelim Grade</TD>
    <TD><INPUT TYPE="TEXT" NAME="prelim" SIZE="1"  MAXLENGTH=3
  value="<?php echo $prelim; ?>">
  
</TD>
<TD>Subject</TD>
    <TD>
      <INPUT TYPE="TEXT" NAME="subject" SIZE="35" MAXLENGTH=35
   value="<?php echo $subject; ?>">
 </TD>
      </TR> 
     <tr> </tr> <tr> </tr>
<tr> </tr> <tr> </tr>
  <TR>
    <TD>Midterm Grade</TD>
    <TD><INPUT TYPE="TEXT" NAME="midterm" SIZE="1" MAXLENGTH=3
   value="<?php echo $midterm; ?>">
</TD>
    <TD>Department</TD>
     <TD>
      <INPUT TYPE="TEXT" NAME="department" SIZE="40" MAXLENGTH=40
  value="<?php echo $department; ?>">
  </TD>
  </TR>
     <tr> </tr> <tr> </tr>
<tr> </tr> <tr> </tr>
<TR>
    <TD>Final Grade</TD>
    <TD><INPUT TYPE="TEXT" NAME="final" SIZE="1" MAXLENGTH=3
  value="<?php echo $final; ?>">
</TD>
     <TD>Gender</TD>
<td> <select name="sex"> 
<option>Male</option>
<option>Female</option>
</select>
      </td>
   </tr>
<tr> </tr> <tr> </tr>
<tr> </tr> <tr> </tr>
<tr>
   <TD>Endterm Grade</TD>
    <TD><INPUT TYPE="TEXT" NAME="endterm" SIZE="1" MAXLENGTH=3
   value="<?php echo $endterm; ?>" READONLY>
</TD>
    <TD>Contact Number</TD>
    <TD>
      <INPUT TYPE="TEXT" NAME="contact" SIZE="15" MAXLENGTH=15
 value="<?php echo $contact; ?>">
 </TD>
</tr>
    <tr> </tr> <tr> </tr>
<tr> </tr> <tr> </tr>
  <tr>
<TD>Remarks</TD>
    <TD>
      <INPUT TYPE="TEXT" NAME="remarks" SIZE="10" 
   value="<?php echo $remarks; ?>" READONLY>
 </TD>
     </TR>
    </TABLE>
  <!-- End of the Table -->
  
<P><input type="submit" name="solve" value="Compute"> 
<input type="submit" name="clear" value=" Clear ">
<input type="submit" name="save" value=" Save  ">
</P>
</FORM>
</body>
</html>


grade.sql

-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Oct 05, 2011 at 12:11 PM
-- Server version: 5.1.36
-- PHP Version: 5.3.0

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `grade`
--

-- --------------------------------------------------------

--
-- Table structure for table `info`
--

CREATE TABLE IF NOT EXISTS `info` (
  `name` varchar(100) NOT NULL,
  `course` varchar(100) NOT NULL,
  `subject` varchar(100) NOT NULL,
  `department` varchar(100) NOT NULL,
  `gender` varchar(100) NOT NULL,
  `contact` int(15) NOT NULL,
  `prelim` int(3) NOT NULL,
  `midterm` int(3) NOT NULL,
  `final` int(3) NOT NULL,
  `endterm` int(3) NOT NULL,
  `remarks` varchar(10) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `info`
--

INSERT INTO `info` (`name`, `course`, `subject`, `department`, `gender`, `contact`, `prelim`, `midterm`, `final`, `endterm`, `remarks`) VALUES
('Jake Pomperada', 'BS Computer Science', 'Pascal Programming', 'Commerce', 'MALE', 4335081, 78, 89, 95, 90, 'PASSED'),
('Ma. Junallie Fuentebella', 'BS Chemical Engineering', 'Chemistry 1', 'Engineering', 'FEMALE', 4335675, 89, 78, 100, 91, 'PASSED'),
('Ana Tan', 'BS Accountancy', 'Financial Management', 'Commerce', 'FEMALE', 7078423, 78, 78, 79, 79, 'PASSED'),
('Tita Swarding', 'Mass Communication', 'Basic Journalism', 'Arts and Sciences', 'FEMALE', 7546348, 87, 89, 94, 91, 'PASSED'),
('Vincent Qui', 'BS Business Management', 'Accouting 101', 'Commerce', 'MALE', 999237563, 74, 83, 84, 82, 'PASSED'),
('Boy Cruz', 'BS Mathematics', 'Calculus', 'Education', 'MALE', 4567812, 65, 72, 76, 73, 'FAILED'),
('Juan Tamad', 'BS Secondary Education', 'Physical Education', 'Education', 'MALE', 4235562, 73, 65, 71, 70, 'FAILED');



Thursday, July 9, 2015

Least Common Multiple (LCM) Solver in Java

This sample program that I wrote in Java programming language will ask the user to enter two numbers and then our program will compute and determine the least common multiple or LCM of the two numbers being provided by our user.


Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

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

Thank you very much and Happy Programming.




Sample Program Output

Program Listing

// lcm.java
// Written By: Mr. Jake R. Pomperada, BSCS, MAED-IT
// July 9, 2015   Thursday
// Email Address:  jakerpomperada@gmail.com 
//                 jakerpomperada@yahoo.com

import java.util.Scanner;

public class lcm {

    public static void find_lcm(int x, int y)
    {
        int max=0,min=0,z=0,lcm=1;
  if(x>y)
    {
    max=x;
    min=y;
    }
    else
    {
    max=x;
    min=y;
    }

for(int i=1;i<=min;i++)
   {
    z=max*i; 
    if(z%min==0) 
     {
      lcm=z; 
      break; 
     }
    }
    System.out.println();
    System.out.println("The Least Common Multiple (LCM) of "+ x 
                   + " and " + y +  " is = " + lcm + ".");
    }

    
   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
        
      char ch;
      int first_value=0;
      int second_value=0;
 do {
      System.out.println();
      System.out.print("\t LEAST COMMON MULTIPLE (LCM) SOLVER ");
      System.out.println("\n");
      
      System.out.print("Kindly give the first number  : "); 
      first_value = input.nextInt();
      
      System.out.print("Kindly give the second number : "); 
      second_value = input.nextInt();

      find_lcm(first_value,second_value);
      System.out.print("\nDo you want to continue (Type y or n) : ");
      ch = input.next().charAt(0);                        
     } while (ch == 'Y'|| ch == 'y');  
      System.out.println();
      System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
      System.out.println("\n\n");
   }

}


Area of a Triangle in Java

In this article I would like to share with you a sample program that I wrote in Java programming language I called this program Area of a Triangle in Java that will compute the are of the triangle based on the based and height of the triangle given by the user.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

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

Thank you very much and Happy Programming.



Sample Program Output

Program Listing

// area_of_the_triangle.java
// Written By: Mr. Jake R. Pomperada, BSCS, MAED-IT
// July 9, 2015   Thursday
// Email Address:  jakerpomperada@gmail.com 
//                 jakerpomperada@yahoo.com

import java.util.Scanner;
 
public class area_of_the_triangle {
 
   public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
        
      char ch;
      double base_triangle = 0;
      double height_triangle = 0;
      double solve_area = 0;
 do {
      System.out.println();
      System.out.print("\tAREA OF THE TRIANGLE SOLVER ");
      System.out.println("\n\n");
      System.out.print("What is the length of base of the triangle : "); 
      base_triangle = input.nextDouble();
 
      System.out.print("What is the length of height of triangle : "); 
      height_triangle = input.nextDouble();
 
      solve_area = (base_triangle * height_triangle) / 2;
      
      System.out.println();
      System.out.println("The Area of Triangle is : " + solve_area + ".");
      System.out.println();
      System.out.print("\nDo you want to continue (Type y or n) : ");
      ch = input.next().charAt(0);                        
     } while (ch == 'Y'|| ch == 'y');  
      System.out.println();
      System.out.print("\t THANK YOU FOR USING THIS PROGRAM");
      System.out.println("\n\n");
   }
 
}

Wednesday, July 8, 2015

Telephone Billing Management System in C

In this article I would like to share with you a program that I wrote a long time ago using C language I called this program Telephone Billing Management System in C. I am using Turbo C 2.0 in DOS in in writing this program it saves, computes the billing statements of the consumer of a telephone company it store the record in a flat file also know as text file.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

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

Thank you very much and Happy Programming.



Sample Program Output


Program Output

#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<windows.h>
#include<stdlib.h>
struct subscriber
{
char phonenumber[20];
char name[50];
float amount;
}s;
void addrecords();
void listrecords();
void modifyrecords();
void deleterecords();
void searchrecords();
void payment();
char get;
int main()
{
int phonenumber;
char choice;


while (1)
{
system("cls");

printf("\n     **********************************************");
printf("\n    ****  TELEPHONE BILLING MANAGEMENT SYSTEM  ****");
printf("\n    ***********************************************");
  printf("\n");
      printf("\n\t A : Adding new records.\n \t L : Listing of records");
printf("\n\t M : Modifying records.\n \t P : Payments");
printf("\n\t S : Searching records.");
printf("\n\t D : Deleting records.\n\t E : Exit Program\n");
  printf("\n");
  printf("\n\t PLEASE SELECT THE LETTERS ONLY " );
choice=getche();
choice=toupper(choice);
switch(choice)
{
case 'P':
payment();break;
case 'A' :
addrecords();break;
case 'L' :
listrecords();break;
case 'M':
modifyrecords();break;
case 'S' :
searchrecords();break;
case 'D':
deleterecords();break;
case 'E':
system("cls");
printf("\n\n\t\t\t\tTHANK YOU");
printf("\n\n\n\n\n:\n\tFOR USING OUR SERVICE");
Sleep(2000);
exit(0);
break;
default:
system("cls");
printf("Incorrect Input");
printf("\nAny key to continue");
getch();
}
}
}
void addrecords()
{
FILE *f;
char test;
f=fopen("data.dat","ab+");
if(f==0)
{   f=fopen("data.dat","wb+");
system("cls");
printf("please wait while we configure your computer");
printf("/npress any key to continue");
getch();
}
while(1)
{
system("cls");
printf("\n Enter phone number:");
scanf("%s",&s.phonenumber);
printf("\n Enter name:");
fflush(stdin);
scanf("%[^\n]",&s.name);
printf("\n Enter amount:");
scanf("%f",&s.amount);
fwrite(&s,sizeof(s),1,f);
fflush(stdin);
system("cls");
printf("1 record successfully added");
printf("\n Press esc key to exit, any other key to add other record:");
test=getche();
if(test==27)
break;
}
fclose(f);
}
void listrecords()
{
FILE *f;
int i;
if((f=fopen("data.dat","rb"))==NULL)
exit(0);
system("cls");
printf("Phone Number\t\tUser Name\t\t\tAmount\n");
for(i=0;i<79;i++)
printf("-");
while(fread(&s,sizeof(s),1,f)==1)
{
printf("\n%-10s\t\t%-20s\t\t $. %.2f /-",s.phonenumber,s.name,s.amount);
}
printf("\n");
for(i=0;i<79;i++)
printf("-");

fclose(f);
getch();
}
void deleterecords()
{
FILE *f,*t;
int i=1;
char phonenumber[20];
if((t=fopen("temp.dat","w+"))==NULL)
exit(0);
if((f=fopen("data.dat","rb"))==NULL)
exit(0);
system("cls");
printf("Enter the phone number to be deleted from the Database");
fflush(stdin);
scanf("%[^\n]",phonenumber);
while(fread(&s,sizeof(s),1,f)==1)
{
if(strcmp(s.phonenumber,phonenumber)==0)
{       i=0;
continue;

}
else
fwrite(&s,sizeof(s),1,t);
}
if(i==1)
{       system("cls");
printf("Phone number \"%s\" not found",phonenumber);
remove("data.dat");
rename("temp.dat","data.dat");
getch();
fclose(f);
fclose(t);
main();
}
remove("data.dat");
rename("temp.dat","file.dat");
system("cls");
printf("The Number %s Successfully Deleted!!!!",phonenumber);
fclose(f);
fclose(t);
getch();
}
void searchrecords()
{
FILE *f;
char phonenumber[20];
int flag=1;
f=fopen("data.dat","rb+");
if(f==0)
exit(0);
fflush(stdin);
system("cls");
printf("Enter Phone Number to search in our database");
scanf("%s", phonenumber);
while(fread(&s,sizeof(s),1,f)==1)
{
if(strcmp(s.phonenumber,phonenumber)==0)
{ system("cls");
printf(" Record Found ");
printf("\n\nPhonenumber: %s\nName: %s\nAmount: $ %0.2f\n",s.phonenumber,s.name,s.amount);
flag=0;
break;
}
else if(flag==1)
{ system("cls");
printf("Requested Phone Number Not found in our database");
}
}
getch();
fclose(f);
}
void modifyrecords()
{
FILE *f;
char phonenumber[20];
long int size=sizeof(s);
if((f=fopen("data.dat","rb+"))==NULL)
exit(0);
system("cls");
printf("Enter phone number of the subscriber to modify:");
scanf("%[^\n]",phonenumber);
fflush(stdin);
while(fread(&s,sizeof(s),1,f)==1)
{
if(strcmp(s.phonenumber,phonenumber)==0)
{
system("cls");
printf("\n Enter phone number:");
scanf("%s",&s.phonenumber);
printf("\n Enter name: ");
fflush(stdin);
scanf("%[^\n]",&s.name);
printf("\n Enter amount: ");
scanf("%f",&s.amount);
fseek(f,-size,SEEK_CUR);
fwrite(&s,sizeof(s),1,f);
break;
}
}
fclose(f);
}
void payment()
{
FILE *f;
char phonenumber[20];
long int size=sizeof(s);
float amt;
int i;
if((f=fopen("data.dat","rb+"))==NULL)
exit(0);
system("cls");
printf("Enter phone number of the subscriber for payment");
scanf("%[^\n]",phonenumber);
fflush(stdin);
while(fread(&s,sizeof(s),1,f)==1)
{
if(strcmp(s.phonenumber,phonenumber)==0)
{
system("cls");
printf("\n Phone No.: %s",s.phonenumber);
printf("\n Name: %s",s.name);
printf("\n Current amount: %f",s.amount);
printf("\n");
for(i=0;i<79;i++)
printf("-");
printf("\n\nEnter amount of payment :");
fflush(stdin);
scanf(" %f",&amt);
s.amount=(amt-s.amount);
fseek(f,-size,SEEK_CUR);
fwrite(&s,sizeof(s),1,f);
break;
}
}
system("cls");
printf("THANK YOU %s FOR YOUR TIMELY PAYMENTS",s.name);
getch();
fclose(f);
}