Rabu, 25 November 2009

INPUT AND OUTPUT

The Answer of Practical Exercise 5 Page : 82-83.

1. Number 1 is about predicate makelower

if we want to convert any upper case letters to lower case, we must write some rules or program in notepad use predicate makelower in order that we can consult it in SWI Prolog. for the first we can write some rules in notepad like the picture below:


After you write its program,
you must write makelower . and enter character that you want on your SWI Prolog. So, you can see the result will be shown in SWI Prolog like the picture below:


2. Number 2 is about predicate copyterms

if we want to reads all the term in a text file and outputs them as terms to another text file one by one on separates lines, we must use predicate copyterms. for the first we must make a file in notepad for input file and save as with txt. format. we give name "infile" for our file.

second, we must make a new file again in notepad for output file, we give name "outfile" for our file.
third, we must make some rules in notepad like this picture below in order that we can consult it to SWI Prolog.
After you write its program, you must write copyterms(‘infile.txt’,'outfile.txt’) . or enter the file's name of your file on your SWI Prolog. So, you can see the result will be shown in SWI Prolog like the picture below:

3. Number 3 is about predicate readfile

if we want to convert a characters to the ASCII value, we can use predicate readfile. according to question number 3, we must make a file in notepad which we must write:

Giving name of the file "tesla" and save it with .txt fomat.
in order we can consult on SWI Prolog, so we must make some rules in notepad like this picture below:

After you write its program, So, you can see the result will be shown in SWI Prolog like the picture below:


4. Number 4 is about predicate combine


create 2 text files in1.txt and in2.txt, each comprising a number of terms terminated by end. you can see this picture below:

to define a predicate combine that takes names of two input files as its first two arguments and the name of an output file as its third argument. in order that the output file contain the terms in the first input file followed by the terms in the second, you must write some rules using predicate combine in notepad like the picture below:



After you write its program, So, you can see the result will be shown in SWI Prolog like the picture below:



5. Number 5 is about predicate compare

in order that we can reads that two text files term by term and each pair of corresponding terms output a messsage saying that they are the same or different, we must make two text files which contain the same number of terms and the final term in each is end. Look the picture below:


then, we must make some rules in notepad using predicate compare like this picture below in order that we can consult it to SWI Prolog.


After you write its program, So, you can see the result will be shown in SWI Prolog like the picture below:





Slide 4

1 komentar: