Uploaded by Dr. Mabrouka Abuhmida

Lab 3

advertisement
Tutorial 3-Term2
Prolog
Task 1
Create a text file testa.txt containing two lines, each of five characters followed
by a new line, e.g.
Define a predicate readfile that will read fifteen characters from this file one by one and output the ASCII value
of each character.
Task 2
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.
Task 3
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.
Task 4
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.
Download