Monday, December 5, 2011

program bank inheritance dalam c#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    abstract class bank
    {
        private int amount;
        private static int total;
        public void deposit(int amt)
        {
            amount += amt;
            total = total + amt;
        }
        public void withdraw(int amt)
        {
            if (amount < amt)
            {
                Console.WriteLine("Saldo Kurang");
            }
            else
            {
                amount -= amt;
                total = total - amt;
            }
        }
        public void cek_saldo()
        {
            Console.WriteLine("Jumlah Saldo Anda = {0}", amount);
        }
        public static void show_total()
        {
            Console.WriteLine("Jumlah Uang di Bank =  {0}", total);
        }
    }
    class BNI : bank
    {  
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Jumlah Nasabah = ");
            int n_nasabah = int.Parse(Console.ReadLine());
            BNI[] nasabah = new BNI[n_nasabah + 1];
            for (int i = 1; i <= n_nasabah; i++)
            {
                nasabah[i] = new BNI();
            }

            while (true)
            {
                Console.WriteLine("Pilihan : ");
                Console.WriteLine("     1. Menabung");
                Console.WriteLine("     2. Mengambil Uang");
                Console.WriteLine("     3. Cek_Saldo");
                Console.WriteLine("     4. Cek_saldo_bank");
                Console.WriteLine("     5. keluar");
                Console.Write("Pilih : ");
                int pilih = int.Parse(Console.ReadLine());
                int no_rek;
                int jumlah;
                switch (pilih)
                {
                    case 1:
                        {
                            Console.Write("Nomor Rekening Anda : ");
                            no_rek = int.Parse(Console.ReadLine());
                            Console.Write("Jumlah Uang ");
                            jumlah = int.Parse(Console.ReadLine());
                            nasabah[no_rek].deposit(jumlah);
                            break;
                        }
                    case 2:
                        {
                            Console.Write("Nomor Rekening Anda : ");
                            no_rek = int.Parse(Console.ReadLine());
                            Console.Write("Jumlah Uang ");
                            jumlah = int.Parse(Console.ReadLine());
                            nasabah[no_rek].withdraw(jumlah);
                            break;
                        }
                    case 3:
                        {
                            Console.Write("Nomor Rekening Anda : ");
                            no_rek = int.Parse(Console.ReadLine());
                            nasabah[no_rek].cek_saldo();
                            break;
                        }
                    case 4:
                        {
                            bank.show_total();
                            Console.WriteLine();
                            break;
                        }
                    case 5:
                        return;
                }
            }
        }
    }
}

Tuesday, November 29, 2011

Bubble Sort dalam bahasa C


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

Shell Sort dalam bahasa C


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

#define MAX 100
#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

// int CheckForBadSorting(int*, const int);
void ShellSortPass(int*, const int, const int);
void ShellSort(int*, const int);
void InputOutput(int*, const int, const char);
void FreeBuffer(int*);

int main(int argc, char* argv[]) {
 system("COLOR 5");
 int *buffer = NULL, max;
 printf("Implementasi Shell Sort\nMasukkan jumlah data [MAX:100] : ");
 scanf("%d",&max);
 fflush(stdin);
 if((max > 0) && (max <= MAX)) {
  buffer = (int*)calloc(max,sizeof(int));
  InputOutput(buffer,max,INPUT);
  printf("\nData yang anda masukkan : ");
  InputOutput(buffer,max,OUTPUT);
  ShellSort(buffer,max);
  printf("\nData setelah disorting : ");
  InputOutput(buffer,max,OUTPUT);
  FreeBuffer(buffer);
  /* if(CheckForBadSorting(buffer,max)) {
   goto MARK;
  } else {
   InputOutput(buffer,max,OUTPUT);
  } */
 } /* MARK : if(buffer != NULL) {
  FreeBuffer(buffer);
 } */
 TRACE_LINE;
    getch();
    fflush(stdin);
    return(EXIT_SUCCESS);
}

/* int CheckForBadSorting(int* buffer, const int max) {
 int i;
 for(i = 1; i < max; ++i) {
  if(buffer[i-1] > buffer[i]) {
   printf("Bad Sorting!");
   return(1);
  }
 }
 return(0);
} */

