home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
simtel
/
sigm
/
vols000
/
vol063
/
nad-3.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1984-04-29
|
23KB
|
1,075 lines
{A NAME AND ADDRESS PROGRAM BY: CRAIG RUDLIN, M.D.
202 OVERLOOK ROAD
RICHMOND, VIRGINIA 23229
VERSION 3.0}
PROGRAM NAD; {$P}
CONST
CITY_ONE = 'RICHMOND ';
STATE_ONE = 'VIRGINIA ';
CITY_TWO = 'BOSTON ';
STATE_TWO = 'MASS ';
TYPE
MAILING = RECORD
NAME:ARRAY[1..30] OF CHAR;
STREET_NUMBER:ARRAY[1..6] OF CHAR;
STREET: ARRAY[1..20] OF CHAR;
CITY: ARRAY[1..18] OF CHAR;
STATE:ARRAY[1..10] OF CHAR;
ZIP:ARRAY[1..10] OF CHAR;
ATTENTION:ARRAY[1..30] OF CHAR;
ACCT_NUMBER:ARRAY[1..4] OF CHAR;
END;
ALPHABET = RECORD
START:INTEGER;
FINISH:INTEGER;
END;
FA=FILE OF ALPHABET;
F = FILE OF MAILING;
$STRING80 = STRING 80;
$STRING0 = STRING 0;
$STRING255 = STRING 255;
$STRING14 = STRING 14;
TR = ARRAY [1..4] OF CHAR;
VAR
FIN: F;
FALP:FA;
COUNTER,I,N:INTEGER;
INFORMATION: MAILING;
NUMBER_OF_RECORDS: INTEGER;
NA,ST_NO,ST,CIT,STA,ZI,ATT: $STRING80;
COR_FLAG,FINISH,CONTINUE,NEWFILE,LISTING: BOOLEAN;
ANSWER:CHAR;
ALPFILE,SORTFILE,FILENAM:$STRING14;
REC_NUMBER,END_OF_FILE:INTEGER;
DESIRED_NAME:ARRAY[1..30] OF CHAR;
DES_NAM:$STRING80;
FOUND:BOOLEAN;
CHANGE_RECORD,DELETE_RECORD,FIND_RECORD,ADD_TO_FILE:BOOLEAN;
PROCEDURE SETLENGTH(VAR X: $STRING0; Y:INTEGER);EXTERNAL;
FUNCTION LENGTH(X:$STRING255):INTEGER;EXTERNAL;
PROCEDURE CLEAR_SCREEN;
BEGIN
WRITE (CHR(27),'*',CHR(0),CHR(0),CHR(0),CHR(0));
END;
PROCEDURE ERASE_LINES(STARTING_LINE,NUMBER_OF_LINES:INTEGER);
VAR
I:INTEGER;
BLANKS:STRING 80;
BEGIN
BLANKS:=' ';{40SPACES}
FOR I:= 1 TO NUMBER_OF_LINES DO
BEGIN
WRITE(CHR(27),'=',CHR(STARTING_LINE+31),CHR(32),BLANKS,BLANKS);
STARTING_LINE:=STARTING_LINE + 1;
END
END;
PROCEDURE MOVE_CURSOR (X,Y:INTEGER);
BEGIN
WRITE(CHR(27),'=',CHR(Y+31),CHR(X+31));
END;
PROCEDURE PROMPT (X,Y,LENGTH:INTEGER; P:$STRING80;
PROTECTED_FIELD_DESIRED:BOOLEAN);
VAR
UNDERLINE:STRING 80;
I:INTEGER;
BEGIN
UNDERLINE:='_';
FOR I:= 1 TO LENGTH DO APPEND(UNDERLINE,'_');
IF PROTECTED_FIELD_DESIRED = FALSE THEN
WRITE(CHR(27),'=',CHR(Y+31),CHR(X+31),P,UNDERLINE)
ELSE
WRITE(CHR(27),'=',CHR(Y+31),CHR(X+31),')',P,
UNDERLINE,CHR(27),'(');
END;
FUNCTION INPUT_DATA (X,Y,LEN:INTEGER; ALPHANUMERIC:BOOLEAN;
MAXIMUM_VALUE,MINIMUM_VALUE:REAL):$STRING80;
VAR
DATA,BLANKS:$STRING80;
I:INTEGER;
PROCEDURE CORRECT(X,Y:INTEGER);
VAR
I,A,B:INTEGER;
BEGIN
ERASE_LINES(20,2);
WRITE (CHR(7));
MOVE_CURSOR (1,20);
IF (ALPHANUMERIC = TRUE) AND (LENGTH(DATA)>LEN) THEN
WRITE('TERM TOO LONG');
MOVE_CURSOR(X,Y);
WRITE(' ');
A:=X;
B:=Y;
FOR I:= 1 TO LENGTH(DATA) DO
BEGIN
MOVE_CURSOR(A,B);
WRITE(' ');
A:=A+1;
END;
MOVE_CURSOR(X,Y);
WRITE('_');
A:=X;
B:=Y;
FOR I:= 1 TO (LEN-1) DO
BEGIN
MOVE_CURSOR(A,B);
WRITE('_');
A:=A+1;
END;
MOVE_CURSOR(X,Y);
READ(DATA);
ERASE_LINES(20,1);
END;
BEGIN
BLANKS:=' ';{40SPACES}
MOVE_CURSOR(X,Y);
READ(DATA);
WHILE(ALPHANUMERIC = TRUE) AND (LENGTH(DATA) > LEN) DO CORRECT(X,Y);
IF LENGTH(DATA) = 0 THEN
BEGIN
DATA:=' ';
FOR I:=1 TO (LEN-1) DO APPEND(DATA,' ');
END;
IF LENGTH(DATA) < LEN THEN
FOR I:= LENGTH(DATA) TO LEN DO APPEND(DATA,' ');
INPUT_DATA:=DATA;
END;
{************ PROCEDURE TO DETERMINE NUMBER RECORDS IN FILE ******}
PROCEDURE NUMBER_RECORDS(FILENAM:$STRING14);
BEGIN
RESET(FILENAM,FIN);
WITH INFORMATION DO
BEGIN
READ(FIN:1,INFORMATION);
NUMBER_OF_RECORDS:=(((ORD(ACCT_NUMBER[1])-48)*1000)+
((ORD(ACCT_NUMBER[2])-48)*100)+
((ORD(ACCT_NUMBER[3])-48)*10)+
((ORD(ACCT_NUMBER[4])-48)*1));
END; {OF WITH}
END; {OF PROCEDURE}
{********** DETERMINE THE CURRENT NUMBER OF RECORDS *******}
PROCEDURE CALC_ACCT_NO(CURRENT_NUMBER_OF_RECORDS:INTEGER);
VAR
ONES,TENS,HUNDREDS,THOUSANDS:CHAR;
O,T,H,TH:INTEGER;
BEGIN
O:=0;
T:=0;
H:=0;
TH:=0;
WITH INFORMATION DO
BEGIN
IF CURRENT_NUMBER_OF_RECORDS < 10 THEN
BEGIN
ONES:=CHR(CURRENT_NUMBER_OF_RECORDS + 48);
ACCT_NUMBER[1]:='0';
ACCT_NUMBER[2]:='0';
ACCT_NUMBER[3]:='0';
ACCT_NUMBER[4]:=ONES;
END; {IF}
IF CURRENT_NUMBER_OF_RECORDS = 10 THEN ACCT_NUMBER:='0010';
IF CURRENT_NUMBER_OF_RECORDS = 100 THEN ACCT_NUMBER:='0100';
IF CURRENT_NUMBER_OF_RECORDS = 1000 THEN ACCT_NUMBER:='1000';
IF (CURRENT_NUMBER_OF_RECORDS < 100) AND
(CURRENT_NUMBER_OF_RECORDS > 10) THEN
BEGIN
WHILE (CURRENT_NUMBER_OF_RECORDS < 100) AND
(CURRENT_NUMBER_OF_RECORDS > 10) DO {FOR VALUE 1-99}
BEGIN
CURRENT_NUMBER_OF_RECORDS:=CURRENT_NUMBER_OF_RECORDS-10;
T:=T+1;
IF CURRENT_NUMBER_OF_RECORDS < 10 THEN
BEGIN
ONES:= CHR(CURRENT_NUMBER_OF_RECORDS + 48);
TENS:=CHR(T+48);
ACCT_NUMBER[1]:='0';
ACCT_NUMBER[2]:='0';
ACCT_NUMBER[3]:=TENS;
ACCT_NUMBER[4]:=ONES;
END; {IF}
END; {WHILE}
END; {OF IF}
IF (CURRENT_NUMBER_OF_RECORDS < 10000) AND
(CURRENT_NUMBER_OF_RECORDS > 100) THEN
BEGIN
IF CURRENT_NUMBER_OF_RECORDS < 1000 THEN THOUSANDS:='0';
BEGIN
WHILE (CURRENT_NUMBER_OF_RECORDS < 10000) AND
(CURRENT_NUMBER_OF_RECORDS >= 1000) DO
BEGIN
CURRENT_NUMBER_OF_RECORDS:=CURRENT_NUMBER_OF_RECORDS - 1000;
TH:=TH+1;
IF CURRENT_NUMBER_OF_RECORDS < 1000 THEN THOUSANDS:=CHR(TH+48);
END;
IF CURRENT_NUMBER_OF_RECORDS < 100 THEN HUNDREDS:='0';
WHILE (CURRENT_NUMBER_OF_RECORDS < 1000) AND
(CURRENT_NUMBER_OF_RECORDS >= 100) DO
BEGIN
CURRENT_NUMBER_OF_RECORDS:=CURRENT_NUMBER_OF_RECORDS-100;
H:=H+1;
IF CURRENT_NUMBER_OF_RECORDS < 100 THEN HUNDREDS:=CHR(H+48);
END;
IF CURRENT_NUMBER_OF_RECORDS < 10 THEN TENS:='0';
WHILE (CURRENT_NUMBER_OF_RECORDS < 100) AND
(CURRENT_NUMBER_OF_RECORDS >= 10) DO
BEGIN
CURRENT_NUMBER_OF_RECORDS:=CURRENT_NUMBER_OF_RECORDS-10;
T:=T+1;
IF CURRENT_NUMBER_OF_RECORDS < 10 THEN TENS:=CHR(T+48);
END;
ONES:=CHR(CURRENT_NUMBER_OF_RECORDS+48);
END;
ACCT_NUMBER[1]:=THOUSANDS;
ACCT_NUMBER[2]:=HUNDREDS;
ACCT_NUMBER[3]:=TENS;
ACCT_NUMBER[4]:=ONES;
IF CURRENT_NUMBER_OF_RECORDS = 10 THEN ACCT_NUMBER:='0010';
IF CURRENT_NUMBER_OF_RECORDS = 100 THEN ACCT_NUMBER:='0100';
IF CURRENT_NUMBER_OF_RECORDS = 1000 THEN ACCT_NUMBER:='1000';
END; {OF IF}
END; {OF WITH INFORMATION DO}
END; {OF PROCEDURE}
{******************** PRINT THE FILE ********************}
PROCEDURE PRINT_FILE(FILENAM:$STRING14);
TYPE
C = FILE OF CHAR;
VAR
CONTINUE,ANSWER:CHAR;
AC,HARDCOPY: BOOLEAN;
FOUT: C;
COUNTER:INTEGER;
BEGIN
CLEAR_SCREEN;
REPEAT
WRITELN;
WRITE ('DO YOU WANT THE ACCOUNT NUMBER INCLUDED IN THE PRINT OUT? Y/N ');
READ(ANSWER);
UNTIL (ANSWER = 'Y') OR (ANSWER = 'N');
IF ANSWER = 'Y' THEN AC:=TRUE ELSE AC:=FALSE;
REPEAT
WRITELN;
WRITE ('DO YOU WANT A HARDCOPY OF THE FILE? Y/N ');
READ(ANSWER);
UNTIL (ANSWER = 'Y') OR (ANSWER = 'N');
IF ANSWER = 'Y' THEN
BEGIN
HARDCOPY:=TRUE;
REWRITE('LST:',FOUT);
WRITELN('PREPARE PRINTER TO RECEIVE LISTING.');
WRITELN('WHEN READY, TYPE A CARRIAGE RETURN.');
READ(ANSWER);
CLEAR_SCREEN;
WRITELN('FILE IS NOW BEING PRINTED.');
END;
IF ANSWER = 'N' THEN HARDCOPY:= FALSE;
RESET(FILENAM,FIN);
CLEAR_SCREEN;
NUMBER_RECORDS(FILENAM);
WITH INFORMATION DO
BEGIN
COUNTER:=0;
FOR I:= 2 TO NUMBER_OF_RECORDS DO
BEGIN
READ(FIN:I,INFORMATION);
IF NAME <> 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ' THEN {DO'NT PRINT DELETED RECORDS}
BEGIN
IF HARDCOPY = FALSE THEN
BEGIN
WRITELN;
WRITELN (NAME);
WRITELN(STREET_NUMBER,' ',STREET);
WRITELN(CITY,' ',STATE,' ',ZIP);
WRITELN;
COUNTER:=COUNTER+5;
IF ATTENTION <> ' ' THEN
BEGIN
WRITELN('ATT: ',ATTENTION);
COUNTER:=COUNTER+1;
END; {OF THIS IF}
IF AC = TRUE THEN
BEGIN
WRITELN;
WRITELN('ACCOUNT NUMBER: ',ACCT_NUMBER);
COUNTER:=COUNTER+1;
END;
IF COUNTER >= 21 THEN
BEGIN
PROMPT(1,23,0,'ENTER ANY CHARACTER TO CONTINUE',FALSE);
READ(CONTINUE);
ERASE_LINES(23,1);
COUNTER:=0;
END;
END; {FOR HARDCOPY = FALSE}
IF HARDCOPY = TRUE THEN
BEGIN
WRITELN(FOUT,NAME);
WRITELN(FOUT,STREET_NUMBER,' ',STREET);
WRITELN(FOUT,CITY,' ',STATE,' ',ZIP);
WRITELN(FOUT,' ');
IF ATTENTION <> ' ' THEN
WRITELN(FOUT,'ATT: ',ATTENTION);
IF AC = TRUE THEN
BEGIN
WRITELN(FOUT,' ');
WRITELN(FOUT,'ACCOUNT NUMBER: ',ACCT_NUMBER);
WRITELN(FOUT,' ');
END;
IF AC = FALSE THEN WRITELN(FOUT,' ');
WRITELN(FOUT,' ');
END; {FOR HARDCOPY = TRUE}
END; {OF NAME <> ZZZZZZ..}
END; {FOR LOOP}
END; {THIS IS FOR WITH STATEMENTS}
IF HARDCOPY = FALSE THEN
BEGIN
ERASE_LINES(22,2);
MOVE_CURSOR(1,22);
WRITE('ENTER A CARRIAGE RETURN TO CONTINUE PROGRAM');
READ(ANSWER);
END;
END; {OF PROCEDURE}
{***************** CREATING THE FIRST RECORD OF FILE *******}
PROCEDURE CREATE_FIRST_RECORD (ACTNO: TR);
BEGIN
IF (NEWFILE = TRUE) AND (CONTINUE = TRUE) THEN REWRITE(FILENAM,FIN);
WITH INFORMATION DO
BEGIN
NAME:=' ';
STREET_NUMBER:=' ';
STREET:=' ';
CITY:=' ';
STATE:=' ';
ZIP:=' ';
ATTENTION:='FIRST RECORD OF FILE ';
IF (NEWFILE = TRUE) AND (CONTINUE = TRUE) THEN ACCT_NUMBER:='0001';
IF (NEWFILE = TRUE) AND (CONTINUE = FALSE) THEN ACCT_NUMBER:=ACTNO;
IF NEWFILE = FALSE THEN ACCT_NUMBER:= ACTNO;
WRITE(FIN:1,INFORMATION);
END; {WITH LOOP}
END; {OF PROCEDURE}
{************** ENTER THE NAME OF THE FILE *****************}
PROCEDURE ENTER_FILE_NAME;
VAR
ERROR:BOOLEAN;
BEGIN
REPEAT
NEWFILE:=FALSE;
ERROR:=FALSE;
CLEAR_SCREEN;
WRITELN(' ENTER THE FILE NAME AS: DRIVE: NAME. EXTENSION');
WRITELN;
WRITELN(' WHERE DRIVE IS A SINGLE LETTER--EITHER A OR B');
WRITELN(' NAME IS UP TO 8 LETTERS OR SPACES');
WRITELN(' EXTENSION MUST HAVE 3 LETTERS OR SPACES');
WRITELN;
READLN(FILENAM);
RESET(FILENAM,FIN);
IF EOF(FIN) THEN
BEGIN
REPEAT
MOVE_CURSOR(1,10);
WRITE('FILE NOT FOUND. IS THIS A NEW FILE? Y/N');
READ (ANSWER);
UNTIL (ANSWER = 'Y') OR (ANSWER = 'N');
IF ANSWER = 'N' THEN ERROR:=TRUE;
IF ANSWER = 'Y' THEN NEWFILE:=TRUE ELSE NEWFILE:=FALSE;
IF NEWFILE = TRUE THEN CREATE_FIRST_RECORD('0001');
END; {OF IF EOF}
UNTIL ERROR = FALSE;
IF NEWFILE = TRUE THEN COUNTER:= 2;
IF NEWFILE = FALSE THEN
BEGIN
NUMBER_RECORDS(FILENAM);
COUNTER:=NUMBER_OF_RECORDS + 1;
END;
END; {OF PROCEDURE}
{*********** PROCEDURE TO CORRECT INCORRECT ENTRY ************}
PROCEDURE MISTAKE;
VAR
WRONG:CHAR;
BEGIN
WITH INFORMATION DO
BEGIN
ERASE_LINES(12,9);
PROMPT(1,12,0,'ENTER NUMBER OF INCORRECT INFORMATION',FALSE);
PROMPT(1,14,0,'1-NAME ',FALSE);
PROMPT(1,15,0,'2-# ',FALSE);
PROMPT(1,16,0,'3-STREET ',FALSE);
PROMPT(1,17,0,'4-CITY ',FALSE);
PROMPT(1,18,0,'5-STATE ',FALSE);
PROMPT(1,19,0,'6-ZIP ',FALSE);
PROMPT(1,20,0,'7-ATTENTION ',FALSE);
PROMPT(1,21,0,'8-ALL INFORMATION IS CORRECT AS DISPLAYED ',FALSE);
REPEAT
MOVE_CURSOR(50,16);
READ(WRONG);
CASE WRONG OF
'1':BEGIN
PROMPT(1,3,30,'NAME',FALSE);
NA:=INPUT_DATA(6,3,30,TRUE,0,0);
FOR I:= 1 TO 30 DO NAME[I]:=NA[I];
END;
'2': BEGIN
PROMPT(1,5,6,'#: ',FALSE);
ST_NO:=INPUT_DATA(4,5,6,TRUE,0,0);
FOR I:= 1 TO 6 DO STREET_NUMBER[I]:=ST_NO[I];
END;
'3': BEGIN
PROMPT(10,5,20,'STREET:',FALSE);
ST:=INPUT_DATA(19,5,20,TRUE,0,0);
FOR I:= 1 TO 20 DO STREET[I]:=ST[I];
END;
'4': BEGIN
PROMPT(1,7,10,'CITY: ',FALSE);
CIT:=INPUT_DATA(7,7,18,TRUE,0,0);
IF (CIT[1] <> '7') AND (CIT[1] <> '8') THEN
FOR I:= 1 TO 18 DO CITY[I]:=CIT[I];
IF CIT[1] = '7' THEN {DEFAULT TO FIRST VALUE, E.G. RICHMOND,VA.}
BEGIN
CITY:=CITY_ONE;
STATE:=STATE_ONE;
PROMPT(7,7,0,CITY_ONE,FALSE);
PROMPT(35,7,0,STATE_ONE,FALSE);
END;
IF CIT[1] = '8' THEN {DEFAULT TO SECOND VALUE}
BEGIN
CITY:=CITY_TWO;
STATE:=STATE_TWO;
PROMPT(7,7,0,CITY_TWO,FALSE);
PROMPT(35,7,0,STATE_TWO,FALSE);
END;
END;
'5': BEGIN
PROMPT(28,7,10,'STATE: ',FALSE);
STA:=INPUT_DATA(35,7,10,TRUE,0,0);
FOR I:= 1 TO 10 DO STATE[I]:=STA[I];
END;
'6': BEGIN
PROMPT(48,7,10,'ZIP: ',FALSE);
ZI:= INPUT_DATA(54,7,10,TRUE,0,0);
FOR I:= 1 TO 10 DO ZIP[I]:=ZI[I];
END;
'7': BEGIN
PROMPT(1,9,30,'ATTENTION: ',FALSE);
ATT:=INPUT_DATA(12,9,30,TRUE,0,0);
FOR I:= 1 TO 30 DO ATTENTION[I]:=ATT[I];
END;
END; {OF CASE}
UNTIL WRONG = '8';
END; {OF WITH INFORMATION}
ERASE_LINES(10,12);
END; {OF PROCEDURE}
{***************** OFFER A LISTING OF THE FILE **************}
PROCEDURE OFFER_LISTING(FILENAM:$STRING14);
BEGIN
REPEAT
ERASE_LINES(20,1);
PROMPT(1,20,1,'DO YOU WANT A LISTING OF THE FILE? Y/N ',FALSE);
MOVE_CURSOR(50,20);
READ(ANSWER);
UNTIL (ANSWER = 'Y') OR (ANSWER = 'N');
IF ANSWER = 'Y' THEN PRINT_FILE(FILENAM);
END; {OF PROCEDURE}
{******* PROC TO GET INFORMATION & PUT INFORMATION INTO FILE ******}
PROCEDURE ENTER_INFORMATION;
BEGIN
WITH INFORMATION DO
BEGIN
CLEAR_SCREEN;
PROMPT(1,3,30,'NAME',FALSE);
PROMPT(1,5,6,'#: ',FALSE);
PROMPT(10,5,20,'STREET: ',FALSE);
PROMPT(1,7,18,'CITY: ',FALSE);
PROMPT(28,7,10,'STATE: ',FALSE);
PROMPT(48,7,10,'ZIP: ',FALSE);
PROMPT(1,9,30,'ATTENTION: ',FALSE);
MOVE_CURSOR(1,22);
WRITE('ENTERING EXIT FOR THE NAME TERMINATES THIS PROCEDURE');
MOVE_CURSOR(1,23);
WRITE('DEFAULT VALUES FOR CITY AND STATE ARE:');
MOVE_CURSOR(40,23);
WRITE('7 = RICHMOND,VA. 8 = BOSTON,MASS.');
NA:=INPUT_DATA(6,3,30,TRUE,0,0);
FOR I:= 1 TO 30 DO NAME[I]:=NA[I];
IF NAME <> 'EXIT ' THEN
BEGIN
ST_NO:=INPUT_DATA(4,5,6,TRUE,0,0);
ST:=INPUT_DATA(19,5,20,TRUE,0,0);
CIT:=INPUT_DATA(7,7,18,TRUE,0,0);
IF (CIT[1] <> '7') AND (CIT[1] <> '8') THEN
STA:=INPUT_DATA(35,7,10,TRUE,0,0);
IF CIT[1] = '7' THEN {DEFAULT TO VALUE ONE, E.G. RICHMOND,VA.}
BEGIN
CITY:=CITY_ONE;
STATE:=STATE_ONE;
PROMPT(7,7,0,CITY_ONE,FALSE);
PROMPT(35,7,0,STATE_ONE,FALSE);
END;
IF CIT[1] = '8' THEN {DEFAULT TO VALUE TWO}
BEGIN
CITY:=CITY_TWO;
STATE:=STATE_TWO;
PROMPT(7,7,0,CITY_TWO,FALSE);
PROMPT(35,7,0,STATE_TWO,FALSE);
END;
ZI:=INPUT_DATA(54,7,10,TRUE,0,0);
ATT:=INPUT_DATA(12,9,30,TRUE,0,0);
FOR I:= 1 TO 30 DO NAME[I]:=NA[I];
FOR I:= 1 TO 6 DO STREET_NUMBER[I]:=ST_NO[I];
FOR I:= 1 TO 20 DO STREET[I]:=ST[I];
IF (CIT[1] <> '7') AND (CIT[1] <> '8') THEN
BEGIN
FOR I:= 1 TO 18 DO CITY[I]:=CIT[I];
FOR I:= 1 TO 10 DO STATE[I]:=STA[I];
END;
FOR I:= 1 TO 10 DO ZIP[I]:=ZI[I];
FOR I:= 1 TO 30 DO ATTENTION[I]:=ATT[I];
CALC_ACCT_NO(COUNTER);
REPEAT
PROMPT(1,20,1,'IS INFORMATION CORRECT AS ENTERED? Y/N',FALSE);
MOVE_CURSOR(50,20);
READ(ANSWER);
UNTIL (ANSWER = 'Y') OR (ANSWER = 'N');
IF ANSWER = 'N' THEN MISTAKE;
END;{OF IF NOT EQUAL TO 'EXIT'}
IF NAME <> 'EXIT ' THEN
BEGIN
WRITE(FIN:COUNTER,INFORMATION);
COUNTER:=COUNTER+1;
END; {OF IF NAME NOT EQUAL TO 'EXIT'}
END; {OF WITH}
END; {OF PROCEDURE}
{************************* MENU ******************************}
PROCEDURE MENU;
VAR
ANSWER:INTEGER;
BEGIN
CLEAR_SCREEN;
CHANGE_RECORD:=FALSE;
DELETE_RECORD:=FALSE;
FIND_RECORD:=FALSE;
ADD_TO_FILE:=FALSE;
LISTING:=FALSE;
MOVE_CURSOR(12,2);
WRITELN(' SELECT ONE PROCEDURE, AND ENTER CORRESPONDING NUMBER');
WRITELN;
WRITELN('1- CREATE A NEW, OR ADD TO AN EXISTING, NAME & ADDRESS FILE');
WRITELN('2- CHANGE OR CORRECT A RECORD IN AN EXISTING NAME & ADDRESS FILE');
WRITELN('3- DELETE A RECORD FROM AN EXISTING NAME & ADDRESS FILE');
WRITELN('4- DETERMINE IF A PARTICULAR NAME ALREADY EXISTS IN THE FILE');
WRITELN('5- LIST THE NAME & ADDRESS FILE ON EITHER THE CRT OR PRINTER');
WRITELN;
WRITELN;
REPEAT
WRITE('YOUR SELECTION, PLEASE: ');
READ(ANSWER);
UNTIL (ANSWER < 6) AND (ANSWER > 0);
CASE ANSWER OF
1: ADD_TO_FILE:= TRUE;
2: CHANGE_RECORD:=TRUE;
3: DELETE_RECORD:=TRUE;
4: FIND_RECORD:=TRUE;
5: LISTING:=TRUE;
END; {OF CASE}
CLEAR_SCREEN;
END; {OF PROCEDURE MENU}
{******************* ADD TO A NEW OR EXISTING FILE **************}
PROCEDURE ADD(FILENAM:$STRING14);
BEGIN
WITH INFORMATION DO
BEGIN
REPEAT
ENTER_INFORMATION;
UNTIL NAME = 'EXIT ';
CONTINUE:=FALSE;
CALC_ACCT_NO(COUNTER - 1);
CREATE_FIRST_RECORD(ACCT_NUMBER);
END; {OF WITH INFORMATION}
END; {OF PROCEDURE}
{******************** FIND A NAME IN THE FILE *******************}
PROCEDURE FIND(FILENAM:$STRING14; FLAG:INTEGER);
VAR
FINISHED:BOOLEAN;
I,LINE_COUNTER:INTEGER;
LOCALIZERS:ALPHABET;
LINE_FLAG:BOOLEAN;
FIRST_LETTER:INTEGER;
BEGIN
REPEAT
FINISHED:=TRUE;
REC_NUMBER:=1;
FOUND:=FALSE;
END_OF_FILE:=COUNTER -1; {COUNTER WAS SET = NUMBER_OF_RECORDS + 1
IN THE ENTER_FILE_NAME PROCEDURE}
CLEAR_SCREEN;
MOVE_CURSOR(2,2);
IF FLAG = 1 THEN
WRITELN(' PROCEDURE TO DETERMINE IF A NAME IS PRESENT IN FILE ',
FILENAM)
ELSE IF FLAG = 2 THEN
WRITELN(' PROCEDURE TO FIND AND CHANGE A RECORD')
ELSE IF FLAG = 3 THEN
WRITELN(' PROCEDURE TO FIND AND DELETE A RECORD');
PROMPT(1,4,30,'ENTER THE NAME YOU WISH TO LOCATE',FALSE);
DES_NAM:=INPUT_DATA(35,4,30,TRUE,0,0);
FOR I:= 1 TO 30 DO DESIRED_NAME[I]:=DES_NAM[I];
CLEAR_SCREEN;
PROMPT(2,12,0,'PROGRAM NOW SEARCHING FILE. ONE MOMENT PLEASE.',FALSE);
RESET(FILENAM,FIN);
I:=1;
WHILE FILENAM[I] <> '.' DO
BEGIN
ALPFILE[I]:=FILENAM[I];
I:=I+1;
END;
ALPFILE[I]:='.';
ALPFILE[I+1]:='A';
ALPFILE[I+2]:='L';
ALPFILE[I+3]:='P';
IF (I+4) < 14 THEN
BEGIN
I:=I+4;
FOR N:= I TO 14 DO
ALPFILE[N]:=' ';
END;
RESET(ALPFILE,FALP);
WITH LOCALIZERS DO
BEGIN
FIRST_LETTER:=ORD(DESIRED_NAME[1]) - 64;
READ(FALP:FIRST_LETTER,LOCALIZERS);
WITH INFORMATION DO
BEGIN
I:=START;
REPEAT
READ(FIN:I,INFORMATION);
IF DESIRED_NAME = NAME THEN
BEGIN
FOUND:=TRUE;
REC_NUMBER:=I;
ERASE_LINES(12,1);
PROMPT(1,1,0,'INFORMATION AS FOUND IN FILE: ',FALSE);
PROMPT(1,3,0,'NAME: ',FALSE);
PROMPT(1,5,0,'#: ',FALSE);
PROMPT(10,5,0,'STREET: ',FALSE);
PROMPT(1,7,0,'CITY: ',FALSE);
PROMPT(28,7,0,'STATE: ',FALSE);
PROMPT(48,7,0,'ZIP: ',FALSE);
PROMPT(1,9,0,'ATTENTION: ',FALSE);
MOVE_CURSOR(6,3);
WRITE(NAME);
MOVE_CURSOR(4,5);
WRITE(STREET_NUMBER);
MOVE_CURSOR(19,5);
WRITE(STREET);
MOVE_CURSOR(7,7);
WRITE(CITY);
MOVE_CURSOR(35,7);
WRITE(STATE);
MOVE_CURSOR(54,7);
WRITE(ZIP);
MOVE_CURSOR(12,9);
WRITE(ATTENTION);
END;
I:=I+1;
UNTIL (I > FINISH) OR (FOUND = TRUE);
IF FOUND = FALSE THEN
BEGIN
ERASE_LINES(12,1);
PROMPT(2,12,0,'NAME AS ENTERED NOT FOUND IN FILE.',FALSE);
REPEAT
MOVE_CURSOR(2,14);
WRITE('WOULD YOU LIKE A LIST OF NAMES BEGINNING WITH ',
DESIRED_NAME[1],' ? Y/N');
READ(ANSWER);
UNTIL (ANSWER = 'Y') OR (ANSWER = 'N');
IF ANSWER = 'Y' THEN
BEGIN
CLEAR_SCREEN;
LINE_COUNTER:=1;
FOR I:=START TO FINISH DO
BEGIN
READ(FIN:I,INFORMATION);
IF LINE_COUNTER < 15 THEN
BEGIN
MOVE_CURSOR(2,LINE_COUNTER);
WRITE(NAME);
END;
IF (LINE_COUNTER >=15) AND (LINE_COUNTER < 30) THEN
BEGIN
MOVE_CURSOR(45,LINE_COUNTER-14);
WRITE(NAME);
END;
IF LINE_COUNTER >= 30 THEN
BEGIN
PROMPT(2,23,0,'ENTER A CARRIAGE RETURN TO CONTINUE ',FALSE);
READ(ANSWER);
CLEAR_SCREEN;
LINE_COUNTER:=0;
END;
LINE_COUNTER:=LINE_COUNTER + 1;
END; {FOR I = START TO FINISH OF LISTING}
END; {OF IF ANSWER = Y}
ERASE_LINES(22,2);
PROMPT(2,23,0,'ENTER A CARRIAGE RETURN TO CONTINUE',FALSE);
READ(ANSWER);
CLEAR_SCREEN;
END; {OF FOUND = FALSE}
END; {OF WITH INFORMATION}
END; {OF LOCALIZERS}
IF FLAG = 1 THEN
BEGIN
ERASE_LINES(22,1);
REPEAT
MOVE_CURSOR(1,22);
WRITE('DO YOU WISH TO FIND ANOTHER RECORD IN FILE ',FILENAM,' Y/N?');
READ(ANSWER);
UNTIL (ANSWER = 'Y') OR (ANSWER = 'N');
IF ANSWER = 'Y' THEN FINISHED:=FALSE ELSE FINISHED:=TRUE;
END; {OF IF FLAG = 1}
UNTIL FINISHED = TRUE;
END; {OF PROCEDURE}
{******************** DELETE A RECORD **************************}
PROCEDURE DELETE(FILENAM:$STRING14);
VAR
FINISH:BOOLEAN;
BEGIN
REPEAT
WITH INFORMATION DO
BEGIN
FIND(FILENAM,3);
IF FOUND = TRUE THEN
BEGIN
RESET(FILENAM,FIN);
REPEAT
MOVE_CURSOR(1,22);
WRITE('IS IT OK TO DELETE THIS RECORD? Y/N');
READ(ANSWER);
UNTIL (ANSWER = 'Y') OR (ANSWER = 'N');
IF ANSWER = 'Y' THEN
BEGIN
ERASE_LINES(22,1);
MOVE_CURSOR(1,22);
WRITE('RECORD HAS BEEN DELETED.');
NAME:='ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ';
STREET_NUMBER:=' ';
STREET:=' ';
CITY:=' ';
STATE:=' ';
ZIP:=' ';
ATTENTION:=' ';
ACCT_NUMBER:=' ';
WRITE(FIN:REC_NUMBER,INFORMATION);
END; {OF ANSWER = Y}
END; {OF FOUND = TRUE}
IF FOUND = FALSE THEN
WRITELN('NO DELETION OCCURRED.');
END; {OF WITH INFORMATION}
ERASE_LINES(22,1);
REPEAT
MOVE_CURSOR(1,22);
WRITE('DO YOU WISH TO DELETE ANOTHER RECORD FROM FILE ',FILENAM,' Y/N');
READ(ANSWER)
UNTIL (ANSWER = 'Y') OR (ANSWER = 'N');
IF ANSWER = 'Y' THEN FINISH:= FALSE ELSE FINISH:=TRUE;
UNTIL FINISH = TRUE;
END; {OF PROCEDURE}
{****************** PROCEDURE TO CHANGE A RECORD IN FILE ***********}
PROCEDURE CHANGE(FILENAM:$STRING14);
VAR
FINISH:BOOLEAN;
BEGIN
REPEAT
WITH INFORMATION DO
BEGIN
FIND(FILENAM,2);
IF FOUND = TRUE THEN
BEGIN
RESET(FILENAM,FIN);
MISTAKE;
WRITE(FIN:REC_NUMBER,INFORMATION);
MOVE_CURSOR(1,23);
WRITELN('RECORD HAS BEEN MODIFIED AS DESIRED');
END; {OF WITH INFORMATION}
END; {OF IF FOUND = TRUE}
REPEAT
ERASE_LINES(22,1);
MOVE_CURSOR(1,22);
WRITE('DO YOU WISH TO CHANGE ANOTHER RECORD IN FILE ',FILENAM,' Y/N?');
READ(ANSWER);
UNTIL (ANSWER = 'Y') OR (ANSWER = 'N');
IF ANSWER = 'Y' THEN FINISH:=FALSE ELSE FINISH:=TRUE;
UNTIL FINISH = TRUE;
END; {OF PROCEDURE}
{*************** OFFER A CHANCE TO GO BACK TO MENU *************}
PROCEDURE AGAIN;
BEGIN
CLEAR_SCREEN;
REPEAT
PROMPT(2,10,0,'WOULD YOU LIKE TO CHOOSE FROM THE MENU, AGAIN? Y/N ',FALSE);
PROMPT(2,12,0,'ENTERING AN N WILL TERMINATE THE PROGRAM.',FALSE);
MOVE_CURSOR(54,10);
READ(ANSWER);
UNTIL (ANSWER = 'Y') OR (ANSWER = 'N');
IF ANSWER = 'Y' THEN FINISH:= FALSE ELSE FINISH:=TRUE;
END; {OF PROCEDURE}
{**************** MAIN PROGRAM BEGINS HERE ******************}
BEGIN
FINISH:=FALSE;
REPEAT
MENU;
CONTINUE:=TRUE;
ENTER_FILE_NAME;
IF CHANGE_RECORD = TRUE THEN CHANGE(FILENAM);
IF DELETE_RECORD = TRUE THEN DELETE(FILENAM);
IF FIND_RECORD = TRUE THEN FIND(FILENAM,1);
IF ADD_TO_FILE = TRUE THEN ADD(FILENAM);
IF LISTING = TRUE THEN OFFER_LISTING(FILENAM);
IF (ADD_TO_FILE = TRUE) OR (DELETE_RECORD = TRUE) THEN
BEGIN
CLEAR_SCREEN;
PROMPT(2,10,0,'WHEN THE CP/M PROMPT A> APPEARS, TYPE:',FALSE);
PROMPT(16,12,0,'ALPHABET',FALSE);
PROMPT(2,14,0,'THIS WILL RUN THE PROGRAM TO ALPHABETIZE THE FILE',FALSE);
PROMPT(2,15,0,'AND ESTABLISH THE FILE OF POINTERS. THANK YOU.',FALSE);
FINISH:= TRUE;
END;
IF (ADD_TO_FILE = FALSE) AND (DELETE_RECORD = FALSE) THEN AGAIN;
UNTIL FINISH = TRUE;
END.