Sunday, September 11, 2016

Prime Number Checker in Delphi

A program that I wrote using Delphi to accept a number from the user and then our program will check and determine if the given number is a Prime 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

unit prime;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Label3: TLabel;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


function ISPrime(const vlNumber: Integer): Boolean;
var
X: Integer;
vlPrime: Boolean;
begin
X := 2;
vlPrime := True;
While (X < vlNumber) and vlPrime do begin
vlPrime := ((vlNumber mod X) <> 0);
Inc(X);
end;
ISPrime := vlPrime;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
      if edit1.text ='' then
      begin
     ShowMessage('Emtpy not allow');
        Edit1.text :='';
        Label3.Caption := '';
        Edit1.SetFocus;
   end
       else if    ISPrime( strtoint(Edit1.Text))  then
     Begin

           Label3.Caption:= 'The number  ' + Edit1.Text
      + ' is a Prime Number'+'.'
      end
      else
      
           Label3.Caption:= 'The number  ' + Edit1.Text
      + ' is Not a Prime Number'+'.'

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Edit1.text :='';
  Label3.Caption := '';
  Edit1.SetFocus;
end;

end.

Odd and Even Number Checker in C#

A simple program that I wrote using C# to check if the given number by our user is Odd or Even numbers.

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

// Odd and Even Number Checker in C#
// September 11, 2016 Sunday
// Written By: Mr. Jake R. Pomperada, MAED-IT

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public static bool IsEven(int value)
        {
            return value % 2 == 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int number = 0;

            if (!int.TryParse(textBox1.Text, out number))
            {
                MessageBox.Show("I need just a number in the textbox.");
                textBox1.Text = "";
                label2.Text = "";
                textBox1.Focus();
            }

        else if (IsEven(number))
          {
              label2.Text = "The Number " + number + " is an Even Number.";

          }
          else
          {
              label2.Text = "The Number " + number+ " is an Odd Number.";
          }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            label2.Text = "";
            textBox1.Focus();
        }
    }
}



Saturday, September 10, 2016

Fahrenheit To Celsius in C#

In this article that I  written I wrote a simple program using C# that will ask the user to give temperature in Fahrenheit and then our program will convert it in Celsius temperature equivalent. I also included error trapping procedure to check if the the given value is a number or not. Feel free to use my code in your project in C#. In this sample program I am using Visual Studio 2010 as programming tool.


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

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace temperature
{
      

    public partial class Form1 : Form
    {

           
        public static double Fahrenheit_Celsius(double f)
  {
   return (5.0 / 9.0) * (f - 32);
  }
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double temp = 0.00;
            char degree = (char)176;

          if (!double.TryParse(textBox1.Text, out temp))
            {
                MessageBox.Show("I need just a number in the textbox.");
                textBox1.Text = "";
                textBox3.Text = "";
                textBox1.Focus();
            }
          
            double solve = Fahrenheit_Celsius(temp);
            
            textBox3.Text = solve.ToString("00.00") + degree + "C";
            textBox3.Enabled = false;
        }          
                     

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox3.Text = "";
            textBox1.Focus();
        }

       
    }
}


Friday, September 9, 2016

Decimal To Roman Numeral Converter in Delphi

In this article I would like to share with you a sample program that I wrote using Delphi version 6 as my programming language that will ask the user to give a number and then our program will convert the given decimal number by our user into roman numerals. 

The code is very short and easy to understand in Delphi.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
 
My mobile number here in the Philippines is 09173084360
.



Borland Delphi 6.0






Sample Program Output


Program Listing

unit romans;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Label5: TLabel;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function DecToRoman(Decimal: Longint): string;
const
  Numbers: array[1..13] of Integer =
    (1, 4, 5, 9, 10, 40, 50, 90, 100,
    400, 500, 900, 1000);
  Romans: array[1..13] of string =
    ('I', 'IV', 'V', 'IX', 'X', 'XL',
    'L', 'XC', 'C', 'CD', 'D', 'CM', 'M');
var
  i: Integer;
begin
  Result := '';
  for i := 13 downto 1 do
    while (Decimal >= Numbers[i]) do
    begin
      Decimal := Decimal - Numbers[i];
      Result  := Result + Romans[i];
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label5.Caption:= 'The equivalent value of ' + Edit1.Text
      + ' to Roman Numberal is ' + DecToRoman(StrToInt(Edit1.Text))+'.';
 end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Edit1.text :='';
Label5.Caption := '';
Edit1.SetFocus
end;

end.

Sunday, September 4, 2016

Binary To Decimal Converter in Delphi