void ShellSortPass(int* buffer, const int max, const int interval) {
 int i;
    for(i = 0; i < max; ++i) {
        int j, tmp = buffer[i];
        for(j = i-interval; j >= 0; j -= interval) {
            if(buffer[j] <= tmp) {
             break;
            } buffer[j+interval] = buffer[j];
        } buffer[j+interval] = tmp;
 }
}

void ShellSort(int* buffer, const int max) {
 int CiuraIntervals[] = {701, 301, 132, 57, 23, 10, 4, 1},
 IntervalIdx = 0, interval = CiuraIntervals[0];
    double ExtendCiuraMultiplier = 2.3;
    if(max > interval) {
     while(max > interval) {
      --IntervalIdx;
            interval = (int)(interval*ExtendCiuraMultiplier);
        }
    } else {
        while(max < interval) {
            ++IntervalIdx;
            interval = CiuraIntervals[IntervalIdx];
        }
    }
    while(interval > 1) {
        ++IntervalIdx;
  if(IntervalIdx >= 0) {
   interval = CiuraIntervals[IntervalIdx];
  } else {
   interval = (int)(interval/ExtendCiuraMultiplier);
  } ShellSortPass(buffer,max,interval);
    }
}

void InputOutput(int* buffer, const int max, const char STAT) {
 int i;
 if('i' == STAT) {
  for(i = 0; i < max; ++i) {
   printf("%d. Data ke-%d : ",(i+1),(i+1));
   scanf("%d",&buffer[i]);
   fflush(stdin);
  }
 } else if('o' == STAT) {
  for(i = 0; i < max; ++i) {
   printf("%d ",buffer[i]);
  }
 }
}

void FreeBuffer(int* buffer) {
 free(buffer);
 buffer = NULL;
}

bucket Sort dalam bahasa C


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

#define MAX 100
#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 InputOutput(int*, const int, const char);
void BucketSort(int*, const int);
void FreeBuffer(int*);

int main(int argc, char *argv[]) {
 system("COLOR 5");
 int *buffer = NULL, max;
 printf("Implementasi Bucket Sort\nMasukkan jumlah data [MAX:100] : ");
 scanf("%d",&max);
 fflush(stdin);
 if((max > 0) && (max <= MAX)) {
  buffer = (int*)calloc(max,sizeof(int));
  InputOutput(buffer,max,INPUT);
  printf("\nData yang anda masukkan : ");
  InputOutput(buffer,max,OUTPUT);
  BucketSort(buffer,max);
  printf("\nData setelah disorting  : ");
  InputOutput(buffer,max,OUTPUT);
  FreeBuffer(buffer);
 }
 TRACE_LINE;
 getch();
 fflush(stdin);
 return(EXIT_SUCCESS);
}

void InputOutput(int* buffer, const int max, const char STAT) {
 int i;
 if('i' == STAT) {
  for(i = 0; i < max; ++i) {
   printf("%d. Data ke-%d : ",(i+1),(i+1));
   scanf("%d",&buffer[i]);
   fflush(stdin);
  }
 } else if('o' == STAT) {
  for(i = 0; i < max; ++i) {
   printf("%d ",buffer[i]);
  }
 }
}

void BucketSort(int* buffer, const int max) {
 int i, j, *count = (int*)calloc(max,sizeof(int));
 for(i = 0; i < max; ++i) {
  count[i] = 0;
 } for(i = 0; i < max; ++i) {
  ++(count[buffer[i]]);
 } for(i = 0, j = 0; i < max; ++i) {
  for(; count[i] > 0; --(count[i])) {
   buffer[j++] = i;
  }
 } FreeBuffer(count);
}

void FreeBuffer(int* buffer) {
 free(buffer);
 buffer = NULL;
}

Quick Sort dalam bahasa C


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

#define MAX 30
#define INPUT 'i'
#define OUTPUT 'o'
#define TRUE 1
#define FALSE 0
#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

