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


Payroll System in Java Using Text File

In this article I would like to showcase the work of my best friend and programming buddy Mr. Bernie Saligumba he is a programmer just like me that has a great passion in learning specially in writing codes. He called this program payroll system in Java using text file as the depository of records.

 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.


Program Listing

//SALIGUMBA BERNIE//

import java.util.*;
import java.io.*;
import java.text.*;

class salary
{public double s(double rate,double hrs)
 {double sal=0;
  sal=(rate*hrs)/8;
  return sal;}
}
class time_in_hrs
{public int inhrs(int hrs)
 {int gen_in_minus=0;
  if(hrs<=805)
  {gen_in_minus=4;}
  else
  {gen_in_minus=12-(hrs/100);}
 return gen_in_minus;}
}
class time_out_hrs
{public int outhrs(int hrs)
 {int gen_out_minus=0;
  gen_out_minus=(hrs/100)-13;
  return gen_out_minus; }
}
class time_in_mins
{public double mins(int hrs)
 {int tmins=0;
  if(hrs<=805)
  {tmins=0;}
  else
  {tmins=hrs%100;}
  return tmins;}
}
class time_out_mins
{public double mouts(int hrs)
 {int tmins=0,m=0;
  tmins=hrs%100;
  if(tmins==0)
  {m=0;}
  else
  {m=60-tmins;}
  return m;}
}
class flxhrs
{public int flx_hrs(int hrs)
 {int gen_in_minus=0;
  gen_in_minus=hrs/100;
  return gen_in_minus;}
 }
class flx_mins_in
{public double flxmins(int hrs)
 {int tmins=0;
  if(hrs<805)
  {tmins=0;}
  else
  {tmins=hrs%100;}
  return tmins;}
 }
class flx_mins_out
{public double flxmouts(int hrs)
 {int tmins=0,m=0;
  tmins=hrs%100;
  if(tmins==0)
  {m=0;}
  else
  {m=60-tmins;}
  return m;}
 }

public class payroll1
{ public static void main(String[] args) throws IOException
    {String read;
     double ss=0, rate=0;
     int lop;
     String day[]={"Monday","Tuesday","Wednesday","Thursday","Friday"};
     String in="",out="",date="";

     double mon_in_hrs=0, mon_out_hrs=0, mon_in_mins=0, mon_out_mins=0,
     total_flxhrs1=0, total_flxhrs2=0, total_mins1=0, total_mins2=0,
             a_flxhrs=0,total_hrs1=0,total_hrs2=0,
             a_hrs=0,overallmins=0,a_mins=0,overall=0,tothrs=0;

     salary sals = new salary();
     time_in_hrs tih = new time_in_hrs();
     time_out_hrs toh = new time_out_hrs();
     time_in_mins tim = new time_in_mins();
     time_out_mins tom = new time_out_mins();
     flxhrs fhrs = new flxhrs();
     flx_mins_in fminsin= new  flx_mins_in();
     flx_mins_out fminsout = new  flx_mins_out();

     FileReader fr = new FileReader("employee.txt");
     BufferedReader br = new BufferedReader(fr);
     FileWriter fw = new FileWriter("DTR.txt",true);
     BufferedWriter bw = new BufferedWriter(fw);
     NumberFormat nf = new DecimalFormat("###,##0.00");

     System.out.print("\n CODE: ");
     Scanner cod=new Scanner(System.in);
     String code = cod.next();

     while((read=br.readLine())!=null)
     {String arr[]=read.split(",");
      if(code.equals(arr[1]))
      {System.out.print("\nEmployee name  : "+arr[0]);
       System.out.print("\nEmployee code  : "+arr[1]);
       System.out.print("\nEmployee level : "+arr[2]);

       if(arr[2].equals("1"))
       {rate=480.00;
        System.out.print("\n Employee  rate : "+nf.format(rate));
       }
       if(arr[2].equals("2"))
       {rate=580.00;
        System.out.print("\n Employee rate : "+nf.format(rate));
       }
       if(arr[2].equals("3"))
       {rate=700.00;
        System.out.print("\n Employee rate : "+nf.format(rate));
       }
       arr[1] = arr[1]+""; bw.write(arr[1]);
       System.out.println("");
       for(lop=0;lop<5;lop++)
       {System.out.print("\nDTR FOR "+day[lop]);
        System.out.print("\nLog_in: ");
        Scanner lin = new Scanner(System.in);
        in = lin.next();
        System.out.print("Log_out: ");
        Scanner lout = new Scanner(System.in);
        out = lout.next();

        String r_arr[]=in.split(":"); String r_arr1[]=out.split(":");
        int mon_in = Integer.parseInt(r_arr[0]+r_arr[1]);
        int mon_out = Integer.parseInt(r_arr1[0]+r_arr1[1]);

        if(mon_in>=800 && mon_out <=1200)
        {mon_in_hrs=fhrs.flx_hrs(mon_in);
         mon_out_hrs=fhrs.flx_hrs(mon_out);
         mon_in_mins=fminsin.flxmins(mon_in);
         mon_out_mins=fminsout.flxmouts(mon_out);

         total_flxhrs1=total_flxhrs1+mon_in_hrs;
         total_flxhrs2=total_flxhrs2+mon_out_hrs;
         a_flxhrs=total_hrs2-total_hrs1;
         total_mins1= total_mins1+mon_in_mins;
         total_mins2= total_mins2+mon_out_mins;
        }else if(mon_in>=1300 && mon_out <=1700)
        {mon_in_hrs=fhrs.flx_hrs(mon_in);
         mon_out_hrs=fhrs.flx_hrs(mon_out);
         mon_in_mins=fminsin.flxmins(mon_in);
         mon_out_mins=fminsout.flxmouts(mon_out);

         total_flxhrs1=total_flxhrs1+mon_in_hrs;
         total_flxhrs2=total_flxhrs2+mon_out_hrs;
         total_mins1= total_mins1+mon_in_mins;
         total_mins2= total_mins2+mon_out_mins;
         }else{
         mon_in_hrs=tih.inhrs(mon_in);
         mon_out_hrs=toh.outhrs(mon_out);
         mon_in_mins=tim.mins(mon_in);
         mon_out_mins=tom.mouts(mon_out);
         total_hrs1=total_hrs1+mon_in_hrs;
         total_hrs2=total_hrs2+mon_out_hrs;
         total_mins1= total_mins1+mon_in_mins;
         total_mins2= total_mins2+mon_out_mins;
         }
        in = in+";"; out = out+";";
        bw.write(in); bw.write(out);

       a_hrs = total_hrs1+total_hrs2;
       a_flxhrs = total_flxhrs2-total_flxhrs1;
       overallmins = (total_mins1-total_mins2)/60;

       a_mins = a_hrs- overallmins;

       overall =a_mins+a_flxhrs;
       tothrs = overall;

       ss = sals.s(rate, tothrs);

       }
       System.out.print("\nPayroll date  : ");
       Scanner dte = new Scanner(System.in);
       date = dte.next();

       System.out.print("\nEEmployee name  : "+arr[0]);
       System.out.print("\nEmployee  code  : "+arr[1]);
       System.out.print("\nEmployee  level : "+arr[2]);
       System.out.print("\nEmployee  rate  : "+nf.format(rate));
       System.out.print("\nEmployee  hours : "+nf.format(tothrs));
       System.out.print("\nEmployee salary : "+nf.format(ss));
       System.out.print("\nPayroll  date   : "+date);
       System.out.println("");
     }

  }
fr.close(); bw.close();
}

}

