I made a program simulating that of the lobby of a hotel, and I have a problem with storing the record variables into the file...for some reason only those variables of type string are saved and those of integer and of array are not, or if they are stored, thay containg nothing. I can see this when I open the file, and later when trying to perform a search into the file, it obviously doesn't work. I really need some help!
Thanks in advanced :)
Program hotel;
{Created by Vivian Tabak
2010}
{This program is to be used at a hotel lobby ('Ocean View Hotel'), where a worker will decide whether to enter a passenger's information in order to make a reservation or to search for a passenger that has already made a reservation in the hotel.}
Uses crt;
Type
passenger = record {Creates the variables for the}
name: string [20]; {record file}
lastname: string[20];
date1:integer;
date2:integer;
numberofpassengers:string[1];
numberrooms:integer;
roomtype:array [1..50] of integer;
roomnumber:array [1..50] of integer;
{payment: string [7];
arrival: string [3];}
end; {End of the creation of record variables}
filerecord = file of passenger; {Creates the record file}
Var n, option: integer;
ssname, sslastname: char;
xx, yy, lengthl, widthw: integer;
profile: passenger; {Stores the record variables}
passengerfile : filerecord; {File to store the record for each passenger}
z, i, a, q: integer;
Procedure rectangle (var xr, yr, lengthr, widthr: integer); {Paramters of
the rectangle
procedure}
{Procedure to create a rectangle used to show data in an ordered structure; It creates the rectangle by reading the parameters of X coordinate, Y coordinate, length and width desired}
var aux1, aux2: integer;
Begin
gotoxy (xr,yr);
write ('É'); {Creates upper left corner}
gotoxy (xr,(yr+widthr+1));
write ('È'); {Creates lower left corner}
for aux1:= (xr+1) to (xr+lengthr) do {Creates upper and lower}
begin {horizontal lines}
gotoxy (aux1,yr);
write ('Í');
gotoxy (aux1,(yr+widthr+1));
write ('Í');
end;
gotoxy ((xr+lengthr+1),yr);
write ('»'); {Creates right upper corner}
gotoxy ((xr+lengthr+1),(yr+widthr+1));
write('¼'); {Creates left upper corner}
for aux2:= (yr+1) to (yr+widthr) do {Creates right and left}
begin {vertical lines}
gotoxy (xr, aux2);
write ('º');
gotoxy ((xr+lengthr+1), aux2);
write ('º');
end;
end;
Procedure reservation; {Procedure without parameters}
{This procedure allows information of a passenger to be entered, and for a
record of that passenger to be produced and stored in the file}
Begin
Textbackground (green); {Text background and text colour are stated}
Textcolor (white); {for this procedure}
Clrscr;
xx:=30; {Variable used to define x coordinate for the rectangle's upper right corner}
yy:=3; {Variable used to define y coordinate for the rectangle's upper left corner}
lengthl:=18; {Variable used to define length of the rectangle}
widthw:=2; {Variable used to define width of the rectangle}
rectangle (xx, yy, lengthl, widthw); {Rectangle procedure is called}
Gotoxy (33,4); {A screen for the input of the}
Write ('Passanger Data'); {passenger's name, lastname, }
{check-in date and check-out }
xx:=11; {date is show}
yy:=7;
lengthl:=57;
widthw:=13;
rectangle (xx, yy, lengthl, widthw);
gotoxy (24, 10);
write ('Name: ');
gotoxy (24, 12);
write ('lastname: ');
gotoxy (24, 14);
write ('Check-in date: ');
gotoxy (24, 15);
write ('(day & month number together)');
gotoxy (24, 17);
write ('Check-out date: ');
gotoxy (24, 18);
write ('(day & month number together)');
gotoxy (40, 10);
readln (profile.name);
gotoxy (40, 12);
readln (profile.lastname);
gotoxy (40, 14);
readln (profile.date1);
gotoxy (40, 17);
readln (profile.date2);
clrscr;
xx:=30;
yy:=3;
lengthl:=18;
widthw:=2;
rectangle (xx, yy, lengthl, widthw);
Gotoxy (32,4);
Write ('Room information');
xx:=11;
yy:=7;
lengthl:=57;
widthw:=13;
rectangle (xx, yy, lengthl, widthw);
gotoxy (24, 12);
write ('Number of passengers: ');
gotoxy (24, 14);
write ('Number of rooms: ');
gotoxy (46, 12);
readln (profile.numberofpassengers);
gotoxy (46, 14);
readln (n);
clrscr;
profile.numberrooms:=n;
For n:= 1 to profile.numberrooms do
begin
xx:=3;
yy:=2;
lengthl:=10;
widthw:=1;
rectangle (xx, yy, lengthl, widthw);
gotoxy (5,3);
write ('Room N§');
write (n);
read;
xx:=30;
yy:=4;
lengthl:=18;
widthw:=2;
rectangle (xx, yy, lengthl, widthw);
Gotoxy (35,5);
Write ('Room Type');
xx:=21;
yy:=8;
lengthl:=38;
widthw:=12;
rectangle (xx, yy, lengthl, widthw);
Gotoxy (30,9);
Write ('1 - Ocean View Single');
Gotoxy (30,11);
Write ('2 - Ocean View Double');
Gotoxy (30,13);
Write ('3 - City Sights Single');
Gotoxy (30,15);
Write ('4 - City Sights Double');
Gotoxy (30,17);
Write ('5 - Suite');
Gotoxy (30, 20);
Write ('Enter room type number: ');
readln (profile.roomtype[n]);
clrscr;
end;
xx:=15;
yy:=2;
lengthl:=13;
widthw:=2;
rectangle (xx, yy, lengthl, widthw);
Gotoxy (19,3);
Writeln ('Name');
xx:=30;
yy:=2;
lengthl:=13;
widthw:=2;
rectangle(xx, yy, lengthl, widthw);
Gotoxy (33, 3);
writeln ('Lastname');
xx:=45;
yy:=2;
lengthl:=16;
widthw:=2;
rectangle(xx, yy, lengthl, widthw);
Gotoxy (48,3);
Writeln ('Room Number');
xx:=15;
yy:=6;
lengthl:=13;
widthw:=n+2;
rectangle(xx, yy, lengthl, widthw);
Gotoxy (17,8);
Writeln (profile.name);
xx:=30;
yy:=6;
lengthl:=13;
widthw:=n+2;
rectangle(xx, yy, lengthl, widthw);
Gotoxy (32,8);
Writeln (profile.lastname);
xx:=45;
yy:=6;
lengthl:=16;
widthw:=n+2;
rectangle(xx, yy, lengthl, widthw);
Randomize;
For i:=1 to profile.numberrooms do
Begin
Gotoxy (47,7+i);
Write ('Room N§');
Gotoxy (54,7+i);
Write (i);
profile.roomnumber[i]:= Random(49)+1;
Gotoxy (58,7+i);
write (profile.roomnumber[i]);
end;
Read;
Read;
Assign (passengerfile, 'C:\Hotel\hotel.txt');
Reset (passengerfile);
Seek (passengerfile, filesize(passengerfile));
Write (passengerfile, profile);
Readln;
Close (passengerfile);
end; {End procedure}
Procedure Search (sname, slastname: char);
Var p:integer;
sfullname: string[45];
coma:char;
count: integer;
letra: char;
Begin
Assign (passengerfile, 'C:\Hotel\hotel.txt');
Reset (passengerfile);
Read (sname, slastname);
While not (EOF (passengerfile)) do
Begin
Read (passengerfile, profile);
with profile do
Begin
If name= profile.name then
Begin
If slastname= profile.lastname then
Begin
Gotoxy (4,4);
write (passengerfile, profile);
Readln;
end;
end;
end;
end;
end;
Begin
Textbackground (red);
Textcolor (white);
Clrscr;
xx:=4;
yy:=2;
lengthl:=71;
widthw:=20;
rectangle (xx, yy, lengthl, widthw);
Gotoxy (26,4);
Writeln ('Welcome to Ocean View Hotel');
Gotoxy (26,5);
Writeln ('°°°°°°°°°°°°°°°°°°°°°°°°°°°');
Gotoxy (7,9);
Writeln ('ùChoose 1 if you would like to enter a reservation');
Gotoxy (7,11);
Writeln ('ùChoose 2 if you would like to search for a passsanger in the hotel');
Gotoxy (27,15);
Write ('Insert number of choice: ');
Readln (option);
Clrscr;
Case option of
1: reservation;
2: Begin
xx:=4;
yy:=2;
lengthl:=71;
widthw:=20;
rectangle (xx, yy, lengthl, widthw);
Gotoxy (26,4);
Writeln ('Passenger Search');
Gotoxy (7,9);
Writeln ('Enter passenger name: ');
Gotoxy (7,11);
Writeln ('Enter passenger lastname: ');
Gotoxy (34,9);
Readln (ssname);
Gotoxy (34,11);
Readln (sslastname);
Clrscr;
search (ssname, sslastname);
readln;
end;
end;
end.