int ChoosePivot(int, int);
    void InputOutput(int*, const int, const char),
        QuickSort(int*, int, int),
    Swap(int*, int*),
FreeBuffer(int*);

int main(int argc, char *argv[]) {
    system("COLOR 5");
    int *buffer = NULL, max;
    printf("Implementasi Quick Sort [Ascending]\nJumlah data [MAX:30] : ");
    scanf("%d",&max);
    fflush(stdin);
    if((max > FALSE) && (max <= MAX)) {
        buffer = (int*)calloc(max,sizeof(int));
        InputOutput(buffer,max,INPUT);
        printf("\n1. Data yang anda masukkan : ");
        InputOutput(buffer,max,OUTPUT);
        QuickSort(buffer,FALSE,(max-TRUE));
        printf("\n2. Data setelah disorting : ");
        InputOutput(buffer,max,OUTPUT);
        FreeBuffer(buffer);
    }
    TRACE_LINE;
    getch();
    fflush(stdin);
    return(EXIT_SUCCESS);
}

void InputOutput(int* buffer, int max, const char STAT) {
    int i;
    if(INPUT == STAT) {
        for(i = 0; i < max; ++i) {
            printf("%d. Data ke-%d : ",(i+TRUE),(i+TRUE));
            scanf("%d",&buffer[i]);
            fflush(stdin);
        }
    } else if(OUTPUT == STAT) {
        for(i = 0; i < max; ++i) {
            printf("%d ",buffer[i]);
        }
    }
}

int ChoosePivot(int top, int bottom) {
    return((top+bottom)/2);
}

void QuickSort(int* buffer, int bottom, int top) {
    int i, j, k, pivot; // m = bottom, n = top;
    if(bottom < top) {
        pivot = ChoosePivot(bottom,top);
        Swap(&buffer[bottom],&buffer[pivot]);
        i = bottom+TRUE; j = top; k = buffer[bottom];
        while(i <= j) {
            while((i <= top) && (buffer[i] <= k)) {
                ++i;
            }
            while((j >= bottom) && (buffer[j] > k)) {
                --j;
            }
            if(i < j) {
                Swap(&buffer[i],&buffer[j]);
            }
        }
        Swap(&buffer[bottom],&buffer[j]);
        QuickSort(buffer,bottom,(j-TRUE));
        QuickSort(buffer,(j+TRUE),top);
    }
}

void Swap(int* buffer1, int* buffer2) {
    int tmp = *buffer1;
    *buffer1 = *buffer2;
    *buffer2 = tmp;
}

void FreeBuffer(int* buffer) {
    free(buffer);
    buffer = NULL;
}

Exchange sort dalam bahasa C


#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 ExchangeSort(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 Exchange 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);
        ExchangeSort(buffer,max);
        printf("\nData setelah disorting : ");
        InputOutput(buffer,max,OUTPUT);
        FreeBuffer(buffer);
    }
    TRACE_LINE;
    getch();
    fflush(stdin);
    return(EXIT_SUCCESS);
}

void ExchangeSort(int* buffer, int max) {
    int i, j;
    for(i = 0; i < (max-TRUE); ++i) {
        for(j = (i+TRUE); j < max; ++j) {
            if(*(buffer+i) > *(buffer+(j))) {
                Swap((buffer+i),(buffer+(j))); // Swap(&(*(buffer+j)),&(*(buffer+(j+TRUE))));
            }
        }
    }
}

void Swap(int* buffer1, int* buffer2) {
    int tmp = *buffer1;
    *buffer1 = *buffer2;
    *buffer2 = tmp;
}

void InputOutput(int* buffer, int max, const char STAT) {
    int i;
    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;
}

Gnome sort dalam bahasa C


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

#define MAX 100
#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 InputOutput(int*, const int, const char);
void GnomeSort(int*, const int);
void Swap(int*, int*);
void FreeBuffer(int*);

