Help! Trying to Complete School Assignment Part 1

I can't figure out this problem!

Using pointers and linked lists, trying to make changes to the customer information in the procedures Edit_Customer, SubMenu_Customer and SubMenu Dependents - but I can't get the changes to save! I have to send this in multiple messages because of the # of characters..

Anyone?

PROGRAM tstmenus;

{$Apptype Console}

USES
Sysutils;

CONST
Answer_Set = ['Y','y','N','n'];
Min = 1;
Max = 100;
Space = ' ';

TYPE
Customer_PTR = ^RecPTR; {Pointer to RecPTR, which is a record containing variables
or elements to the Customer Record, and a pointer side called next}

Address = Record
Street : String[25];
City : String[20];
State : String[2];
Zip : String[5];
END;
Dependent = Record
F_Name : String[15];
MI : Char;
Sex : Char;
Age : Integer;
END;
DependList = Array[Min..Max] of Dependent;

Customer = Record
L_Name : String[15];
F_Name : String[10];
MI : Char;
Sex : Char;
Age : Integer;
Num : Integer;
Home : Address;
Dependents : DependList;
END;
RecPTR = Record {This is the data that will be stored in dynamic memory}
Customer_Data : Customer; {This information is the data side of a link}
Next : Customer_PTR; {This information is the pointer side of a link}
END;
Customer_File = File of Customer;
{************************Load Data into Memory*********************************}
PROCEDURE Get_Data(VAR Source: Customer_File; VAR First: Customer_PTR);

VAR
Second,Last: Customer_PTR;

BEGIN
RESET(Source);
First := Nil;
Last := Nil;
WHILE NOT EoF(Source) DO
BEGIN
NEW(Second);
IF First = Nil THEN
First := Second;
READ(Source,Second^.Customer_Data);
Second^.Next := Nil;
IF Last <> Nil THEN
Last^.Next := Second;
Last := Second;
END;
CLOSE(Source);
END;
{*********************Enter New Customer Information***************************}
PROCEDURE New_Customer(VAR Cust_Rec: Customer);

VAR
Index: Integer;
Temp : String;
Code : Integer;

BEGIN
WITH Cust_Rec DO
BEGIN
Write('ENTER THE LAST NAME OF THE CUSTOMER: ');
Readln(L_Name);
Write('ENTER THE FIRST NAME OF THE CUSTOMER: ');
Readln(F_Name);
Write('ENTER THE MIDDLE INITIAL OF THE CUSTOMER: ');
Readln(MI);
Write('SEX[M/F]: ');
Readln(Sex);
IF(Sex <> 'M') and (Sex <> 'm') and (Sex <> 'F') and (Sex <> 'f') THEN
REPEAT
Write('YOU DID NOT ENTER A CORRECT VALUE.');
Write('PLEASE ENTER M or F: ');
Readln(Sex);
UNTIL (Sex = 'M') or (Sex = 'm') or (Sex = 'F') or (Sex = 'f');
REPEAT
Write('AGE: ');
Readln(Temp);
VAL(Temp,Age,Code);
IF Code <> 0 THEN
BEGIN
Writeln;
Writeln('YOU DID NOT ENTER A CORRECT VALUE.');
Writeln('PLEASE ENTER YOUR AGE IN NUMERIC VALUE (IE 35)');
Writeln('PRESS ENTER TO CONTINUE');
Readln;
END;
UNTIL Code = 0;
REPEAT
Write('NUMBER OF DEPENDENTS: ');
Readln(Temp);
VAL(Temp,Num,Code);
IF Code <> 0 THEN
BEGIN
Writeln;
Writeln('YOU DID NOT ENTER A CORRECT VALUE.');
Writeln('PLEASE ENTER THE NUMBER OF DEPENDENTS USING A NUMERIC VALUE (IE 3)');
Writeln('PRESS ENTER TO CONTINUE');
Readln;
END;
UNTIL Code = 0;
WITH Home DO
BEGIN
Write('ENTER THE STREET ADDRESS: ');
Readln(Street);
Write('CITY: ');
Readln(City);
Write('STATE (2-DIGIT ABBREVIATION): ');
Readln(State);
Write('ZIP CODE: ');
Readln(Zip);
Writeln;
END;
IF Num > 0 THEN
FOR Index := 1 TO Num DO
WITH Dependents[Index] DO
BEGIN
Write('ENTER THE DEPENDENT NAME: ');
Readln(F_NAME);
Write('ENTER THE MIDDLE INITIAL: ');
Readln(MI);
Write('SEX[M/F]: ');
Readln(Sex);
Write('AGE: ');
Readln(Age);
END;
END;
END;
{*********************Insert Customer Record Into File*************************}
PROCEDURE Add_Customer(VAR First: Customer_PTR);

VAR
P, Prev, I : Customer_PTR;
Found : Boolean;
Cust_Rec: Customer;
Ans: Char;

BEGIN
REPEAT
New_Customer(Cust_Rec);
IF (First = NIL) THEN
BEGIN
NEW(First);
First^.Customer_Data := Cust_Rec;
First^.Next := NIL;
END
ELSE
BEGIN
Prev := NIL;
P := First;
Found := False;
WHILE (P <> NIL) AND NOT Found DO
BEGIN
IF Cust_Rec.L_Name > P^.Customer_Data.L_Name THEN
BEGIN
Prev := P;
P := P^.Next
END
ELSE
Found := True;
END;
IF Prev = NIL THEN
BEGIN
NEW(I);
I^.Next := First;
I^.Customer_Data := Cust_Rec;
First := I
END
ELSE
BEGIN
NEW(I);
I^.Next := Prev^.Next;
I^.Customer_Data := Cust_Rec;
Prev^.Next := I
END;
END;
REPEAT
Writeln;
Writeln('DO YOU WANT TO ENTER ANOTHER CUSTOMER? Y/N');
Readln(Ans);
UNTIL Ans IN Answer_Set;
UNTIL (ANS = 'N') OR (ANS = 'n');
END;

{************************Prompt to Save Binary File****************************}
PROCEDURE Save_File(VAR Source: Customer_File);

VAR
Filename: String;

BEGIN
Writeln;
Writeln('ENTER THE PATH AND NAME OF FILE TO BE SAVED: ');
Readln(Filename);
Assign(Source, Filename);
END;
{*************************Store Data in Binary File****************************}
PROCEDURE Store_File(VAR Source: Customer_File; First: Customer_PTR);

VAR
CPointer: Customer_PTR;

BEGIN
Rewrite(Source);
CPointer := First;
WHILE CPointer <> Nil DO
BEGIN
Write(Source, CPointer^.Customer_Data);
CPointer := CPointer^.Next;
END;
Writeln('THE DATA HAS BEEN SAVED.');
Writeln('PRESS THE ENTER KEY TO CONTINUE.');
Readln;
END;

