Hello again,
I have another assignment and need some help again.
This time, I have to display the contents of a record file, consisting of contact information for a list of people.
I have to create a text file with several lines of contact information- surname, firstname, email and tel number.
I have to use the newly created text file as input and create a record for each person and store in a file. After the record has been created, allow the user the option to see all records stored. The records should be displayed in the following order- Firstname, Surname, Tel number and email.
I completed the code for this program but it refuses to compile. Can someone please check my code and see where I went wrong and how to correct it?
Here is the code-
Program Directory (infile, Data, output);
{Program to display the contents of a record file, consisting of contact
information for a list of people}
{This Program is expecting input from a text file, after which, the data
will be both outputted to the screen and to a newly created text file}
TYPE
REC_TYPE = RECORD {creates the variables for the Record File}
FIRST_NAME : STRING [20];
SURNAME : STRING [20];
TEL : STRING [8];
EMAIL : STRING [25];
END; {End the creation of record variables}
FILETYPE = FILE OF REC_TYPE; {Creates the Record File}
VAR
Profile : REC_TYPE; {Stores the Record Variables}
Data : FILETYPE; {File to store the record for each person's contact info}
infile : TEXT; {indicates that the file is a text file}
Choice : CHAR; {variable for Choice made}
count : INTEGER;
{**************************************************************************}
PROCEDURE Display_Instructions; {Procedure without Parameters}
{This Procedure Displays Instructions On How To Use The Program}
BEGIN
WRITELN ('This Program Displays Contact Information for a List of People.');
WRITELN ('When the Program Commences, Please Choose One of the Options.');
WRITELN ('If you choose YES, the information will be displayed.');
WRITELN ('If you choose NO, the program will terminate.');
END; {End Procedure}
{***************************************************************************}
PROCEDURE Decision; {Procedure without Parameters}
BEGIN
WRITELN ('Would You Like To View the Contact List?');
WRITELN ('Y : Yes');
WRITELN ('N : No');
END; {End Procedure}
{***************************************************************************}
PROCEDURE Contact_Data; {Procedure without Parameters}
{This Procedure allows for input and output of data to the text file}
BEGIN
ASSIGN (infile, 'G:\Assignment2\Directory.txt');
RESET (infile);
ASSIGN (Data, 'G:\Assignment2\Data.txt');
REWRITE (Data);
WHILE NOT (EOF (infile)) DO
BEGIN
READLN (infile);
{End WITH}
END; {End WHILE}
RESET (Data);
END; {End Procedure}
{***************************************************************************}
PROCEDURE Information; {Procedure without Parameters}
{This Procedure allows the data to be output to the screen}
BEGIN
count := 0;
WHILE NOT (EOF (Data)) DO
BEGIN
READLN (Data);
WITH Profile DO
BEGIN
WRITELN ('Firstname, , Surname, , Tel, , Email, ,');
count := count + 1;
END;
END;
END;
{***************************************************************************}
BEGIN {Program Starts Here}
Display_Instructions;
WRITELN; {Allows a Line to be skipped}
Decision;
WRITELN; {Allows a Line to be skipped}
WRITELN ('Please Enter Your Choice');
READLN (Choice);
WHILE (Choice = 'Y') OR (Choice = 'y') OR (Choice = 'N') OR (Choice = 'n') DO
BEGIN
IF (Choice = 'Y') OR (Choice = 'y') THEN
Information
ELSE IF (Choice = 'N') OR (Choice = 'n') THEN
WRITELN ('No Records Are Currently Being Displayed');
READLN (Choice); {Prevents Eternal Looping of the Records}
{End IF}
{End ELSE}
END; {End While}
Contact_Data;
END. {End Program}