Student Of Fortune
Showing posts with label Delphi. Show all posts
Showing posts with label Delphi. Show all posts

Bubble Sort In C Language

   Bubble Sort is a sorting method with principles: data on the location / index I as compared with other data on the location / index next to I +1, if there is an incompatibility of data, the data in the location I would be exchanged with the data at the location I +1. Then slowly, the data will move toward to the right location. Of this nature, which means that the term bubble bubble is taken. Like the bubbles in soda drinks, which slowly moves up to the top.

      Presented examples of how it works, to 5 pieces of data that is 4, 5, 1, 3, 2. Ordering starts from the first location (I was 1), and compared with the location next to him (I +1 is 2). Because the data 4 and 5 was located at a suitable sequence, was not exchanged. Then check the next location data (I was 2) with the location next to him (I +1 is 3), 5 and 1 data was not suitable, then exchanged. Next location (I was 3) compared with the location next to him (I +1 is 4), data were 5 and 3, does not fit anymore, then exchanged again. So forth, are done to confirmed that all existing data in a suitable location, which is done in a way there is no more exchanges are done. Here is the process of change data for a sample data 4, 5, 1, 3, 2 are:
First iteration (First Pass)

4 5 1 3 2 (suitable)
4 5 1 3 2 (exchange 5 and 1) 4 1 5 3 2
4 1 5 3 2 (exchange 5 and 3) 4 1 3 5 2
4 1 3 5 2 (exchange 5 and 2) 4 1 3 2 5

Second loop (Second Pass)

4 1 3 2 5 (exchange 4 and 1) 1 4 3 2 5
1 4 3 2 5 (exchange 4 and 3) 1 3 4 2 5
1 3 4 2 5 (exchange 4 and 2) 1 3 2 4 5
1 3 2 4 5 (suitable)

Third iteration (Third Pass)

1 3 2 4 5 (suitable)
1 3 2 4 5 (exchange 3 ​​and 2) 1 2 3 4 5
1 2 3 4 5 (suitable)
1 2 3 4 5 (suitable)

Fourth iteration (Fourth Pass)

1 2 3 4 5 (suitable)
1 2 3 4 5 (suitable)
1 2 3 4 5 (suitable)
1 2 3 4 5 (suitable)
See The Code : 
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAX 30
#define DELAY 10000000
#define TRUE 1
#define FALSE 0
#define INPUT 'i'
#define OUTPUT 'o'
#define _MY_DEBUG
#if defined(_MY_DEBUG)
    #define TRACE_LINE printf("\n\n- Program Statistics :\n1. File : %s\n2. Date : %s\n3. Time : %s\n",__FILE__,__DATE__,__TIME__);
#else
    #define TRACE_LINE
#endif
void BubbleSort(int*, int),
    Swap(int*, int*),
        InputOutput(int*, const int, const char),
    Delay(void),
FreeBuffer(int*);
int main(int argc, char *argv[]) {
    system("COLOR 5");
    int *buffer = NULL, max;
    printf("Implementasi Bubble Sort\nMasukkan banyak data [max:30] : ");
    scanf("%d",&max);
    fflush(stdin);
    if((max > FALSE) && (max <= MAX)) {
        buffer = (int*)calloc(max,sizeof(int));
        InputOutput(buffer,max,INPUT);
        printf("\nData yang anda masukkan : ");
        InputOutput(buffer,max,OUTPUT);
        BubbleSort(buffer,max);
        printf("\nData setelah disorting : ");
        InputOutput(buffer,max,OUTPUT);
        FreeBuffer(buffer);
    } TRACE_LINE;
    getch();
    fflush(stdin);
    return(EXIT_SUCCESS);
}
void BubbleSort(int* buffer, int max) {
    int i, j;
    for(i = 0; i < max; ++i) {
        for(j = 0; j < max-i; ++j) {
            if(*(buffer+j) > *(buffer+(j+TRUE))) { // if(buffer[j] > buffer[j+TRUE]) {
                Swap((buffer+j),(buffer+(j+TRUE))); // Swap(&(*(buffer+j)),&(*(buffer+(j+TRUE))));
            }
        }
    }
}
void Swap(int* buffer1, int* buffer2) {
    int tmp = *buffer1;
    *buffer1 = *buffer2;
    *buffer2 = tmp;
}
void InputOutput(int* buffer, const int max, const char STAT) {
    int i;
    /* switch(STAT) {
        case(INPUT) : {
            for(i = 0; i < max; ++i) {
                printf("%d. Data ke-%d : ",(i+TRUE),(i+TRUE));
                scanf("%d",&buffer[i]);
                fflush(stdin);
            }
        } break;
        case(OUTPUT) : {
            for(i = 0; i < max; ++i) {
                printf("%d ",buffer[i]);
                Delay();
            }
        } break;
        default :
            break;
    } */
    if('i' == STAT) {
        for(i = 0; i < max; ++i) {
            printf("%d. Data ke-%d : ",(i+TRUE),(i+TRUE));
            scanf("%d",&buffer[i]);
            fflush(stdin);
        }
    } else if('o' == STAT) {
        for(i = 0; i < max; ++i) {
            printf("%d ",buffer[i]);
            Delay();
        }
    }
}
void Delay(void) {
    int i = FALSE;
    while(i < DELAY) {
        ++i;
    }
}
void FreeBuffer(int* buffer) {
    free(buffer);
    buffer = NULL;
}
See The Out put :

 

Video tutorials to learn Delphi

