Das in der letzten Aufgabe (Blatt 2) zu erstellende Programm soll nun nach folgenden Vorgaben restrukturiert und erweitert werden:
(* ----------- Data of a Person with its Operations -------- *) CONST NameLength = 30; PhoneLength = 15; TYPE Name = ARRAY[0..NameLength] OF CHAR; Phone = ARRAY [0..PhoneLength] OF CHAR; Date = RECORD day : CARDINAL[1..31]; month: CARDINAL[1..12]; year: CARDINAL[1900..2100]; END; PersDat = RECORD famName: Name; firstName: Name; birthDate: Date; phone: Phone; END; PROCEDURE nameIsLess(x,y: PersDat): BOOLEAN; (* returns TRUE, if x.famName less than y.famName *) PROCEDURE nameIsEqual(x,y: PersDat):BOOLEAN; (* returns TRUE, if x.famName = y.famName *) PROCEDURE isYounger(x,y: PersDat): BOOLEAN; (* returns TRUE, if person x is younger than person y *) PROCEDURE sameAge(x,y: PersDat): BOOLEAN; (* returns TRUE, if persons x and y have the same birthdate *) PROCEDURE WriteRec(f: FILE; pers: PersDat); (* f - open stream for writing * writes data with one blank as separator *) PROCEDURE ReadRec(f:FILE; VAR pers: PersDat):BOOLEAN; (* f - open stream for reading ! * reads one record assuming whitespace as separator * TRUE, if done, otherwise FALSE *) (* ----------- List of Person Data and Operations ------------ *) CONST NumberOfPers = 50; TYPE Range = [1..NumberOfPers]; RangeSet = SET OF Range; PersList = ARRAY Range OF PersDat; IndexList = ARRAY Range OF Range; VAR persList: PersList; nameList, ageList: IndexList; TYPE CmpPersDat = PROCEDURE(PersDat, PersDat):BOOLEAN; PROCEDURE InitPersList( fromFile: FILE; VAR persList: PersList; VAR number: CARDINAL): BOOLEAN; (* Separator is whiteSpace - no check !!! * number: the actually read number of records * TRUE, if number > 0, otherwise FALSE *) PROCEDURE WriteRecords( f: FILE; pList: PersList; number : CARDINAL; ind: RangeSet); (* writes a set of records, defined by ``ind'', * to open stream ``f'' *) PROCEDURE Sort( a: PersList; number: CARDINAL; cmp:CmpPersDat; VAR res: IndexList); (* sorts the records in ``a'' by building a sorted * index list ``res'' * comparing by function ``cmp'' *) PROCEDURE linSearch( VAR p: PersDat; number: CARDINAL; less, equal: CmpPersDat; persList: PersList; ind: IndexList; VAR res: RangeSet); (* the caller is responsible for consistency between * compare-procedures ``less'', ``equal'', * index list ``ind'' and definiton of components in ``p'' * * defines a set of indices ``res'' of list ``persList'' * containing records matching with components * defined in ``p'' using corresponding sorted index list *)
Aufruf des Programmes:
phones [ -n name | -b birthdate] inputfile
Das von Ihnen erwartete Programm phones soll also folgende Aufgaben erfüllen:
Viel Erfolg!