dtr.txt

A02-00058:00;17:00;7:59;17:00;8:23;17:00;8:00;17:00;8:00;17:00;

employee.txt

Juan_Santiago,A02-0001,2
Maricel_Trojillo,A02-0002,3
Vicky_Soberano,A02-0003,1
Garry_Lapinig,A0-0004,2
Franco_Castillo,A02-0005,3



Square Number Values in C language


We are started learning how to write a computer program we learn the fundamentals of programming. This fundamentals are very important because we cannot solve the problem without proper understanding the basic concepts of programming. One of the basic concepts is the study of sequence, variable declarations and the use of iteration or looping statements.  When we talking about sequence we are referring the basic structure of our program the library statements that we declare prior we declare any single variable in our program. 

As a programmer it is also our responsibility to know and understand what type of variables and its corresponding data types to be used in our program. If we don’t know the variable and data type we can use we can generate errors in our program by providing erroneous data and the output information that will generate by our program in also incorrect.

As we said our computer is a tool and machine very dependent to its users and the programs that runs on it. I have also mention the use of iteration or looping statements. This structure in programming is very important also because it minimize the number of lines of code that we use in our program by using this structure we can cut down the number of lines of our codes and the repetitive commands and routine that our program will be perform.

In this article I will discuss another program that I wrote for my class programming activity using C programming language I called this program Square Number Values. This program is very simple yet it show how to use variable declaration, the use of pointers and string declaration. What the program will do is to ask or prompts the user to enter five numbers and then the program will square those values that are being provided by the user and then display the result in the screen. The compiler that I used in this program in Code::Block editor that has a build in compiler called Dev C++ that is freely available to download over the Internet free from any charge.

The first portion of our program code is that it will accept input values from the user. For your information I declare three variables in our program the x,y and the character pointer string that I named words which is also declared as one dimensional array.  What is pointer string will do every time our looping statement run or execute it put string value for example 1 it will attach the string value of st so the output will be 1st, 2nd,3rd,4th and finally the 5th for the input values for the user given to our program.

#include <stdio.h>
#include <stdlib.h>

