James Tam program investors (input, output, investorList, updatedInvestorList); const MAXCLIENTS = 10; NAMELENGTH = 30; EMAILLENGTH = 30; type Client =

Slides:



Advertisements
Similar presentations
James Tam Linked Lists in Pascal Linked Lists In this section of notes you will learn how to create and manage a dynamic list.
Advertisements

Program CheckPass; var TestScore, ExamScore : integer; FinalScore : real; Status : string; begin write(‘Enter the Test score:’); readln(Testscore); write(‘Enter.
J. Michael Moore Text Files CSCE 110 From James Tam’s material.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
James Tam Multi-Dimensional Arrays In Pascal In this section of notes you will learn about how and when to use multi- dimensional arrays.
James Tam Repetition In Pascal In this section of notes you will learn how to have a section of code repeated without duplicating the code.
James TamThe Bubble Sort in Pascal Sorting (Bubble) In this section of notes you will learn one technique for ordering a list.
James Tam Breaking Problems Down This section of notes shows you how to break down a large problem into smaller modules that are easier to implement and.
James Tam Breaking Problems Down This section of notes shows you how to break down a large programming problem into smaller modules that are easier to.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
James Tam Sorting (Bubble) In this section of notes you will learn one technique for ordering a list.
James Tam Sorting (Bubble) In this section of notes you will learn one technique for ordering a list.
James Tam Introduction To Files In Pascal In this section of notes you will learn how to read from and write to files in Pascal.
James Tam Arrays In this section of notes you will be introduced to a composite type where all elements must be of the same type (homogeneous): arrays.
James Tam Sorting (Bubble) In this section of notes you will learn one technique for ordering a list.
James Tam Repetition In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
James Tam Introduction To Files In Pascal In this section of notes you will learn how to read from and write to files in your Pascal programs.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
James Tam Multi-Dimensional Arrays In Pascal In this section of notes you will learn about how and when to use multi- dimensional arrays.
J. Michael Moore From James Tam’s material Multi-Dimensional Arrays CSCE 110.
James Tam Linked Lists In this section of notes you will learn how to create and manage a dynamic list.
James Tam Sorting (Bubble) In this section of notes you will learn one technique for ordering a list.
J. Michael Moore Structured Programming CPSC 110 Drawn from James Tam's material.
J. Michael Moore Other Control Structures CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
J. Michael Moore Arrays CSCE 110 From James Tam’s material.
J. Michael Moore Modules: Getting information out CPSC 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
J. Michael Moore Structured Programming CSCE 110 Drawn from James Tam's material.
James Tam Linked Lists In this section of notes you will learn how to create and manage a dynamic list.
James Tam Linked Lists In this section of notes you will learn how to create and manage a dynamic list.
James Tam Breaking Problems Down This section of notes shows you how to break down a large programming problem into smaller modules that are easier to.
James Tam Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
J. Michael Moore From James Tam’s material Multi-Dimensional Arrays CSCE 110.
James Tam Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate your code.
James Tam Arrays In this section of notes you will be introduced to a homogeneous composite type, one- dimensional arrays.
James Tam Breaking Problems Down This section of notes shows you how to break down a large problem into smaller modules that are easier to implement and.
J. Michael Moore From James Tam's material Records CSCE 110.
J. Michael Moore Other Control Structures CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Loops In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
James Tam Multi-Dimensional Arrays In Pascal In this section of notes you will learn about how and when to use multi- dimensional arrays.
James Tam Breaking Problems Down This section of notes shows you how to break down a large programming problem into smaller modules that are easier to.
James Tam Records You will learn in this section of notes how to create a new, composite type, that can be composed of different types of elements.
J. Michael Moore Modules – the Basics CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
James Tam Linked Lists In this section of notes you will learn how to create and manage a dynamic list.
Link Lists In this section of notes you will learn how to create and manage a dynamic list. Link Lists in Pascal.
James Tam Introduction To Files In Pascal You will learn how to read from and write to text files in Pascal.
J. Michael Moore Arrays CSCE 110. J. Michael Moore Typical (although simplified) Problem Write a program that will track student grades in a class. The.
James Tam Records You will learn in this section of notes what is a record and how to use them in Pascal.
James Tam Breaking Problems Down This section of notes shows you how to break down a large problem into smaller modules that are easier to implement and.
James Tam Introduction To Files In Pascal In this section of notes you will learn how to read from and write to files in Pascal.
James Tam Introduction To Files In Pascal In this section of notes you will learn how to read from and write to text files in Pascal.
J. Michael Moore Modules – the Basics CSCE 110 Influenced by material developed by James Tam & Jennifer Welch.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Introduction to Pascal The Basics of Program writing.
Pascal Programming Today Chapter 11 1 Chapter 11.
PASCAL PROGRAMMING.
James Tam Multi-Dimensional Arrays In Pascal In this section of notes you will learn about how and when to use multi- dimensional arrays.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 11.
Array : 1-dimension อนันต์ ผลเพิ่ม Anan Phonphoem
Looping(1) For … to … do... Can you do this? Write a program to display:
FOR LOOP STRUCTURE For := to do eg. for I := 1 to 100 do begin writeln(‘This is a loop’); end;
Pascal Prof. Steven A. Demurjian
kbkjlj/m/lkiubljj'pl;
Sorting (Bubble) In this section of notes you will learn one technique for ordering a list.
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Presentation transcript:

James Tam program investors (input, output, investorList, updatedInvestorList); const MAXCLIENTS = 10; NAMELENGTH = 30; LENGTH = 30; type Client = record firstName : array [1..NAMELENGTH] of char; lastName : array [1..NAMELENGTH] of char; income : real; array [1.. LENGTH] of char; end; (* Declaration of record client *) ClientList = array [1..MAXCLIENTS] of Client; var investorList : text; updatedInvestorList : text;

James Tam procedure readClientInformation (var tamjClientList : ClientList ; var clientCount : integer ); var i : integer; begin; i := 1; writeln; reset(investorList); writeln('Opening file "investorList" for reading'); clientCount := 0; (* No clients exist in list yet. *) while NOT EOF (investorList) do begin with tamjClientList[i] do begin readln(investorList, firstName); readln(investorList, lastName); readln(investorList, income); readln(investorList, ); readln(investorList); (* Eat the newline between client records *) end;

James Tam i := i + 1; clientCount := clientCount + 1; end; close(investorList); end; (* Read client information *) procedure displayInstructions; 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 "investorList". 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 "updatedInvestorList"'); end;

James Tam procedure displayClientList (tamjClientList : ClientList; clientCount : integer ); var i : integer; begin writeln; writeln('Displaying client list'); for i := 1 to clientCount do begin with tamjClientList[i] do begin writeln('First name: ':12, firstName); writeln('Last name: ':12, lastName); writeln('Income :$':12, income:0:2); writeln(' ':12, ); end; (*with-do *) writeln; end; (* for *) end; (* displayClientList *)

James Tam procedure addClient (var tamjClientList : ClientList; var clientCount : integer); var newClient : Client; begin writeln; writeln('Adding new client to list of clients'); with newClient do begin write('Enter first name of client (max 30 characters): '); readln(firstName); write('Enter last name of client (max 30 characters): '); readln(lastName); write('Enter annual gross income of client (max 8 digits)$'); readln(income); write('Enter of client (max 30 characters):'); readln( ); writeln; end; (* with-do *)

James Tam tamjClientList[clientCount+1] := newClient; clientCount := clientCount + 1; writeln('Added new client ', newClient.lastName); end; (* addClient *) 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 tamjClientList : ClientList; clientCount : integer); var i : integer; isSorted : boolean; begin isSorted := True; for i := 1 to (clientCount-1) do begin if (tamjClientList[i].lastName > tamjClientList[i+1].lastName) then begin swap(tamjClientList[i], tamjClientList[i+1]); isSorted := False; end; (* if-then *) end; (* for *) end; (* repeat-until *) until (isSorted = True); end; (* reorder *)

