I have to make a program with the following features.
- array of records
TYPE employeeRecord = RECORD name: STRING; surname: STRING; age: Integer; END; employeeRecords = ARRAY OF employeeRecord ;
- a procedure/function to ADD data into the array
I did this one and I think it is working fine!
- a procedure/function to DELETE data from the array
I have problems with this procedure. It doesn't work when I try to delete the data in the first position of the array. Here's what I did so far:
PROCEDURE delete(VAR records: employeeRecords); VAR n, j: Integer; nameDel: STRING; BEGIN Write('Name: '); Readln(nameDel); n := 0; WHILE (records[n].name <> nameDel) AND (n < High(records)) DO BEGIN inc(n); END; IF records[n].name <> nameDel THEN BEGIN Writeln('That employee could not be found!'); Writeln; END; IF records[n].name = nameDel THEN BEGIN FOR j := n TO High(records)-1 DO BEGIN records[j].name := records[j+1].name; records[j].surname := records[j+1].surname; records[j].age:= records[j+1].age; SetLength(records, High(records)); // MAYBE THIS LINE IS NOT CORRECT END END END;
If you have some ideas, please let me know. Thanks in advance!