I wrote this simple program that will ask the user to give a number in binary and then our program will convert the number to its decimal equivalent using Delphi as my programming language.

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

binary.pas 


unit binary;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Label3: TLabel;
    Button2: TButton;
    Label4: TLabel;
    Label5: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
     
  end;

var
  Form1: TForm1;


implementation

{$R *.dfm}

   function Pow(i, k: Integer): Integer;
var
  j, Count: Integer;
begin
  if k>0 then j:=2
    else j:=1;
  for Count:=1 to k-1 do
    j:=j*2;
  Result:=j;
end;

function BinToDec(Str: string): Integer;
var
  Len, Res, i: Integer;
  Error: Boolean;
begin
  Error:=False;
  Len:=Length(Str);
  Res:=0;
  for i:=1 to Len do
    if (Str[i]='0')or(Str[i]='1') then
      Res:=Res+Pow(2, Len-i)*StrToInt(Str[i])
    else
    begin
      MessageDlg('It is not a binary number', mtInformation, [mbOK], 0);
      Error:=True;
      Break;
    end;
  if Error=True then Result:=0
    else Result:=Res;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin

   if edit1.text ='' then
      begin
     ShowMessage('Emtpy not allow');
        Edit1.text :='';
        Label3.Caption := '';
        Edit1.SetFocus;
   end
     else
           Label3.Caption:= 'The equivalent value of ' + Edit1.Text
      + ' to Binary is ' + IntToStr(BinToDec(Edit1.Text))+'.'

      End;

procedure TForm1.Button2Click(Sender: TObject);
begin
Edit1.text :='';
Label3.Caption := '';
Edit1.SetFocus
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
button1.Hint := 'Click here to convert binary number into its decimal equivalent.';
button1.ShowHint := true;
end;

end.



Decimal To Binary Converter in Delphi

I wrote this simple program that will ask the user to give a number in decimal and then our program will convert the number to its binary equivalent using Delphi as my programming language.

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

dec.pas

unit dec;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    Label3: TLabel;
    Button2: TButton;
    Label4: TLabel;
    Label5: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
     function DecToBinStr(N: Integer): string;
  end;

var
  Form1: TForm1;
    Negative: Boolean;

implementation

{$R *.dfm}


function TForm1.DecToBinStr(N: Integer): string;
var
  S: string;
  i: Integer;

begin
  if N<0 then
    Negative:=True;
  N:=Abs(N);
  for i:=1 to SizeOf(N)*8 do
  begin
    if N<0 then
      S:=S+'1'
    else
      S:=S+'0';
    N:=N shl 1;
  end;
  Delete(S, 1, Pos('1', S)-1);
  if Negative then
    S:='-'+S;
  Result:=S;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
      Label3.Caption:= 'The equivalent value of ' + Edit1.Text
      + ' to Binary is ' + DecToBinStr(StrToInt(Edit1.Text))+'.';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Edit1.text :='';
Label3.Caption := '';
Edit1.SetFocus
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
button1.Hint := 'Click here to convert decimal number into its binary equivalent.';
button1.ShowHint := true;
end;

end.






Saturday, September 3, 2016

Selection Sort in C++

A program that I wrote a long time ago in my C++ programming class in college to perform selection sort. The code is very simple and easy to 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 <iostream>

using namespace std;

#define MAX 5

void SelSort(int X[],int start,int stop)
{
   int begin=start;
   int smallsofar=begin;
   int tmp;

   if(start<stop)
   {
        for(int i=begin+1;i<=stop;i++)
      {
           if(X[i] < X[smallsofar])
              smallsofar=i;
      }
      tmp=X[begin];
      X[begin]=X[smallsofar];
      X[smallsofar]=tmp;

      SelSort(X,start+1,stop);
   }
}

int main()
{
   int abc[MAX];
    cout << "\t\t\t      SELECTION SORT IN C++";
    cout << "\n\t\t Created By: Mr. Jake R. Pomperada, MAED-IT";
    cout << "\n\n";   
   for(int i=0;i<5;i++) {

    cout << "Enter Item No.:" << i+1 << ":";
    cin >> abc[i];
   }
   cout << "\n\t Original Arrangement of Numbers";
   cout << "\n\n";
   for(int i=0;i<5;i++)
        {

        cout << "\t " << abc[i] << " ";
           }

   SelSort(abc,0,MAX-1);
   cout << "\n";
   cout << "\n\t Sorted Arragmenent  of Number";
   cout << "\n\n";
   for(int i=0;i<5;i++)
        {
        cout << "\t " << abc[i] << " ";
           }
cout << "\n\n";
system("PAUSE");
}