James Tam procedure saveClientInformation (tamjClientList : ClientList; clientCount : integer); var i : integer; begin writeln; rewrite(updatedInvestorList); writeln('Saving updated investor information to file'); writeln('"updatedInvestorList"'); for i := 1 to clientCount do begin with tamjClientList[i] do begin writeln(updatedInvestorList, firstName); writeln(updatedInvestorList, lastName); writeln(updatedInvestorList, income:0:2); writeln(updatedInvestorList, ); writeln(updatedInvestorList); end; (* with-do *)

James Tam end; (* for loop *) writeln(updatedInvestorList); close(updatedInvestorList); end; (* saveClientInformation *) (* Main program *) begin var tamjClientList : ClientList; var clientCount : integer; var menuSelection : char; readClientInformation(tamjClientList, clientCount); displayInstructions; writeln; 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(menuSelection); case (menuSelection) of 'D', 'd' : begin displayClientList(tamjClientList, clientCount); end; 'A', 'a' : begin addClient(tamjClientList, clientCount); 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 to do'); writeln('this in your own program.'); end; 'R','r' : begin writeln; reorder (tamjClientList, clientCount); 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.'); 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; end; (* Case with menu options*) end; (* repeat-until loop *) until (menuSelection = 'Q') OR (menuSelection = 'q'); saveClientInformation(tamjClientList, clientCount); end.