program investors input output investor List updated Investor

  • Slides: 12
Download presentation
program investors (input, output, investor. List, updated. Investor. List); const MAXCLIENTS = 10; NAMELENGTH

program investors (input, output, investor. List, updated. Investor. List); const MAXCLIENTS = 10; NAMELENGTH = 30; EMAILLENGTH = 30; type Client = record first. Name : array [1. . NAMELENGTH] of char; last. Name : array [1. . NAMELENGTH] of char; income : real; email : array [1. . EMAILLENGTH] of char; end; (* Declaration of record client *) Client. List = array [1. . MAXCLIENTS] of Client; var investor. List : text; updated. Investor. List : text; James Tam

procedure read. Client. Information (var tamj. Client. List : Client. List ; var client.

procedure read. Client. Information (var tamj. Client. List : Client. List ; var client. Count : integer ); var i : integer; begin; i : = 1; writeln; reset(investor. List); writeln('Opening file "investor. List" for reading'); client. Count : = 0; (* No clients exist in list yet. *) while NOT EOF (investor. List) do begin with tamj. Client. List[i] do begin readln(investor. List, first. Name); readln(investor. List, last. Name); readln(investor. List, income); readln(investor. List, email); readln(investor. List); (* Eat the newline between client records *) end; James Tam

i : = i + 1; client. Count : = client. Count + 1;

i : = i + 1; client. Count : = client. Count + 1; end; close(investor. List); end; (* Read client information *) procedure display. Instructions; begin writeln; writeln('This program allows you track a list of clients each of which is'); writeln('is an investor. The initial investor information will be read'); writeln('from the file called "investor. List". From there you can display'); writeln('the list of clients onscreen, add a client, modify the'); writeln('information for a client, erase clients from the list, recorder'); writeln('the list of clients or search for a client. When you are done'); writeln('quit the program and all of your changes will be written out to'); writeln('a file called "updated. Investor. List"'); end; James Tam

procedure display. Client. List (tamj. Client. List : Client. List; client. Count : integer

procedure display. Client. List (tamj. Client. List : Client. List; client. Count : integer ); var i : integer; begin writeln; writeln('Displaying client list'); for i : = 1 to client. Count do begin with tamj. Client. List[i] do begin writeln('First name: ': 12, first. Name); writeln('Last name: ': 12, last. Name); writeln('Income : $': 12, income: 0: 2); writeln('Email: ': 12, email); end; (*with-do *) writeln; end; (* for *) end; (* display. Client. List *) James Tam

procedure add. Client (var tamj. Client. List : Client. List; var client. Count :

procedure add. Client (var tamj. Client. List : Client. List; var client. Count : integer); var new. Client : Client; begin writeln; writeln('Adding new client to list of clients'); with new. Client do begin write('Enter first name of client (max 30 characters): '); readln(first. Name); write('Enter last name of client (max 30 characters): '); readln(last. Name); write('Enter annual gross income of client (max 8 digits)$'); readln(income); write('Enter email of client (max 30 characters): '); readln(email); writeln; end; (* with-do *) James Tam

tamj. Client. List[client. Count+1] : = new. Client; client. Count : = client. Count

tamj. Client. List[client. Count+1] : = new. Client; client. Count : = client. Count + 1; writeln('Added new client ', new. Client. last. Name); end; (* add. Client *) procedure swap (var first : Client; var second : Client); var temp : Client; begin temp : = first; first: = second; second : = temp; end; (* swap *) James Tam

procedure reorder (var tamj. Client. List : Client. List; client. Count : integer); var

procedure reorder (var tamj. Client. List : Client. List; client. Count : integer); var i : integer; is. Sorted : boolean; begin is. Sorted : = True; for i : = 1 to (client. Count-1) do begin if (tamj. Client. List[i]. last. Name > tamj. Client. List[i+1]. last. Name) then begin swap(tamj. Client. List[i], tamj. Client. List[i+1]); is. Sorted : = False; end; (* if-then *) end; (* for *) end; (* repeat-until *) until (is. Sorted = True); end; (* reorder *) James Tam

procedure save. Client. Information (tamj. Client. List : Client. List; client. Count : integer);

procedure save. Client. Information (tamj. Client. List : Client. List; client. Count : integer); var i : integer; begin writeln; rewrite(updated. Investor. List); writeln('Saving updated investor information to file'); writeln('"updated. Investor. List"'); for i : = 1 to client. Count do begin with tamj. Client. List[i] do begin writeln(updated. Investor. List, first. Name); writeln(updated. Investor. List, last. Name); writeln(updated. Investor. List, income: 0: 2); writeln(updated. Investor. List, email); writeln(updated. Investor. List); end; (* with-do *) James Tam

end; (* for loop *) writeln(updated. Investor. List); close(updated. Investor. List); end; (* save.

end; (* for loop *) writeln(updated. Investor. List); close(updated. Investor. List); end; (* save. Client. Information *) (* Main program *) begin var tamj. Client. List : Client. List; var client. Count : integer; var menu. Selection : char; read. Client. Information(tamj. Client. List, client. Count); display. Instructions; writeln('Options'); writeln('(D)isplay list of clients'); writeln('(A)dd a new client'); writeln('(M)odify an existing client'); writeln('(E)rase a client''s record from the list'); writeln('(R)eorder the client list by ascending last name'); writeln('(S)earch for a client'); writeln('(Q)uit the program. '); James Tam

write('Enter your option: '); readln(menu. Selection); case (menu. Selection) of 'D', 'd' : begin

write('Enter your option: '); readln(menu. Selection); case (menu. Selection) of 'D', 'd' : begin display. Client. List(tamj. Client. List, client. Count); end; 'A', 'a' : begin add. Client(tamj. Client. List, client. Count); end; 'M', 'm' : begin writeln; writeln('Modify client: You need to write the code to do this'); writeln('in your own program. '); end; James Tam

'E', 'e' : begin writeln; writeln('Erase client record: You need to write the code

'E', 'e' : begin writeln; writeln('Erase client record: You need to write the code to do'); writeln('this in your own program. '); end; 'R', 'r' : begin writeln; reorder (tamj. Client. List, client. Count); end; 'S', 's' : begin writeln; writeln('Search for a client: You need to write the code to do'); writeln('this in your own program. '); end; James Tam

'Q', 'q' : begin writeln; writeln('Thank you for using the Investor 2000 (TM) program.

'Q', 'q' : begin writeln; writeln('Thank you for using the Investor 2000 (TM) program. '); writeln('Come again!'); writeln; end; otherwise begin writeln; writeln('Please enter one of the following options: D, A, M, E, R'); writeln('S or Q'); writeln; end; (* Case with menu options*) end; (* repeat-until loop *) until (menu. Selection = 'Q') OR (menu. Selection = 'q'); save. Client. Information(tamj. Client. List, client. Count); end. James Tam