main()
{
    int x=0,y=0;
    char *words[5] = {"st", "nd","rd","th","th"};
    int values[5];
       printf("\n\n");
       printf("\t ======[SQUARE NUMBER VALUES]=======");
       printf("\n\n");
       for (x=0; x<5; x++)
       {
        printf("Enter %d%s Number : ",x+1,words[x]);
        scanf("%d",&values[x]);
       }

Here is the second and the last portion of our program code what our program will do is to list the values given by the user and then our program will multiply the number b y itself in order to generate its square value equivalent again we are using one dimensional array as our data structure just to gather whose values previously given by our user of our program and also to display the list of values and its computed square values. After that our program will thank the user for using our program and will terminated the operation of our program and return to our windows operating system.

  printf("\n\n");
    printf(" Original Value     Square Values");
    printf("\n\n");
       for (x=0; x<5; x++)
        {
           printf("\n %7d      %13d",values[x], values[x] * values[x]);
        }
    printf("\n\n");
    printf("\t Thank you for using this program.");
    printf("\n\n");
    system("pause");
}

I hope in this article you have learned something the use of variable declaration, understand the usage of pointers and strings and finally the iteration and looping statements to generate square number values. If you have some questions feel free send me an email I am very glad to answer your questions about the articles that I wrote in this website.

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

#include <stdio.h>
#include <stdlib.h>

main()
{
    int x=0,y=0;
    char *words[5] = {"st", "nd","rd","th","th"};
    int values[5];
       printf("\n\n");
       printf("\t ======[SQUARE NUMBER VALUES]=======");
       printf("\n\n");
       for (x=0; x<5; x++)
       {
        printf("Enter %d%s Number : ",x+1,words[x]);
        scanf("%d",&values[x]);
       }
    printf("\n\n");
    printf(" Original Value     Square Values");
    printf("\n\n");
       for (x=0; x<5; x++)
        {
           printf("\n %7d      %13d",values[x], values[x] * values[x]);
        }
    printf("\n\n");
    printf("\t Thank you for using this program.");
    printf("\n\n");
    system("pause");
}


Perfect Number Generator in Java

In this article I would like to share with you a sample program that I wrote in my spare time I called this program Perfect Number Generator in Java. According to Wikipedia.org a perfect number is defined as in number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum).

What does our program will do is to ask the user to enter a number as our range from the given number our program will list down the numbers that is belong to perfect number. By the way I am using Netbeans as my text editor in this program a good text editor that is very user friendly to use and best of all it is free to download from the Internet because it is open source.

The program is very simple and easy to understand. I hope you will find my work useful in learning how to program in Java. 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

import java.util.Scanner;  

class perfect_number
{
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
       System.out.print("\t\t    PERFECT NUMBER GENERATOR ");
       System.out.print("\n");
       System.out.print("\nKindly enter a Number ? :");
        long range_number=input.nextLong();
        System.out.println("\nThe perfect numbers from 1 and "+range_number+" are:");
        System.out.println();
        for(int b=1;b<range_number;b++)
        {
            int sum = 0;
            {
                for(int a=1;a<b;a++)
                {
                    if(b%a == 0)
                    {
                        sum+=a;
                    }
                }
                if(sum == b)
                {
                   
                    System.out.print(" "+ b + " ");
                }
            }
        }
       System.out.println("\n");
       System.out.println("\t\t END OF PROGRAM");     
       System.out.println("\n"); 
    }
       
}





Tuesday, July 7, 2015

Highest and Smaller Number in Java

One of the most interesting problem in programming is to ask the user to enter a series of number and then our program will determine which of the given number is the smallest and the highest number from the series of number by the user. Normally the data structure that we will use in this problem is array to be specific one dimensional array so to speak and then we will use for loop statement and if statement to compare each numbers and to check which of the given number is the smallest and highest.

I called this program Highest and Smallest Number in Java what the program does is to prompt or ask the user how many numbers to be accepted and to be process. After the user provide the values in our program it will compare and determine what is the smallest and the highest in a given list of values.

The program is very simple and easy to understand. I hope you will find my work useful in learning how to program in Java. 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

// smallest_biggest_number.java
// Written By: Mr. Jake R. Pomperada, MAED-IT
// Date : July 7, 2015
// Email Address: jakerpomperada@yahoo.com
//                            jakerpomperada@gmail.com

// Problem : Write a program in Java that will check what is the highest and
//           lowest number given by the user using one dimensional array.

import java.util.Scanner;  

public class smallest_biggest_number {
    
    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);
       
        int[] num= new int[10];
       
       System.out.print("\t\t    SMALLEST AND HIGHEST NUMBER ");
       System.out.print("\n\n");
       System.out.print("How many items ? : ");
       int n=input.nextInt();
       int smallest = Integer.MAX_VALUE;
       int biggest =Integer.MIN_VALUE;
      
       for(int i =0;i<n;i++) {
            int y=i+1;
            System.out.print("Enter item value no. " + y  + " value : ");
            num[i]=input.nextInt();
            if(num[i] < smallest) {

             smallest = num[i];

            }
            if (num[i] > biggest) {
                biggest = num[i];
               }

        }
       System.out.println();
       System.out.println("The Smallest number is  " +smallest + ".");
       System.out.println("The Biggest number is   " +biggest +".");
       System.out.println();
       System.out.println("\t\t END OF PROGRAM");     
       System.out.println("\n\n");
    }

}