int main(int argc, char *argv[]) {
 system("COLOR 3");
 int *buffer = NULL, max;
 printf("Implementasi Gnome Sort\nMasukkan jumlah data [MAX:100] : ");
 scanf("%d",&max);
 fflush(stdin);
 if((max > 0) && (max <= MAX)) {
  buffer = (int*)calloc(max,sizeof(int));
  InputOutput(buffer,max,INPUT);
  printf("\nData yang anda masukkan : ");
  InputOutput(buffer,max,OUTPUT);
  GnomeSort(buffer,max);
  printf("\nData setelah disorting : ");
  InputOutput(buffer,max,OUTPUT);
  FreeBuffer(buffer);
 } TRACE_LINE;
 getch();
 fflush(stdin);
 return(EXIT_SUCCESS);
}

void InputOutput(int* buffer, const int max, const char STAT) {
 int i;
 if('i' == STAT) {
  for(i = 0; i < max; ++i) {
   printf("%d. Data ke-%d : ",(i+1),(i+1));
   scanf("%d",&buffer[i]);
   fflush(stdin);
  }
 } else if('o' == STAT) {
  for(i = 0; i < max; ++i) {
   printf("%d ",buffer[i]);
  }
 }
}

void GnomeSort(int* buffer, const int max) {
 int i;
 for(i = 1; i < max;) {
  if(buffer[i-1] <= buffer[i]) {
   ++i;
  } else {
   Swap(&buffer[i],&buffer[i-1]); --i;
   if(!i) {
    i = 1;
   }
  }
 }
}

void Swap(int* buffer1, int* buffer2) {
 int tmp = *buffer1;
 *buffer1 = *buffer2;
 *buffer2 = tmp;
}

void FreeBuffer(int* buffer) {
 free(buffer);
 buffer = NULL;
}

Insertion Sort dalam bahasa C


#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 InsertionSort(int*, const int);
void InputOutput(int*, const int, const char);
void Delay(void);
void FreeBuffer(int*);

int main(int argc, char *argv[]) {
    system("COLOR 5");
    int *buffer = NULL, max;
    printf("Implementasi Insertion 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);
        InsertionSort(buffer,max);
        printf("\nData setelah disorting : ");
        InputOutput(buffer,max,OUTPUT);
        FreeBuffer(buffer);
    }
    TRACE_LINE;
    getch();
    fflush(stdin);
    return(EXIT_SUCCESS);
}

void InsertionSort(int* buffer, const int max) {
    int i, j, tmp;
    for(i = 1; i < max; ++i) {
        tmp = buffer[i];
        j = i-TRUE;
        while((j >= FALSE) && (buffer[j] > tmp)) {
            buffer[j+TRUE] = buffer[j];
            --j;
        }
        buffer[j+TRUE] = tmp;
    }
}

void InputOutput(int* buffer, const int max, const char STAT) {
    int i;
    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;
}

Counting Sort dalam bahasa C


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

#define UINT unsigned int
#define MAX 100
#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 InputOutput(long*, const long, const char);
int CountingSort(long*, const long, const long);
void FreeBuffer(long*);

int main(int argc, char *argv[]) {
 system("COLOR 5");
 long *buffer = NULL, max;
 printf("Implementasi Counting Sort\nMasukkan jumlah data [MAX:100] : ");
 scanf("%ld",&max);
 fflush(stdin);
 if((max > 0) && (max <= MAX)) {
  buffer = (long*)calloc(max,sizeof(long));
  InputOutput(buffer,max,INPUT);
  printf("\nData yang anda masukkan : ");
  InputOutput(buffer,max,OUTPUT);
  if(!CountingSort(buffer,max,65535)) { // 2147483647
   /* Jika user menginputkan nilai lebih besar atau sama dengan 65535
   kedalam array buffer, maka Fungsi CountingSort tidak akan bekerja
   sesuai dengan fungsinya atau bisa mengakibatkan program Error / akan
   terjadi Segmentation Fault */
   printf("\nData setelah disorting : ");
   InputOutput(buffer,max,OUTPUT);
  } FreeBuffer(buffer);
 }
 TRACE_LINE;
 getch();
 fflush(stdin);
 return(EXIT_SUCCESS);
}

