Sabtu, 01 Mei 2010

Blum Blum Shub in Delphi

2 days ago there is a friend that ask me about Blum-Blum Shub Random Number Generator method. I can ask her question at that time. So I post the code I got in this blog. Hope this can help.

Source :

procedure TForm1.Blum;

var

xo,i,p,q,start: Integer;

text_datei: TextFile;// ga dipake juga gpp

begin

start:=StrToInt(Form1.Edit1.Text);

p:=StrToInt(Form1.Edit3.Text);

q:=StrToInt(Form1.Edit5.Text);

Writeln(text_datei, 'Hasil');

Writeln(text_datei, 'Start: '+IntToStr(start));

Writeln(text_datei, 'Parameter P: '+IntToStr(p));

Writeln(text_datei, 'Parameter Q: '+IntToStr(q));

Writeln(text_datei, 'N=P*Q: '+IntToStr(p*q));

Writeln(text_datei, ' ');

for i := 1 to StrToInt(Form1.Edit2.Text) do begin

xo:=(start*start) mod (p*q); // start = s

if xo<0>

Form1.Ausgabe(xo);

start:=xo; end;

end;

//ini prosedur untuk menampilkan, baiknya diganti saja

procedure TForm1.Ausgabe(ergebnis: Integer); // ergebnis adalah parameter

begin

Writeln(text_datei ,IntToStr(a)+'. '+IntToStr(ergebnis));

Form1.Memo1.Lines.Append(IntToStr(ergebnis));

a:=a+1;

Form1.count;

end;



Simple Calculator in Delphi



I copy this code from Martin Austermeier, hope this code help you

Calc.pas

unit Calc;

(***********************************************************************

simple calculator for Delphi programs

by Martin Austermeier CIS 100116,3455

Version 1.1 - 10.10.95:

* corrected embarassing subtract bug

* "overflow" error display

* deleted some unnecessary code

--------------------------------------------------------------


This is not a component; just include it with "USES Calc".


Sorry, I don't have the time to write mucho documentation.

Only a few items:

* you might want to change the Form's Caption.


* the calculator is designed to show results with two decimal places.

Look at SetResult (PRECISION, DECIMAL_PLACES) if you want to change this.


* there are only the basic functions.

Not even a "percent" button.. ;-)

If you integrate new buttons, you should set their "Tag" property,

and process them like in CalcButtonClick()


* I invoke the calculator as a modal form (see ShowCalculator).

You'd have to write a Close mechanism if you want to use it as

a non-modal window.


* a typical call would look like

var myNumber : Double;

begin

myNumber := 123.45;

if Calc.Showcalculator(myNumber) then [myNumber has changed];

end;

**********************************************************************)


interface


uses

SysUtils, WinTypes, WinProcs, Messages, Classes,

Forms, Buttons, Controls, StdCtrls, ExtCtrls;


type

TCalcStatus = (CS_FIRST, CS_VALID, { the rest is error stati }

CS_ERROR, CS_OVERFLOW);


type

TCalculator = class(TForm)

MainPanel: TPanel;

DisplayPanel: TPanel;

BottomPanel: TPanel;

Panel3: TPanel;

resultLabel: TLabel;

Button1: TButton;

Button2: TButton;

Button3: TButton;

Button4: TButton;

Button5: TButton;

Button6: TButton;

Button7: TButton;

Button8: TButton;

Button9: TButton;

Button0: TButton;

ButtonComma: TButton;

ButtonDiv: TButton;

ButtonMult: TButton;

ButtonSub: TButton;

ButtonAdd: TButton;

ButtonSign: TButton;

ButtonC: TButton;

ButtonEq: TButton;

okBtn: TBitBtn;

cancelBtn: TBitBtn;

procedure CalcButtonClick(Sender: TObject);

