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

Odd and Even Numbers Using Structure in C++

A simple program to check if the given number is an odd or even number using structure 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>
#include <iomanip>

using namespace std;



struct odd {

int n;

  int odd_even() {

  if (n % 2 == 0)
        {
                 cout << n <<" Number is even!\n";
        }
        else
        {
                 cout << n << " Number is odd!\n";
        }
   return(n);

  }

};

main() {

    odd value;

   cout << "\t\t ODD and Even Number Determiner";
   cout << "\n\n";
   cout << "Enter a Number :";
   cin >> value.n;
   cout << "\n\n";
   cout << value.odd_even();
   cout << "\n\n";
   system("pause");


}


Loan Interest Solver in Perl

A simple program that I wrote using PERL to solve the loan of the customer. I will ask the user for the principal amount load, interest rate and the time.


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

#!D:\xampp\perl\bin

sub find_interest {
  ($amount,$rate,$time) = @_;
   $solve_interest = ($amount * $rate * $time) / 100;
}

print "\n\n";
print "Loan Interest Solver";
print "\n\n";
print "Enter Principal Amount : ";
chomp($amount=<>);
print "Enter Rate of Interest : ";
chomp($rate=<>);
print "Enter Period of Time   : ";
chomp($time=<>);
print "\n\n";
print "Display Result";
print "\n\n";
print "The interest rate is $" ;
print  find_interest($amount,$rate,$time);
print "\n\n";
print "End of Program";
print "\n\n";


Cube Root in C++

A simple program that I wrote in C++ to show how to solve cube root. I am using CodeBlocks as my text editor and Dev C++ as my C++ compiler.


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;

struct cube{

  int value;

  int solve()
    {
        return(value * value * value);
    }
  };

  main() {

       cube val;

      cout << "\t\t Cube Root Solver 1.0";
      cout << "\n\n";
      cout << "Enter a Number : ";
      cin >> val.value;
      cout << "\n";
      cout << "The Cube Root Value of " << val.value
           << " is " << val.solve() << ".";
     cout << "\n\n";
     system("pause");
  }


Power of a Number Perl

A simple program that will ask the user to give the base and power of a number from the user using PERL as our 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
.


Program Listing

#!D:\xampp\perl\bin

sub solve_power {
    ($base1, $exponent) = @_;
    $solve  = $base1 ** $exponent;
}

print "\n\n";
print "Power of a Number";
print "\n\n";
print "Enter base number : ";
chomp($base=<>);
print "Enter power number (positive integer) : ";
chomp($exp=<>);
print "\n\n";
print "Display Result";
print "\n\n";
print "$base ^ $exp  = " ;
print  solve_power($base,$exp);
print "\n\n";
print "End of Program";
print "\n\n";

Leap Year Checker in Delphi

A program that I wrote using Delphi programming language that will ask the user to give a year and then our program will check if the given year by the user is a leap year or not a leap year. The code is very simple because I am using a function in Delphi called IsLeapYear() to check if the given year is a leap year or not. I hope you will find my work useful. Thank you.

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

leap.pas

unit leap;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Edit1: TEdit;
    Label3: TLabel;
    Button1: TButton;
    Label4: TLabel;
    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}

Var Given_Year : Integer;

procedure TForm1.Button1Click(Sender: TObject);
begin

Given_Year := StrToInt(Edit1.Text);

If IsLeapYear(Given_Year) Then
    Label3.Caption := 'The year ' + Edit1.Text + ' is a Leap Year.'
Else
   Label3.Caption :=  'The year ' + Edit1.Text + ' is not a Leap Year.'
end;

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

end.