void InputOutput(long* buffer, const long max, const char STAT) {
 long i;
 if('i' == STAT) {
  for(i = 0; i < max; ++i) {
   printf("%ld. Data ke-%ld : ",(i+1),(i+1));
   scanf("%ld",&buffer[i]);
   fflush(stdin);
  }
 } else if('o' == STAT) {
  for(i = 0; i < max; ++i) {
   printf("%ld ",buffer[i]);
  }
 }
}

int CountingSort(long* buffer, const long max, const long value) {
 long i, j, OutputPos;
    long* counts = (long*)calloc(value,sizeof(long));
    if(counts == NULL) {
     printf("\nError : No Memory Available for Counts!");
     return(1);
    } else {
     for(i = 0; i < max; ++i) {
   ++counts[buffer[i]];
  } OutputPos = 0;
  for(i = 0; i < value; ++i) {
   for(j = 0; j < counts[i]; ++j) {
    buffer[OutputPos] = i;
    ++OutputPos;
   }
  } FreeBuffer(counts);
    }
    return(0);
}

void FreeBuffer(long* buffer) {
 free(buffer);
 buffer = NULL;
}

procedure counting sort

Procedure CountingSort (Input/output T:array [1..N] of integer)
{Mengurutkan Tabel T integer [1..N] dengan pencacahan, dimana range atau rentang nilainya [1..k] dengan hasil akhir T terurut menaik , dengan asumsi:Nilai N (jumlah elemen T) dan k diketahui 
Asumsi : Nilai N (jumlah elemen T) dan k diketahui, rentang nilai untuk elemen T integer antara 1..k }

Kamus 
C : array [1..k] of integer {Tabel array pencacahan}
i, j : Integer {indek perulangan}
c : Integer {jumlah elemen T yang sudah diisi pada pembentukan kembali}

Algoritma 
for i = 1 to k do {Loop 1}
C[ i ] <-- 0;
endfor

for i = 1 to N do {Loop 2}
C[ T[ i ] ] <-- C[ T [ i ] ] + 1
endfor

C <-- 0

for i = 1 to k do {Loop 3}
if C[ i ] < > 0 then 
for j = 1 to C[ i ] do {Loop 4}
C <-- C + 1
T[C] <-- i
endfor;
endif;
endfor;

program inheritance mobil dalam c#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication27
{
    class kendaraan
    {
        public kendaraan()
        {
            Console.WriteLine("bahan bakar = bensin");
        }
        public kendaraan(string tipe)
        {
            Console.WriteLine("bahan bakar = {0}",tipe);
        }
    }
    class mobilsport : kendaraan
    {
        public mobilsport()
        {
            Console.WriteLine("NOS added");
        }
        public mobilsport(string tipe):base(tipe)
        {
            Console.WriteLine("NOS added");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            mobilsport ob = new mobilsport();
        }
    }
}

program inheritance handphone 2 dalam c#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace inheritance
{
    class Handphone
    {  
        public string nama;
        public void call()
        {
            Console.WriteLine("telepon dari {0}",nama);
        }
        public void sms()
        {
            Console.WriteLine("sms dari {0}",nama);
        }
    }
    class Blackberry : Handphone
    {
        public void b1()
        {
            base.nama="blackbery";
            Console.WriteLine("bbm");
            base.call();
            base.sms();
        }
    }
    class nokia : Handphone
    {
        public void b2()
        {
            base.nama="nokia";
            Console.WriteLine("camera");
            base.call();
            base.sms();
        }
    }
    class dakota : Blackberry
    {
        public void d1()
        {
            {
                base.nama="dakota";
                Console.WriteLine("touch");
                base.call();
                base.sms();
            }
    }
        class Program
        {
            static void Main(string[] args)
            {
                Blackberry obj1 = new Blackberry();
                obj1.b1();
                nokia obj2 = new nokia();
                obj2.b2();
                dakota obj3 = new dakota();
                obj3.d1();
            }
        }
    }
}

program inheritance handphone dalam c#


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace inheritance
{
    class Handphone
    {
        public void call()
        {
            Console.WriteLine("call");
        }
        public void sms()
        {
            Console.WriteLine("sms");
        }
    }
    class Blackberry : Handphone
    {
        public void b1()
        {
            Console.WriteLine("bbm");
            base.call();
            base.sms();
        }
    }
    class nokia : Handphone
    {
        public void b2()
        {
            Console.WriteLine("camera");
            base.call();
            base.sms();
        }
    }
    class dakota : Blackberry
    {
        public void d1()
        {
            {
                Console.WriteLine("touch");
                base.call();
                base.sms();
            }
    }
        class Program
        {
            static void Main(string[] args)
            {
                Blackberry obj1 = new Blackberry();
                obj1.b1();
                nokia obj2 = new nokia();
                obj2.b2();
                dakota obj3 = new dakota();
                obj3.d1();
            }
        }
    }
}

Wednesday, November 23, 2011

struktur data list

download aja di
download

Monday, November 21, 2011

penjualan tiket pesawat dalam pascal


Program menjual_tiket;
Uses wincrt;
Type mat = array[1..10,1..10] of integer;
Function free(a: mat): Boolean;
Var
I,j : integer;
                found: boolean;
Begin
Found:= true;
I:= 1;
While (found) and (i<=8) do
                      begin
J:=1;
While (found) and (j<=5) do
If a[I,j] =0 then
Found:=false
Else
J:= j+1;
I:= i+1;
                      end;
                free:= found;
End;

        Function cek_damping(a: mat): boolean;
        Var
  I,j : integer;
  Found : boolean;
        Begin
    Found := false;
    I:= 1;
        While (not found) and (i<=8) do
                     begin
      J:=1;
      While (not found) and (j<5) do
            If (a[I,j] <> 0) and (a[I,j+1]<>0) then
Found := true
    Else
J:= j+1;
      I:= i+1;
                     end;
    Cek_damping:= found;
        End;

        Function kursi_pinggir(a: mat): boolean;
        Var
  I,j : integer;
  Found : boolean;
        Begin
    Found := false;
    j:= 1;
    While (not found) and (j<=5) do
                begin
  I:=1;
  While (not found) and (i<8) do
If a[I,j] <> 0 then
Found := true
Else
   i:= i+1;
  j:= j+4;
                end;
     kursi_pinggir:= found;
        End;


        Function kursi_nonton(a: mat): boolean;
        Var
  I,j : integer;
  Found : boolean;
        Begin
    Found := false;
    I:= 2;
        While (not found) and (i<=8) do
                     begin
      J:=1;
      While (not found) and (j<5) do
            If (a[I,j] <> 0) and (a[I,j+1]<>0) then
Found := true
    Else
J:= j+1;
      I:= i+1;
                     end;
    kursi_nonton:= found;
        End;

        procedure rubah(n : integer; var a:mat);
        var
           i,j : integer;
        begin
           For i:= 1 to 8 do
For j:= 1 to 5 do
If a[I,j] = n then
If a[I,j] = n then
A[I,j] :=0;
        end;
Var
   y: string;
   a: mat;
   i,j,n: integer;
   hasil, hasil1, hasil2, hasil3 : boolean;
Begin
For i:= 1 to 8 do
For j:= 1 to 5 do
A[I,j] := ((i*5)-5+j);
For i:= 1 to 8 do
begin
For j:= 1 to 5 do
Write(a[I,j], '             ');
Writeln;
End;

        repeat
Writeln('masukkan no tempat duduk yang anda inginkan');
        Readln(n);
        clrscr;
        hasil := free(a);
        writeln('bangku yang anda pesan masih dalam keadaan ', hasil);
        writeln;
rubah(n,a);
For i:= 1 to 8 do
begin
For j:= 1 to 5 do
Write(a[I,j], '             ');
Writeln;
End;
        writeln('apakah masih ada yang ingin memesan tiket pesawat???? (Y/N) ');
        readln(y);
        until y = 'n';
        hasil1:= cek_damping(a);
        writeln(hasil1);
        hasil2:= kursi_pinggir(a);
        writeln(hasil2);
        hasil3:= kursi_nonton(a);
        writeln(hasil3);
End.