There are various facilities to learn Delphi. we can learn with books, Internet, friends, videos, courses and so forth. at this time we discuss about Delphi study using video. One of the most effective method is through video. Because we only see delphi ters and direct practice. Previously, for those who do not have a Delphi compiler, please download the free Delphi compiler (Turbo Delphi 2006), or it could be Delphi 7 Personal or Delphi2005 Personal. Please download the software, sorry did not include a link to download its software.

One of the resources that provide video tutorials Delphi is  

Instead we are hard to find by search engines, then there already provided links and direct links various tutorials. Almost all of them using Turbo Delphi. But it should be compatible with Delphi 7 and above. The address that provides a collection of [links] video tutorials from various sources, namely:
  • CodeGearGuru tutorial movies
  • Delphi-PRAXiS :: Videos
  • Two-minute tutorials, by : Nick Hodges
  • 3DBuzz Delphi Training Series
  • Delphi Course by R I D D L E R S O F T
  • 30 Camtasia Demos in 30 Days Series
  • And other tutorials

[Dephi] Creating a Login Form With Delphi and Microsoft Access Database

Many of the novice Delphi programmers, the difficulty to create a login form within the application. For that I will try to make a simple tutorial on how to create a login form for the administrator, nor any other operator.
Follow the Instructions Below:
1. Run the program Delphi.
2. Add 2 Labels, 2 TEdit, and 1 Button
3. Set properties for each component.


4. File -> New -> Form, to add a form  
5. Save Project, for the FrmLogin give the name "Ulogin units", while to form has made, you can give       
    unit's name UHasilLogin.
6. Set looks like in the picture.
 
7. Now create a database to store their login data. Use the Microsoft Access database.
8. Run Microsoft Access
9. File New Blank Database
10. Give the name file with data, then Click Create,
  
If you simply want to create a new DB without opening Ms.Access, my friend can use this VBS script, save with the name script.vbs in a text editor like notepad
Dim DBFileName
Dim objConnection,FSO
Dim objDBFile

Set objConnection = CreateObject("ADOX.Catalog")
Set FSO=CreateObject("Scripting.FileSystemObject")

DBFileName=Trim(InputBox("Enter Filename With Location  " _
 & "Database Will be Created", "JET Database Generator","C:\DB_Baru.mdb"))
 
If DBFileName <> Empty Then
  ' make new Database 
 objConnection.Create "Provider = Microsoft.Jet.OLEDB.4.0; " & _
         "Data Source = " & DBFileName
         
 If FSO.FileExists(DBFileName) Then
  MsgBox "Database has been created",vbInformation,"Success"
 End If
 
End if
11. Open a new databse and create a single table, with the name of the login table. Use the Create table in      design view to create tables
12. Make 2 Field as shown below. Set Field Size as desired.

17. And below the code for login form
ULogin unit;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, dialogs, StdCtrls, DB, ADODB;
type
  
TFrmLogin = class (TForm)
   
Label1: TLabel;
   
edusername: TEdit;
   
Label2: TLabel;
   
edpassword: TEdit;
   
Button1: TButton;
   
ADOQuery1: TADOQuery;
   
ADOConnection1: TADOConnection;
   
Button1Click procedure (Sender: TObject);
   
FormCreate procedure (Sender: TObject);
  
private
   
{Private Declarations}
  
public
   
{Public Declarations} end;
var FrmLogin: TFrmLogin;
implementation uses  
/ / XPMan for display form such as the button following the theme on windows
/ / Add to ULogin UHasilLogin unit by pressing Alt + F11, or with
/ / typed it

XPMan, UHasilLogin;

{$ R *. DFM}

TFrmLogin.FormCreate procedure (Sender: TObject);
var
s: Char;
alamatdb: WideString;
begin

/ / Manipulation cursors crSQLWait order not to appear
Screen.Cursors [crSQLWait]: = Screen.Cursors [crDefault];

/ / set the display form
s: = '*';
edusername.Text: ='';
edpassword.PasswordChar: = s;
edpassword.Text: ='';

/ / set the connection on ADOConnection
/ / This script allows you to manage database connections in applications
/ / in order to application can process
database that has been selected in a computer 
/ / anywhere without the need to have a path / address the same database.

alamatdb: = ExtractFilePath (Application.ExeName) + 'data.mdb';
with ADOConnection1 do begin
Connected: = False;
LoginPrompt: = False;
Mode: = cmShareDenyNone;
ConnectionString: = 'Provider = Microsoft.Jet.OLEDB.4.0; Data Source =' +
alamatdb + '; persist Security Info = False';
end;
 
ADOConnection1.Connected: = True;
end;

TFrmLogin.Button1Click procedure (Sender: TObject);
begin
    with ADOQuery1 do begin
      Close;
      SQL.Clear; / / clear
command sql if there is.
      SQL.Add ('SELECT * FROM login WHERE username =' +
      QuotedStr (edusername.Text));
      Open;
    end; / / end with

    / / if not found then the data sought
    / / display message
    if ADOQuery1.RecordCount = 0 then
      Application.MessageBox ('Sorry, your username does not exist', 'Information',
      MB_OK or MB_ICONINFORMATION)
    else begin
      if ADOQuery1.FieldByName ('password'). AsString <> edpassword.Text then
        Application.MessageBox ('Make sure the correct username or password',
        'Error', MB_OK or MB_ICONERROR)
      else begin
         Hide;
         Form1.Show;
      end
    end;
end;

end.
 
18. Add code Application.Terminate to button located on the unit uHasilLogin.
19. Compile the program and See the results

20. Finish 
 
Recommended Post Slide Out For Blogger

Recent Comments

My Rank