Comments

  • {**********************Display Found Customer Information**********************}
    PROCEDURE Display_Customer(P: Customer_PTR);

    VAR
    Index, Len : integer;
    Temp: String;

    BEGIN
    WITH P^.Customer_Data DO
    BEGIN
    Writeln;
    Temp := Trimright(F_Name)+ ' ' + Trimleft(MI)+ '. ' + Trimleft(L_Name);
    Len := Length(Temp);
    Writeln(Temp,Space:(30 - Len),'Sex: ', Sex, Space:3,
    'Age: ',Age,Space:3,'Dependents: ', Num);
    WITH Home DO
    BEGIN
    Writeln(Street);
    Temp := Trimright(City) + ', ' + Trimleft(State);
    Len := Length(Temp);
    Writeln(Temp, Space:(12-Len), Zip);
    Writeln;
    END;
    Writeln ('Dependents: ');
    FOR Index := 1 to Num DO
    WITH Dependents[index] DO
    BEGIN
    Temp := Trimright(F_Name) + ' ' + Trimleft(MI) + '.';
    Len := Length(Temp);
    Writeln(Temp, Space:(30-Len), 'Sex: ',sex,space:3,'Age: ',Age);
    END;
    Writeln;
    Writeln;
    Writeln('Press the Enter key to continue');
    Readln;
    END;
    END;
    {*****************************Search for Customer******************************}
    PROCEDURE Find_Customer(First: Customer_PTR; VAR P,Prev: Customer_PTR; VAR Found: Boolean);

    VAR
    Target : String;

    BEGIN
    Writeln;
    Write('ENTER THE LAST NAME OF THE CUSTOMER: ');
    Readln(Target);
    P := First;
    Prev := Nil;
    Found := False;
    WHILE (P <> Nil) AND NOT Found DO
    BEGIN
    IF Trim(UpperCase(P^.Customer_Data.L_Name)) = (Trim(UpperCase(Target))) THEN
    Found := True
    ELSE
    BEGIN
    Prev := P;
    P := P^.Next;
    END;
    END;
    IF (P = NIL) THEN
    BEGIN
    WRITELN;
    WRITELN('THERE WAS NO CUSTOMER RECORD MATCHING THE NAME ENTERED!');
    WRITELN('CHECK YOUR SPELLING AND PRESS THE ENTER KEY TO CONTINUE.');
    READLN;
    END;
    END;
    {*************************Delete Customer Information**************************}
    PROCEDURE Delete_Customer(VAR First:Customer_PTR; P,Prev:Customer_PTR);

    BEGIN
    IF Prev = NIL THEN
    BEGIN
    First := First^.Next;
    DISPOSE(P);
    END
    ELSE
    BEGIN
    Prev^.Next := P^.Next;
    DISPOSE(P);
    END;
    END;
    {*************************Get File To Be Processed*****************************}
    PROCEDURE Get_File(VAR Source:Customer_File);

    VAR
    Filename: String;
    Flag: Integer;
    Ans: Char;

    BEGIN
    REPEAT
    Ans :=' ';
    Writeln;
    Writeln('ENTER THE PATH AND FILENAME OF THE BINARY FILE TO BE OPENED: ');
    Readln(Filename);
    Assign(Source, Filename);
    {$I-}
    Reset(Source);
    {$I+}
    Flag := Ioresult;
    IF Flag <> 0 THEN
    BEGIN
    Writeln('THE FILE YOU ENTERED DOES NOT EXIST!!');
    REPEAT
    Writeln('DO YOU WANT TO ENTER ANOTHER FILE? [Y or N]');
    Readln(Ans);
    UNTIL Ans in Answer_Set;
    END;
    UNTIL (Flag = 0) OR (Ans = 'N') OR (Ans = 'n');
    END;
    {***********************Display List of Customers******************************}
    PROCEDURE Display_List(VAR First: Customer_PTR);

    VAR
    CPointer: Customer_PTR;
    Index, Len : integer;
    Temp: String;

    BEGIN
    CPointer := First;
    WHILE CPointer <> Nil DO
    BEGIN
    WITH CPointer^.Customer_Data DO
    BEGIN
    Temp := Trimright(F_Name)+ ' ' + Trimleft(MI)+ '. ' + Trimleft(L_Name);
    Len := Length(Temp);
    Writeln(Temp,Space:(30 - Len),'Sex: ', Sex, Space:3,
    'Age: ',Age,Space:3,'Dependents: ', Num);
    WITH Home DO
    BEGIN
    Writeln(Street);
    Temp := Trimright(City) + ', ' + Trimleft(State);
    Len := Length(Temp);
    Writeln(Temp, Space:(12-Len), Zip);
    Writeln;
    END;
    Writeln ('Dependents: ');
    FOR Index := 1 to Num DO
    WITH Dependents[Index] DO
    BEGIN
    Temp := Trimright(F_Name) + ' ' + Trimleft(MI) + '.';
    Len := Length(Temp);
    Writeln(Temp, Space:(30-Len), 'Sex: ',sex,space:3,'Age: ',Age);
    END;
    Writeln;
    Writeln;
    Writeln('Press the Enter key to continue');
    Readln;
    END;
    CPointer := CPointer^.Next;
    END;
    END;
  • {*********************SubMenu For Customer Changes*****************************}
    PROCEDURE SubMenu_Customer(VAR Source: Customer_File; First: Customer_PTR);// VAR Cust_Rec: Customer);

    VAR
    CPointer: Customer_PTR;
    Selection, Code : Integer;
    Temp,TempName, TempStreet,TempCity,TempState,TempZip : String;
    TempMI: Char;
    TempSex: Char;
    TempAge: Integer;

    BEGIN
    // WITH Cust_Rec DO
    REPEAT
    Writeln('SELECT A FIELD TO EDIT OR EXIT TO GO BACK TO THE PREVIOUS MENU.');
    Writeln;
    Writeln(' [1] FIRST NAME');
    Writeln(' [2] MIDDLE INITIAL');
    Writeln(' [3] SEX');
    Writeln(' [4] AGE');
    Writeln(' [5] STREET ADDRESS');
    Writeln(' [6] CITY');
    Writeln(' [7] STATE');
    Writeln(' [8] ZIP CODE');
    Writeln(' [9] EXIT TO PREVIOUS MENU');
    REPEAT
    Write('ENTER YOUR SELECTION FROM THE LIST ABOVE: ');
    Readln(Temp);
    Writeln;
    VAL(Temp,Selection,Code);
    IF Code <> 0 THEN
    BEGIN
    Writeln;
    Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    Writeln('PLEASE TRY AGAIN.');
    Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    Readln;
    END;
    IF (Selection < 0) OR (Selection > 9) THEN
    BEGIN
    Writeln;
    Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    Writeln('PLEASE TRY AGAIN.');
    Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    Readln;
    END;
    UNTIL (Code = 0) AND (Selection > 0) AND (Selection < 10);
    CASE (Selection) OF
    1 : BEGIN
    Writeln('ENTER NEW FIRST NAME');
    Readln(TempName);
    CPointer^.Customer_Data.F_Name := TempName;
    Store_File(Source, First);
    END;
    2 : BEGIN
    Writeln('ENTER NEW MI');
    Readln(TempMI);
    CPointer^.Customer_Data.MI := TempMI;
    END;
    3 : BEGIN
    Writeln('ENTER NEW SEX');
    Readln(TempSex);
    CPointer^.Customer_Data.Sex := TempSex;
    END;
    4 : BEGIN
    Writeln('ENTER NEW AGE');
    Readln(TempAge);
    CPointer^.Customer_Data.Age := TempAge;
    END;
    5 : BEGIN
    Writeln('ENTER NEW STREET ADDRESS');
    Readln(TempStreet);
    CPointer^.Customer_Data.Home.Street := TempStreet;
    END;
    6 : BEGIN
    Writeln('ENTER NEW CITY');
    Readln(TempCity);
    CPointer^.Customer_Data.Home.City := TempCity;
    END;
    7 : BEGIN
    Writeln('ENTER NEW STATE');
    Readln(TempState);
    CPointer^.Customer_Data.Home.State := TempState;
    END;
    8 : BEGIN
    Writeln('ENTER ZIP CODE');
    Readln(TempZip);
    CPointer^.Customer_Data.Home.Zip := TempZip;
    END;
    END;
    UNTIL (SELECTION = 9);
    END;
    {*********************SubMenu For Dependent Changes****************************}
    PROCEDURE SubMenu_Dependents(VAR First:Customer_PTR);

    VAR
    CPointer: Customer_PTR;
    Selection2, Code : Integer;
    Temp,TempName : String;
    TempMI: Char;
    TempSex: Char;
    TempAge: Integer;

    BEGIN
    REPEAT
    Writeln('SELECT A FIELD TO EDIT OR EXIT TO GO BACK TO THE PREVIOUS MENU.');
    Writeln;
    Writeln(' [1] FIRST NAME');
    Writeln(' [2] MIDDLE INITIAL');
    Writeln(' [3] SEX');
    Writeln(' [4] AGE');
    Writeln(' [5] EXIT TO PREVIOUS MENU');
    REPEAT
    Write('ENTER YOUR SELECTION FROM THE LIST ABOVE: ');
    Readln(Temp);
    Writeln;
    VAL(Temp,Selection2,Code);
    IF Code <> 0 THEN
    BEGIN
    Writeln;
    Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    Writeln('PLEASE TRY AGAIN.');
    Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    Readln;
    END;
    IF (Selection2 < 0) OR (Selection2 > 5) THEN
    BEGIN
    Writeln;
    Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    Writeln('PLEASE TRY AGAIN.');
    Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    Readln;
    END;
    UNTIL (Code = 0) AND (Selection2 > 0) AND (Selection2 < 6);
    CASE (Selection2) OF
    1 : BEGIN
    WRITELN('ENTER NEW FIRST NAME');
    READLN(TempName);
    CPointer^.Customer_Data.F_Name := TempName;
    END;
    2 : BEGIN
    Writeln('ENTER NEW MI');
    Readln(TempMI);
    CPointer^.Customer_Data.MI := TEMPMI;
    END;
    3 : BEGIN
    Writeln('ENTER NEW SEX');
    Readln(TempSex);
    CPointer^.Customer_Data.Sex := TempSex;
    END;
    4 : BEGIN
    Writeln('ENTER NEW AGE');
    Readln(TempAge);
    CPointer^.Customer_Data.Age := TempAge;
    END;
    END;
    UNTIL (Selection2 = 5);
    END;
    {*********************Change Customer Information******************************}
    PROCEDURE Edit_Customer(VAR First:Customer_PTR);

    VAR
    Source: Customer_File;
    Ans: Char;
    Selection, Code : Integer;
    Temp: String;

    BEGIN
    REPEAT
    First := Nil;
    REPEAT
    Writeln;
    Writeln('ENTER YOUR SELECTION FROM THE MENU');
    Writeln;
    Writeln(' [1] EDIT CUSTOMER DATA');
    Writeln(' [2] EDIT DEPENDENT DATA');
    Writeln(' [3] EXIT TO MAIN MENU');
    Writeln;
    Writeln('ENTER SELECTION FROM THE LIST ABOVE');
    Readln(Temp);
    VAL(Temp,Selection,Code);
    IF Code <> 0 THEN
    BEGIN
    Writeln;
    Writeln('YOU ENTERED AN INVALID KEY!');
    Writeln('PLEASE TRY AGAIN.');
    Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    Readln;
    END;
    IF (Selection < 0) OR (Selection > 3) THEN
    BEGIN
    Writeln;
    Writeln('YOU ENTERED AN INVALID MENU SELECTION!');
    Writeln('PLEASE TRY AGAIN.');
    Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    Readln;
    END;
    UNTIL (Code = 0) AND (Selection > 0) AND (Selection < 4);
    CASE (Selection) OF
    1 : BEGIN {SubMenu to Change Customer Information}
    REPEAT
    SubMenu_Customer(Source,First);
    REPEAT
    Writeln('DO YOU WANT TO EDIT ANOTHER FIELD? Y/N');
    Readln(ANS);
    UNTIL Ans IN Answer_Set;
    UNTIL (Ans = 'N') OR (Ans = 'n');
    // Store_File(Source, First);
    END;
    2 : BEGIN {SubMenu to Change Dependent Information}
    REPEAT
    SubMenu_Dependents(First);
    REPEAT
    Writeln('DO YOU WANT TO EDIT ANOTHER FIELD? Y/N');
    Readln(ANS);
    UNTIL Ans IN Answer_Set;
    UNTIL (Ans = 'N') OR (Ans = 'n');
    Store_File(Source, First);
    END;
    END;
    UNTIL (Selection = 3);
    END;
    {*****************************Selection Menu***********************************}
    PROCEDURE Menu;

    VAR
    Source: Customer_File;
    First, P, Prev: Customer_PTR;
    Choice, Code: Integer;
    Temp: String;
    Ans: Char;
    Found: Boolean;

    BEGIN
    REPEAT
    Writeln;
    Writeln(' [1] LOAD BINARY FILE');
    Writeln(' [2] CREATE A NEW CUSTOMER LIST');
    Writeln(' [3] ADD A NEW CUSTOMER');
    Writeln(' [4] CHANGE/UPDATE CUSTOMER INFORMATION');
    Writeln(' [5] SEARCH FOR A CUSTOMER');
    Writeln(' [6] DELETE CUSTOMER INFORMATION');
    Writeln(' [7] DISPLAY CUSTOMER LIST');
    Writeln(' [8] EXIT');
    Writeln;
    REPEAT
    Write('ENTER YOUR SELECTION FROM THE LIST ABOVE: ');
    Readln(Temp);
    Writeln;
    VAL(TEMP,CHOICE,CODE);
    IF CODE <> 0 THEN
    BEGIN
    Writeln;
    Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    Writeln('PLEASE TRY AGAIN.');
    Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    Readln;
    END;
    IF (Choice < 0) OR (Choice > 8) THEN
    BEGIN
    Writeln;
    Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    Writeln('PLEASE TRY AGAIN.');
    Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    Readln;
    END;
    UNTIL (Code = 0) AND (Choice > 0) AND (Choice < 9);
    CASE (Choice) OF
    1 : BEGIN {Load binary file}
    Get_File(Source);
    Get_Data(Source, First);
    END;
    2 : BEGIN {New Customer List}
    First := Nil;
    Add_Customer(First);
    Save_File(Source);
    Store_File(Source, First);
    END;
    3 : BEGIN {Add Customer to Current List}
    IF First <> Nil THEN
    BEGIN
    Add_Customer(First);
    Store_File(Source, First);
    END
    ELSE
    BEGIN
    Writeln('YOU DO NOT HAVE AN ACTIVE LIST TO EDIT.');
    Writeln('YOU MUST OPEN OR CREATE A NEW LIST.');
    Writeln('PRESS ENTER TO CONTINUE.');
    Readln;
    END;
    END;
    4 : BEGIN {Change Customer Information}
    IF First <> Nil THEN
    BEGIN
    REPEAT
    Find_Customer(First,P,Prev, Found);
    IF Found THEN
    Display_Customer(P);
    Edit_Customer(First);
    //Store_File(Source,First);
    REPEAT
    Writeln('DO YOU WANT TO CHANGE INFORMATION FOR ANOTHER CUSTOMER? [Y or N]');
    Readln (Ans);
    UNTIL Ans IN Answer_Set;
    UNTIL (Ans = 'N') OR (Ans = 'n');
    END
    ELSE
    BEGIN
    Writeln('YOU DO NOT HAVE AN ACTIVE LIST TO EDIT.');
    Writeln('YOU MUST OPEN OR CREATE A NEW LIST.');
    Writeln('PRESS ENTER TO CONTINUE.');
    Readln;
    END;
    END;
    5 : BEGIN {Search for Customer}
    IF First <> Nil THEN
    BEGIN
    REPEAT
    Find_Customer(First,P,Prev, Found);
    IF Found THEN
    Display_Customer(P);
    REPEAT
    Writeln;
    Writeln('DO YOU WANT TO FIND ANOTHER CUSTOMER [Y or N]?');
    Readln(Ans);
    UNTIL Ans in Answer_Set;
    UNTIL (Ans = 'N') OR (Ans = 'n');
    END
    ELSE
    BEGIN
    Writeln('YOU DO NOT HAVE AN ACTIVE LIST TO EDIT.');
    Writeln('YOU MUST OPEN OR CREATE A NEW LIST.');
    Writeln('PRESS ENTER TO CONTINUE.');
    Readln;
    END;
    END;
    6 : BEGIN {Delete Customer}
    IF First <> Nil THEN
    BEGIN
    REPEAT
    Find_Customer(First,P,Prev,Found);
    Delete_Customer(First,P,Prev);
    Store_File(Source,First);
    REPEAT
    Writeln;
    Writeln('DO YOU WANT TO DELETE ANOTHER CUSTOMER? [Y or N]');
    Readln(Ans);
    UNTIL Ans in Answer_Set;
    UNTIL (Ans = 'N') OR (Ans = 'n');
    END
    ELSE
    BEGIN
    Writeln('YOU DO NOT HAVE AN ACTIVE LIST TO EDIT.');
    Writeln('YOU MUST OPEN OR CREATE A NEW LIST.');
    Writeln('PRESS ENTER TO CONTINUE.');
    Readln;
    END;
    END;
    7 : BEGIN {Display Customer List}
    Display_List(First);
    END;
    END;
    UNTIL (Choice = 8);
    END;
    {*****************************MAIN PROGRAM*************************************}
    BEGIN
    MENU
    END.

  • : {*********************SubMenu For Customer Changes*****************************}
    : PROCEDURE SubMenu_Customer(VAR Source: Customer_File; First: Customer_PTR);// VAR Cust_Rec: Customer);
    :
    : VAR
    : CPointer: Customer_PTR;
    : Selection, Code : Integer;
    : Temp,TempName, TempStreet,TempCity,TempState,TempZip : String;
    : TempMI: Char;
    : TempSex: Char;
    : TempAge: Integer;
    :
    : BEGIN
    : // WITH Cust_Rec DO
    : REPEAT
    : Writeln('SELECT A FIELD TO EDIT OR EXIT TO GO BACK TO THE PREVIOUS MENU.');
    : Writeln;
    : Writeln(' [1] FIRST NAME');
    : Writeln(' [2] MIDDLE INITIAL');
    : Writeln(' [3] SEX');
    : Writeln(' [4] AGE');
    : Writeln(' [5] STREET ADDRESS');
    : Writeln(' [6] CITY');
    : Writeln(' [7] STATE');
    : Writeln(' [8] ZIP CODE');
    : Writeln(' [9] EXIT TO PREVIOUS MENU');
    : REPEAT
    : Write('ENTER YOUR SELECTION FROM THE LIST ABOVE: ');
    : Readln(Temp);
    : Writeln;
    : VAL(Temp,Selection,Code);
    : IF Code <> 0 THEN
    : BEGIN
    : Writeln;
    : Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    : Writeln('PLEASE TRY AGAIN.');
    : Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    : Readln;
    : END;
    : IF (Selection < 0) OR (Selection > 9) THEN
    : BEGIN
    : Writeln;
    : Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    : Writeln('PLEASE TRY AGAIN.');
    : Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    : Readln;
    : END;
    : UNTIL (Code = 0) AND (Selection > 0) AND (Selection < 10);
    : CASE (Selection) OF
    : 1 : BEGIN
    : Writeln('ENTER NEW FIRST NAME');
    : Readln(TempName);
    : CPointer^.Customer_Data.F_Name := TempName;
    : Store_File(Source, First);
    : END;
    : 2 : BEGIN
    : Writeln('ENTER NEW MI');
    : Readln(TempMI);
    : CPointer^.Customer_Data.MI := TempMI;
    : END;
    : 3 : BEGIN
    : Writeln('ENTER NEW SEX');
    : Readln(TempSex);
    : CPointer^.Customer_Data.Sex := TempSex;
    : END;
    : 4 : BEGIN
    : Writeln('ENTER NEW AGE');
    : Readln(TempAge);
    : CPointer^.Customer_Data.Age := TempAge;
    : END;
    : 5 : BEGIN
    : Writeln('ENTER NEW STREET ADDRESS');
    : Readln(TempStreet);
    : CPointer^.Customer_Data.Home.Street := TempStreet;
    : END;
    : 6 : BEGIN
    : Writeln('ENTER NEW CITY');
    : Readln(TempCity);
    : CPointer^.Customer_Data.Home.City := TempCity;
    : END;
    : 7 : BEGIN
    : Writeln('ENTER NEW STATE');
    : Readln(TempState);
    : CPointer^.Customer_Data.Home.State := TempState;
    : END;
    : 8 : BEGIN
    : Writeln('ENTER ZIP CODE');
    : Readln(TempZip);
    : CPointer^.Customer_Data.Home.Zip := TempZip;
    : END;
    : END;
    : UNTIL (SELECTION = 9);
    : END;
    : {*********************SubMenu For Dependent Changes****************************}
    : PROCEDURE SubMenu_Dependents(VAR First:Customer_PTR);
    :
    : VAR
    : CPointer: Customer_PTR;
    : Selection2, Code : Integer;
    : Temp,TempName : String;
    : TempMI: Char;
    : TempSex: Char;
    : TempAge: Integer;
    :
    : BEGIN
    : REPEAT
    : Writeln('SELECT A FIELD TO EDIT OR EXIT TO GO BACK TO THE PREVIOUS MENU.');
    : Writeln;
    : Writeln(' [1] FIRST NAME');
    : Writeln(' [2] MIDDLE INITIAL');
    : Writeln(' [3] SEX');
    : Writeln(' [4] AGE');
    : Writeln(' [5] EXIT TO PREVIOUS MENU');
    : REPEAT
    : Write('ENTER YOUR SELECTION FROM THE LIST ABOVE: ');
    : Readln(Temp);
    : Writeln;
    : VAL(Temp,Selection2,Code);
    : IF Code <> 0 THEN
    : BEGIN
    : Writeln;
    : Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    : Writeln('PLEASE TRY AGAIN.');
    : Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    : Readln;
    : END;
    : IF (Selection2 < 0) OR (Selection2 > 5) THEN
    : BEGIN
    : Writeln;
    : Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    : Writeln('PLEASE TRY AGAIN.');
    : Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    : Readln;
    : END;
    : UNTIL (Code = 0) AND (Selection2 > 0) AND (Selection2 < 6);
    : CASE (Selection2) OF
    : 1 : BEGIN
    : WRITELN('ENTER NEW FIRST NAME');
    : READLN(TempName);
    : CPointer^.Customer_Data.F_Name := TempName;
    : END;
    : 2 : BEGIN
    : Writeln('ENTER NEW MI');
    : Readln(TempMI);
    : CPointer^.Customer_Data.MI := TEMPMI;
    : END;
    : 3 : BEGIN
    : Writeln('ENTER NEW SEX');
    : Readln(TempSex);
    : CPointer^.Customer_Data.Sex := TempSex;
    : END;
    : 4 : BEGIN
    : Writeln('ENTER NEW AGE');
    : Readln(TempAge);
    : CPointer^.Customer_Data.Age := TempAge;
    : END;
    : END;
    : UNTIL (Selection2 = 5);
    : END;
    : {*********************Change Customer Information******************************}
    : PROCEDURE Edit_Customer(VAR First:Customer_PTR);
    :
    : VAR
    : Source: Customer_File;
    : Ans: Char;
    : Selection, Code : Integer;
    : Temp: String;
    :
    : BEGIN
    : REPEAT
    : First := Nil;
    : REPEAT
    : Writeln;
    : Writeln('ENTER YOUR SELECTION FROM THE MENU');
    : Writeln;
    : Writeln(' [1] EDIT CUSTOMER DATA');
    : Writeln(' [2] EDIT DEPENDENT DATA');
    : Writeln(' [3] EXIT TO MAIN MENU');
    : Writeln;
    : Writeln('ENTER SELECTION FROM THE LIST ABOVE');
    : Readln(Temp);
    : VAL(Temp,Selection,Code);
    : IF Code <> 0 THEN
    : BEGIN
    : Writeln;
    : Writeln('YOU ENTERED AN INVALID KEY!');
    : Writeln('PLEASE TRY AGAIN.');
    : Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    : Readln;
    : END;
    : IF (Selection < 0) OR (Selection > 3) THEN
    : BEGIN
    : Writeln;
    : Writeln('YOU ENTERED AN INVALID MENU SELECTION!');
    : Writeln('PLEASE TRY AGAIN.');
    : Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    : Readln;
    : END;
    : UNTIL (Code = 0) AND (Selection > 0) AND (Selection < 4);
    : CASE (Selection) OF
    : 1 : BEGIN {SubMenu to Change Customer Information}
    : REPEAT
    : SubMenu_Customer(Source,First);
    : REPEAT
    : Writeln('DO YOU WANT TO EDIT ANOTHER FIELD? Y/N');
    : Readln(ANS);
    : UNTIL Ans IN Answer_Set;
    : UNTIL (Ans = 'N') OR (Ans = 'n');
    : // Store_File(Source, First);
    : END;
    : 2 : BEGIN {SubMenu to Change Dependent Information}
    : REPEAT
    : SubMenu_Dependents(First);
    : REPEAT
    : Writeln('DO YOU WANT TO EDIT ANOTHER FIELD? Y/N');
    : Readln(ANS);
    : UNTIL Ans IN Answer_Set;
    : UNTIL (Ans = 'N') OR (Ans = 'n');
    : Store_File(Source, First);
    : END;
    : END;
    : UNTIL (Selection = 3);
    : END;
    : {*****************************Selection Menu***********************************}
    : PROCEDURE Menu;
    :
    : VAR
    : Source: Customer_File;
    : First, P, Prev: Customer_PTR;
    : Choice, Code: Integer;
    : Temp: String;
    : Ans: Char;
    : Found: Boolean;
    :
    : BEGIN
    : REPEAT
    : Writeln;
    : Writeln(' [1] LOAD BINARY FILE');
    : Writeln(' [2] CREATE A NEW CUSTOMER LIST');
    : Writeln(' [3] ADD A NEW CUSTOMER');
    : Writeln(' [4] CHANGE/UPDATE CUSTOMER INFORMATION');
    : Writeln(' [5] SEARCH FOR A CUSTOMER');
    : Writeln(' [6] DELETE CUSTOMER INFORMATION');
    : Writeln(' [7] DISPLAY CUSTOMER LIST');
    : Writeln(' [8] EXIT');
    : Writeln;
    : REPEAT
    : Write('ENTER YOUR SELECTION FROM THE LIST ABOVE: ');
    : Readln(Temp);
    : Writeln;
    : VAL(TEMP,CHOICE,CODE);
    : IF CODE <> 0 THEN
    : BEGIN
    : Writeln;
    : Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    : Writeln('PLEASE TRY AGAIN.');
    : Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    : Readln;
    : END;
    : IF (Choice < 0) OR (Choice > 8) THEN
    : BEGIN
    : Writeln;
    : Writeln('YOU ENTERED AN INVALID MENU SELECTION');
    : Writeln('PLEASE TRY AGAIN.');
    : Writeln('PRESS THE ENTER KEY TO CONTINUE.');
    : Readln;
    : END;
    : UNTIL (Code = 0) AND (Choice > 0) AND (Choice < 9);
    : CASE (Choice) OF
    : 1 : BEGIN {Load binary file}
    : Get_File(Source);
    : Get_Data(Source, First);
    : END;
    : 2 : BEGIN {New Customer List}
    : First := Nil;
    : Add_Customer(First);
    : Save_File(Source);
    : Store_File(Source, First);
    : END;
    : 3 : BEGIN {Add Customer to Current List}
    : IF First <> Nil THEN
    : BEGIN
    : Add_Customer(First);
    : Store_File(Source, First);
    : END
    : ELSE
    : BEGIN
    : Writeln('YOU DO NOT HAVE AN ACTIVE LIST TO EDIT.');
    : Writeln('YOU MUST OPEN OR CREATE A NEW LIST.');
    : Writeln('PRESS ENTER TO CONTINUE.');
    : Readln;
    : END;
    : END;
    : 4 : BEGIN {Change Customer Information}
    : IF First <> Nil THEN
    : BEGIN
    : REPEAT
    : Find_Customer(First,P,Prev, Found);
    : IF Found THEN
    : Display_Customer(P);
    : Edit_Customer(First);
    : //Store_File(Source,First);
    : REPEAT
    : Writeln('DO YOU WANT TO CHANGE INFORMATION FOR ANOTHER CUSTOMER? [Y or N]');
    : Readln (Ans);
    : UNTIL Ans IN Answer_Set;
    : UNTIL (Ans = 'N') OR (Ans = 'n');
    : END
    : ELSE
    : BEGIN
    : Writeln('YOU DO NOT HAVE AN ACTIVE LIST TO EDIT.');
    : Writeln('YOU MUST OPEN OR CREATE A NEW LIST.');
    : Writeln('PRESS ENTER TO CONTINUE.');
    : Readln;
    : END;
    : END;
    : 5 : BEGIN {Search for Customer}
    : IF First <> Nil THEN
    : BEGIN
    : REPEAT
    : Find_Customer(First,P,Prev, Found);
    : IF Found THEN
    : Display_Customer(P);
    : REPEAT
    : Writeln;
    : Writeln('DO YOU WANT TO FIND ANOTHER CUSTOMER [Y or N]?');
    : Readln(Ans);
    : UNTIL Ans in Answer_Set;
    : UNTIL (Ans = 'N') OR (Ans = 'n');
    : END
    : ELSE
    : BEGIN
    : Writeln('YOU DO NOT HAVE AN ACTIVE LIST TO EDIT.');
    : Writeln('YOU MUST OPEN OR CREATE A NEW LIST.');
    : Writeln('PRESS ENTER TO CONTINUE.');
    : Readln;
    : END;
    : END;
    : 6 : BEGIN {Delete Customer}
    : IF First <> Nil THEN
    : BEGIN
    : REPEAT
    : Find_Customer(First,P,Prev,Found);
    : Delete_Customer(First,P,Prev);
    : Store_File(Source,First);
    : REPEAT
    : Writeln;
    : Writeln('DO YOU WANT TO DELETE ANOTHER CUSTOMER? [Y or N]');
    : Readln(Ans);
    : UNTIL Ans in Answer_Set;
    : UNTIL (Ans = 'N') OR (Ans = 'n');
    : END
    : ELSE
    : BEGIN
    : Writeln('YOU DO NOT HAVE AN ACTIVE LIST TO EDIT.');
    : Writeln('YOU MUST OPEN OR CREATE A NEW LIST.');
    : Writeln('PRESS ENTER TO CONTINUE.');
    : Readln;
    : END;
    : END;
    : 7 : BEGIN {Display Customer List}
    : Display_List(First);
    : END;
    : END;
    : UNTIL (Choice = 8);
    : END;
    : {*****************************MAIN PROGRAM*************************************}
    : BEGIN
    : MENU
    : END.
    :
    :
    I don't think you can expect a meaningful reply to this one. I suggest that you read the following: http://www.catb.org/~esr/faqs/smart-questions.html. Most of us help people from the goodness of our hearts instead of pay. Reading through a whole program and then debugging it takes too much time for this. I would suggest that you first localize the problem and post that piece of code and give any error messages or weird variable values. This way it takes us less time to find the precise problem and offer a solution.
  • I don't think you can expect a meaningful reply to this one. I suggest that you read the following: http://www.catb.org/~esr/faqs/smart-questions.html. Most of us help people from the goodness of our hearts instead of pay. Reading through a whole program and then debugging it takes too much time for this. I would suggest that you first localize the problem and post that piece of code and give any error messages or weird variable values. This way it takes us less time to find the precise problem and offer a solution.


    Hi, I think that's a dead link you gave, I couldn't get to it.

    I'll follow your suggestion though. Thanks1


  • : I don't think you can expect a meaningful reply to this one. I suggest that you read the following: http://www.catb.org/~esr/faqs/smart-questions.html. Most of us help people from the goodness of our hearts instead of pay. Reading through a whole program and then debugging it takes too much time for this. I would suggest that you first localize the problem and post that piece of code and give any error messages or weird variable values. This way it takes us less time to find the precise problem and offer a solution.
    :
    :
    : Hi, I think that's a dead link you gave, I couldn't get to it.
    :
    : I'll follow your suggestion though. Thanks1
    :
    :
    :
    Remove the dot at the end and it works. It is also listed below the post enter-box as "How To Ask Questions The Smart Way". It is also helpful to read the Stylecodes.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories