program Variant(input,output); {Input 2 variant student records, output the records.} type IDType = 1..2500; String30 = String[30]; AddressType = record Line1 : String30; Line2 : String30 end; PhoneType = String30; Residestype = 'O'..'S'; ResidenceCode = 'A'..'Z'; RoomNoType = 1..250; StuRecType = record ID : IDType; Name : String30; case Resides : Residestype of 'R' : (Residence : Residencecode; Room : RoomNoType; RPhone : PhoneType); {note can't use Phone twice} 'S' : ( SAddress : AddressType; SPhone : PhoneType); 'O' : ( OAddress : AddressType; OPhone : PhoneType) end; {no end for `case' needed} var St1,St2 : StuRecType; procedure ReadResides ( var FSt : StuRecType); {pre : none post : data in FPersInfo} begin WriteLn('Input accomodation type : R, S or O'); With Fst do begin ReadLn(Resides); case Resides of 'R' : begin WriteLn('Input residence code, room number, phone number - '); WriteLn('one per line'); ReadLn(Residence); ReadLn(Room); ReadLn(Rphone) end; 'S' : begin WriteLn ('Input a two-line address, followed by a phone number'); ReadLn(SAddress.Line1); ReadLn(SAddress.Line2); ReadLn(SPhone); WriteLn end; 'O' : begin WriteLn ('Input a two-line address, followed by a phone number'); ReadLn(OAddress.Line1); ReadLn(OAddress.Line2); ReadLn(OPhone) end else WriteLn('Bad accommodation code') end {case} end {with Fst} end;{ReadResides} procedure ReadStu (var FStu {output} : StuRecType); { Reads one student record into FStu. Pre : None Post: Data are read into record FStu. } begin {ReadStu} with FStu do begin Write ('ID> '); ReadLn (ID); Write ('Name> '); ReadLn (Name); ReadResides (FStu); end {with} end; {ReadStu} procedure WriteStu( FStu {input} : StuRecType ); begin with FStu do begin Write ('ID = ', ID :4); WriteLn (' Name: ', Name); case Resides of 'R' : begin WriteLn('Residence code: ',Residence); WriteLn('Room number :',Room); WriteLn('Phone number :',RPhone); end; 'S' : begin WriteLn ('Address: ',SAddress.Line1); WriteLn (' ',SAddress.Line2); WriteLn ('Phone: ',SPhone); end; 'O' : begin WriteLn ('Address: ',OAddress.Line1); WriteLn (' ',OAddress.Line2); WriteLn ('Phone: ',OPhone); end else WriteLn('Bad accommodation code') end; {case} WriteLn; end; {with FStu} end; {WriteStu} begin{main} ReadStu(St1); ReadStu(St2); WriteLn; WriteLn('The student records are : '); WriteStu(St1); WriteStu(St2) end.