procedure OkBtnClick(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure FormKeyPress(Sender: TObject; var Key: Char);

private

{ Private-Declaration }

fResult : Double;

fDisplayText : String[30];

fStatus : TCalcStatus;

operand : Double;

operator : Char;


procedure SetResult(r : Double);

function GetResult : Double;

procedure SetStatus(stat : TCalcStatus);

procedure SetDisplayText(s : String);

function GetDisplayText : String;

property Status : TCalcStatus read fStatus write SetStatus;

property DisplayText : String read GetDisplayText write SetDisplayText;


public

{ Public-Declaration }

property CalcResult : Double read GetResult write SetResult;


procedure Clear;

end;


var

Calculator: TCalculator;


function ShowCalculator(var number : Double) : Boolean;

{ display modal (inital result=number); return "number", if TRUE }


implementation


{$R *.DFM}


function ShowCalculator(var number : Double) : Boolean;

begin

Calculator := TCalculator.Create(application);

try

Calculator.CalcResult := number;

if (Calculator.ShowModal = MROK) then

number := Calculator.CalcResult;

finally

Calculator.Free;

end;

end;



procedure TCalculator.SetResult(r : Double);

const

PRECISION = 15;

DECIMAL_PLACES = 2;

begin

fResult := r;

DisplayText := FloatToStrF(fResult, ffFixed, PRECISION, DECIMAL_PLACES);

end;



function TCalculator.GetResult : Double;

begin

result := StrToFloat(DisplayText);

end;



procedure TCalculator.SetStatus(stat : TCalcStatus);

begin

fStatus := stat;

if (fStatus >= CS_ERROR) then

MessageBeep(MB_ICONSTOP);

end;



procedure TCalculator.SetDisplayText(s : String);

const

MAX_LEN = 17; { max# digits in display }

begin

if (Length(s) <= MAX_LEN) then

resultLabel.Caption := s

else begin

Status := CS_OVERFLOW;

end;

end;



function TCalculator.GetDisplayText : String;

begin

result := resultLabel.Caption;

end;



procedure TCalculator.FormCreate(Sender: TObject);

begin

Clear;

end;



procedure TCalculator.Clear;

begin

Status := CS_FIRST;

DisplayText := '0';

operand := 0;

operator := #0;

end;



procedure TCalculator.CalcButtonClick(Sender: TObject);

var

k : Char;

begin

if (Sender is TButton) then begin

ButtonEq.SetFocus; { default button }

k := Char(TButton(Sender).Tag);

FormKeyPress(Sender, k);

end;

end;



procedure TCalculator.OkBtnClick(Sender: TObject);

var

k : Char;

begin

k := '=';

FormKeyPress(self, k); { simulate "=" to get result }

end;



procedure TCalculator.FormKeyPress(Sender: TObject; var Key: Char);

const

KEY_SIGN = '#';

KEY_CLEAR = 'C';

KEY_DECIMAL = '.';


ERR_TXT = 'Error';

OFL_TXT = 'Overflow';


var

k : Char;

begin

k := UpCase(key);


if (k = decimalSeparator) then

k := KEY_DECIMAL;


if (Status <>

or (k = KEY_CLEAR) then

case k of

'0'..'9': begin

if (Status = CS_FIRST) or (DisplayText = '0') then

DisplayText := '';

Status := CS_VALID;

DisplayText := DisplayText + k;

end;


#8 : begin

if (Length(DisplayText) > 0) then begin

DisplayText := Copy(DisplayText, 1, Length(DisplayText)-1);

if (Length(DisplayText) = 0) then

DisplayText := '0';

Status := CS_VALID;

end;

end;


KEY_DECIMAL: begin

if (Pos(decimalSeparator, DisplayText) = 0) then

DisplayText := DisplayText + decimalSeparator;

Status := CS_VALID;

end;


'+', '-', '/', '*', '=' : begin

case operator of

'+': begin

CalcResult := operand + CalcResult;

end;


'-': begin

CalcResult := operand - CalcResult;

end;


'*': begin

CalcResult := operand * CalcResult;

end;


'/': begin

if (CalcResult = 0) then

Status := CS_ERROR

else

CalcResult := operand / CalcResult;

end;


end;


if (Status <> CS_ERROR) then begin

Status := CS_FIRST;

operand := CalcResult;

operator := k;

end;

end;


KEY_SIGN: begin

CalcResult := -CalcResult;

end;


KEY_CLEAR: begin

Clear;

end;


end;


case Status of { in case of error.. }

CS_ERROR : DisplayText := ERR_TXT;

CS_OVERFLOW : DisplayText := OFL_TXT;

end;

end;



end.


Program Project1

program Project1;


uses

Forms;


{$R *.res}


begin

Application.Initialize;

Application.Run;

end.


And the result is :



Selasa, 22 Desember 2009

Nilai Pemrog IC





Untitled Document






































































































































N0. NAMA NIM NA
1 Adityaranda S. 0910960001-96 82.1
2 Cahya Arief Ramadhan 0910960003-96 80
3 Diantika Puspitasari 0910960005-96 77.9
4 Elly Ratna Sayekti 0910960007-96 77
5 Primanda Lusita 0910960011-96 84
6 Septyan Teguh Mahendra 0910960017-96 17
7 Ade Sumantri 0910960021-96 73.3
8 Aulia Yusiana F. 0910960027-96 83.5
9 Febe Athalia Agnar 0910960035-96 80.3
10 Isyar A. Harun 0910960043-96 83.7
11 Khoirul Sholeh 0910960045-96 82.7
12 Olive Khoirul L.M.A 0910960055-96 78
13 Raden Roro Kartika N. 0910960057-96 77.3
14 Rosiana Kurniasari 0910960062-96 79.4
15 Ayu Rachmawati 0910961001-96 77.1
16 Nanik Ulfatun Nikmah 0910961007-96 74.5
17 Tomy Febri P. 0910961009-96 82.8
18 Candra Ratna Hariyanti 0910963007-96 76.1
19 Tita Fadilah 0910963015-96 85.2
20 Nining Dyah Mustikawati 0910963025-96 78.3




Senin, 14 Desember 2009

Daftar Nilai Komputer Dasar Kimia A
































































































































No Nama NIM FINAL
1 Putri Tishana Primandari 0610920046 73
2 Fifi Nafikah 0910920010 83
3 Aris 0910920026 83
4 Devis Resita Dewi 0910920028 81
5 Indah Destiana 0910920046 87
6 Nora Witnya 0910920056 73
7 Nur Faiza 0910920058 85
8 S. Alfisyah Nur Aziza 0910920064 82
9 Sicilla Kusuma 0910920066 80
10 Aliya Fatma 0910921002 73
11 Ivatarina Wulandari 0910921006 74
12 Sarah Fitria Agung 0910921008 73
13 Ardian Retno 0910923004 81
14 Lhuhur Sheto A 0910923010 71
15 Alif Faiza R 0910923028 80
16 Fajar Rizqy M 0910923040 81
17 Juli Iffatu Rosyidah 0910923046 87
18 Megawati Sistin A 0910923050 82
19 Novia Sintesa Dara R 0910923052 86
20 Rara Anggun Mei N 0910923054 82

Minggu, 22 November 2009

Pemecahan Array


Pemecahan Array

Mula-mula kita harus membuat kelas MyArray sbb :

MyArray.java

1

public class MyArray {

private int size;

private double x[];

public MyArray(int _size)

{

size = _size;

x = new double [size];

}

public void setSize(int _size)

{

size = _size;

x = new double [size];

}

public void read()

{

System.out.print("Banyaknya data :");

int n = MyInput.inInt();

setSize(n);

int i;

for (i=0; i

{

System.out.print("Data "+(i+1)+" : ");

x[i] = MyInput.inDouble();

}

}

public void write()

{

int i;

for (i=0; i

{

System.out.println((i+1)+". "+x[i]);

}

}

public double average()

{

int i;

double total = 0;

for (i=0; i

{

total = total + x[i];

}

return total/size;

}

public void distribusiFrek()

{

int i,f1=0,f2=0,f3=0,f4=0,f5=0;

int asan=200;

for (i=0;i

if (x[i]<=20) f1++;

else if (x[i]<=40) f2++;

else if (x[i]<=60) f3++;

else if (x[i]<=80) f4++;

else if (x[i]<=100) f5++;

}

System.out.println("\n\nAda "+size+" data");

System.out.println("\nRange Frekuensi");

System.out.println("0-20 "+f1);

System.out.println("21-40 "+f2);

System.out.println("41-60 "+f3);

System.out.println("61-80 "+f4);

System.out.println("81-100 "+f5);

}

public void sort()

{

int i,j;

double temp;

System.out.println("Urutan Data : ");

for (i=0;i

for (j=i+1;j

if (x[j]

temp=x[i];

x[i]=x[j];

x[j]=temp;

}

}

System.out.println ((int)x[i]+" ");

}

System.out.println("");

}

public void statistik()

{

int i;

double total=0;

for (i=0; i

{

total = total + x[i];

}

System.out.println("\nRata-rata= "+total/size);

double maks = x[ 0 ];

for (int j=0; j

{

if ( x[j] > maks )

maks = x[j];

}

System.out.println("\nMaksimum= "+maks);

double min = x[ 0 ];

for ( int k=0; k

{

if ( x[k] <>

min = x[k];

}

System.out.println("\nMinimum= "+min);

}

}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

Lalu kita membuat kelas MyInput.java

MyInput.java

import java.io.*;

public class MyInput {

private static InputStream in = System.in;

private static PrintStream out = System.out;

private static String buffer = null;

private static int pos = 0;

public static byte inByte()

{

return (byte)readInteger(-128L,127L);

}

public static short inShort()

{

return (short)readInteger(-32768L,32767L);

}

public static int inInt()

{

return (int)readInteger((long)Integer.MIN_VALUE,

(long)Integer.MAX_VALUE);

}

public static long inLong()

{

return readInteger(Long.MIN_VALUE, Long.MAX_VALUE);

}

public static char inChar()

{

char ch = lookChar();

while (ch == ' ' || ch == '\n')

{

readChar();

if (ch == '\n')

dumpString("",0);

ch = lookChar();

}

return readChar();

}

public static double inDouble() {

double x = 0.0;

while (true) {

String str = readRealString();

if (str.equals("")) {

errorMessage("Range " , + Double.MIN_VALUE +

" sampai " + Double.MAX_VALUE);

}

else {

Double f = null;

try { f = Double.valueOf(str); }

catch (NumberFormatException e) {

errorMessage("Range " , + Double.MIN_VALUE +

" sampai " + Double.MAX_VALUE);

continue;

}

if (f.isInfinite()) {

errorMessage("Range " , + Double.MIN_VALUE +

" sampai " + Double.MAX_VALUE);

continue;

}

x = f.doubleValue();

break;

}

}

return x;

}

private static String readRealString()

{

StringBuffer s=new StringBuffer(50);

char ch=lookChar();

while (ch == ' ' || ch == '\n') {

readChar();

if (ch == '\n')

dumpString("",0);

ch = lookChar();

}

if (ch == '-' || ch == '+') {

s.append(readChar());

ch = lookChar();

while (ch == ' ') {

readChar();

ch = lookChar();

}

}

while (ch >= '0' && ch <= '9') {

s.append(readChar());

ch = lookChar();

}

if (ch == '.') {

s.append(readChar());

ch = lookChar();

while (ch >= '0' && ch <= '9') {

s.append(readChar());

ch = lookChar();

}

}

if (ch == 'E' || ch == 'e') {

s.append(readChar());

ch = lookChar();

if (ch == '-' || ch == '+') {

s.append(readChar());

ch = lookChar();

}

while (ch >= '0' && ch <= '9') {

s.append(readChar());

ch = lookChar();

}

}

return s.toString();

}

private static long readInteger(long min, long max)

{

long x=0;

while (true) {

StringBuffer s=new StringBuffer(34);

char ch=lookChar();

while (ch == ' ' || ch == '\n') {

readChar();

if (ch == '\n')

dumpString("",0);

dumpString("",0);

ch = lookChar();

}

if (ch == '-' || ch == '+') {

s.append(readChar());

ch = lookChar();

while (ch == ' ') {

readChar();

ch = lookChar();

}

}

while (ch >= '0' && ch <= '9') {

s.append(readChar());

ch = lookChar();

}

if (s.equals("")){

errorMessage("Range integer : ", + min +

" sampai " + max);

}

else {

String str = s.toString();

try {

x = Long.parseLong(str);

}

catch (NumberFormatException e) {

errorMessage("Range integer : " , + min +

" sampai " + max);

continue;

}

if (x <> max) {

errorMessage("Range integer : ", + min +

" sampai " + max);

continue;

}

break;

}

}

return x;

}

private static void dumpString(String str, int w)

{

for (int i=str.length(); i

out.print(' ');

for (int i=0; i

if ((int)str.charAt(i) >= 0x20 &&

(int)str.charAt(i) != 0x7F)

out.print(str.charAt(i));

else if (str.charAt(i) == '\n' || str.charAt(i) ==

'\r')

newLine();

}

private static void errorMessage(String message,

String expecting)

{

newLine();

dumpString(" *** Input Salah: \n", 0);

dumpString(" *** Range: " + expecting + "\n", 0);

newLine();

dumpString("Masukkan lagi: ", 0);

readChar(); // discard the end-of-line character

}

private static char lookChar()

{

if (buffer == null || pos > buffer.length())

fillBuffer();

if (pos == buffer.length())

return '\n';

return buffer.charAt(pos);

}

private static char readChar()

{

char ch = lookChar();

pos++;

return ch;

}

private static void newLine()

{

out.println();

out.flush();

}

private static boolean possibleLinefeedPending = false;

private static void fillBuffer()

{

StringBuffer b = new StringBuffer();

out.flush();

try {

int ch = in.read();

if (ch == '\n' && possibleLinefeedPending)

ch = in.read();

possibleLinefeedPending = false;

while (ch != -1 && ch != '\n' && ch != '\r') {

b.append((char)ch);

ch = in.read();

}

possibleLinefeedPending = (ch == '\r');

if (ch == -1) {

System.out.println("*** Found an end-of-file while trying to read from standard input! ***");

System.out.println("*** Program will be terminated. *** \n");

throw new RuntimeException(" End-of-file on standard input.");

}

}

catch (IOException e) {

System.out.println(" Unexpected system error on input.");

System.out.println("Terminating program.");

System.exit(1);

}

buffer = b.toString();

pos = 0;

}

}

Apalagi ya? Oh ya! MyMenu.java :

MyMenu.java

1

public class MyMenu {

public static int getPilih()

{

int pilih;

do

{

System.out.println("\n MENU PROGRAM");

System.out.println("1. Input Data");

System.out.println("2. Tampilkan Data");

System.out.println("3. Distribusi Frekuensi");

System.out.println("4. Statistik");

System.out.println("5. Urutkan Data");

System.out.print ("Pilihan Anda : ");

pilih = MyInput.inInt();

System.out.println("");

}while ((pilih<0)||(pilih>5));

return pilih;

}

}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

FINALNYA! Kelas Main.java!

Main.java

1

public class Main {

public static void main (String[] args) {

int pilih;

MyArray arr = new MyArray(1);

do{

pilih = MyMenu.getPilih();

switch(pilih)

{

case 1 : arr.read();break;

case 2 : arr.write();break;

case 3 : arr.distribusiFrek();break;

case 4 : arr.statistik();break;

case 5 : arr.sort();break;

}

}while (pilih!=0);

}

}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19




















Outputnya ! :