A simple program that I wrote using Delphi as my programming language that will ask the user to give a string or word and then our program will check if the given word is a Palindrome or Not. A word becomes a palindrome with you read it forward and backward the spelling of the word is still the same. I hope you will find my work useful in learning Delphi programming.
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 palin;
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;
Label4: TLabel;
Label5: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function IsPalindrome(const s: string): boolean;
var
i, j: integer;
begin
Result := false;
j := Length(s);
for i := 1 to Length(s) div 2 do begin
if s[i] <> s[j] then
Exit;
Dec(j);
end;
Result := true;
end;
var given_string : string;
procedure TForm1.Button1Click(Sender: TObject);
begin
given_string := AnsiLowerCase(edit1.text);
if IsPalindrome(given_string) then
begin
label3.caption := 'The given string ' + AnsiUpperCase(edit1.text)
+ ' is a Palindrome.'
end
else
begin
label3.caption := 'The given string ' + AnsiUpperCase(edit1.text)
+ ' is Not a Palindrome.'
end
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.text :='';
label3.caption :='';
edit1.setfocus;
end;
end.
No comments:
Post a Comment