Rabu, 25 November 2009

INPUT AND OUTPUT in PROLOG..

SOAL 1

Define a predicate makelower/0 which reads in a line of characters from the
keyboard and outputs it again as a single line with any upper case letters converted
to lower case. (The ASCII values of the characters a, z, A and Z are 97, 122, 65 and
90, respectively.)
Thus the following would be a typical use of makelower:
?- makelower.
: This is an Example 123 inCLUDing numbers and symbols +-*/@[] XYz
this is an example 123 including numbers and symbols +-*/@[] xyz
yes

JAWAB
1. deklarasikan dan simpan dengan format .pl



2. lalu buka file tadi


3. lalu ketikkan kata makelower. (akhiri dengan tanda titik), setelah itu tuliskan kata-kata terserah anda, huruf besar kecil juga boleh

hasilnya adalah, semua huruf besar yang ditulis menjadi kecil

SOAL 2
Define a predicate  copyterms which reads all the terms in a text file and
outputs them as terms to another text file one by one on separate lines.
The output file should be in a format suitable for use as the input file in a
subsequent call of copyterms. Thus for example if the input file contained
'first term'. 'second term'.
'third term'.
fourth. 'fifth term'.
sixth.
The output file would contain
'first term'.
'second term'.
'third term'.
fourth.
'fifth term'.
sixth.


JAWAB
1. deklarasikan dan simpan dengan format pl

2. buat file baru bernama Infile.txt, isinya seperti berikut

3. Lalu buka file berformat .pl tadi


4. Setelah itu ketikkan copyterms('Infile.txt','Outfile.txt').


5. hasilnya akan keluar di file baru bernama Outfile.txt, yang berisi seperti ini



SOAL 3
Create a text file testa.txt containing two lines, each of five characters followed
by a new line, e.g.
abcde
fghij
Define a predicate readfile that will read  fifteen characters from this file one by
one and output the ASCII value of each character. Use this to establish whether the   Input and Output  83
representations of 'end of file' and 'end of record' for your version of Prolog are as
suggested in Sections 5.9.1 and 5.9.2, respectively.

JAWAB
1. deklarasikan lalu simpan dengan fromat .pl

2. lalu buat file testa.txt yang berisi seperti di bawah


3. setelah itu buka file berformat .pl tadi


4. Setelah itu ketikkan readfile('testa.txt'). hasilnya adalah seperti ini





SOAL 4
 Using a text editor, create two text files in1.txt and in2.txt, each comprising a
number of terms terminated by end.
Define and test a predicate combine that takes the names of two input files as its
first two arguments and the name of an output file as its third argument. The output
file should contain the terms in the first input file followed by the terms in the
second, one per line and terminated by end.
JAWAB
1. deklarasikan dan simpan dengan format .pl


2. Buat s file lagi, yang satu bernama In1.txt dan yang kedua bernama In2.txt. Isinya lihat di bawah ini (bisa berubah-ubah)


3. lalu buka file yang berformat .pl tadi


4. Setelah itu tuliskan combine('In1.txt','In2.txt','Out.txt').


5. Hasilnya akan muncul file baru bernama Out.txt dan isinya adalah gabungan antara In1 dan In2 seperti ini






SOAL 5
Define and test a predicate compare that reads in two text files term by term
and for each pair of corresponding terms outputs a message either saying that they
are the same or that they are different. Assume that both files contain the same
number of terms and that the final term in each is end.
JAWAB
1. deklarasikan dan simpan dalam format .pl

2. Lalu buat file bernama Satu.txt dan Dua.txt, isinya seperti di bawah ini





 5. setelah itu buka file berformat .pl tadi, dan ketikkan compare('Satu.txt','Dua.txt'). maka hasilnya akan seperti berikut



Tidak ada komentar:

Posting Komentar