HouseLocator
Author |
Message |
MossyMossy
|
Posted: Wed Feb 24, 2010 10:04 am Post subject: HouseLocator |
|
|
What is it you are trying to achieve?
Write a program to prepare a disk file of records called
OnHand suitable for use in the HouseLocator program of this
chapter. In the HouseLocator program the records are read
from the file HouseInfo by the procedure readFile. Change
this procedure so that records for houses are read from the
disk file OnHand. You can use the Turing editor if you are
having difficulty prepare the file OnHand.
What is the problem you are having?
I have no idea how to do this.
Turing: |
% The "HouseLocator" program
% Reads series of records for houses
% Allows questions about records in file
type houseType :
record
color : string (10)
location : string (20)
price : int
end record
const maxHouses := 100
var houseFile : array 1 .. maxHouses of houseType
procedure readFile (var entry : array 1 .. * of houseType, var count :
int)
% Read houseType records into an array
var sale : int
open : sale, "OnHand.txt", get
assert sale > 0
count := 0
loop
get : sale, skip
exit when eof (sale )
count := count + 1
bind var house to entry (count )
get : sale, house. color : 10, house.location : 20,
house.price
end loop
end readFile
procedure outputRecord (h : houseType )
put h. color : 10, h.location : 20, h.price : 10
end outputRecord
function wanted (house : houseType, desiredColor, desiredLocation :
string (*),
desiredUpperPrice : int) : boolean
result (house. color = desiredColor or
desiredColor = "any ")
and (house.location = desiredLocation
or desiredLocation = "any ")
and (house.price <= desiredUpperPrice )
end wanted
procedure readSpecs (var Color : string (*), var location : string (*),
var price : int)
put "Answer 'any' for color or location when it doesn't matter."
put "What color of house do you want?"
get Color % must pad with blanks
Color := Color + repeat (" ", upper (Color ) - length (Color ))
put "What location of house do you want?"
get location % must pad with blanks
location := location + repeat (" ", upper (location ) - length (location ))
put "What is your highest price in dollars?"
get price
end readSpecs
var howMany : int
readFile (houseFile, howMany )
var wantedColor : string (10)
var wantedLocation : string (20)
var upperPrice : int
readSpecs (wantedColor, wantedLocation, upperPrice )
for i : 1 .. howMany
if wanted (houseFile (i ), wantedColor,
wantedLocation, upperPrice ) then
outputRecord (houseFile (i ))
end if
end for
|
Please help me. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|