home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Learn Pascal in a Three Days (2nd Ed.)
(Publisher: Wordware Publishing, Inc.)
Author(s):
ISBN: 1556225679
Publication Date: 07/01/97

Bookmark It

Search this book:
 
Previous Table of Contents Next


Sample runs:

(A) Reading records from the file: In this sample run, three records for three different categories of employees are read from the file. In the fourth attempt to read a record, we entered a social security number which is not in the file, and the message “SSN not found in file” was received. Notice that the data entered from the keyboard are italicized and bolded for clarity.

------------- Main Menu --------------
1. Display an employee record.
2. Add a new employee.
3. Exit.
--------------------------------------
Make a choice and press a number: 1
Please enter the SSN of the employee: 434-55-6666

---------- Employee Record -----------
ID: 1MGT1
Name: James A. Abolrous
Position: President
SSN: 434-55-6666
Salary: 4343.88

------------- Main Menu --------------
1. Display an employee record.
2. Add a new employee.
3. Exit.
--------------------------------------
Make a choice and press a number: 1
Please enter the SSN of the employee: 404-38-1132

---------- Employee Record -----------
ID: 2STF1
Name: Tara S. Strahan
Position: Secretary II
SSN: 404-38-1132
Rate: 8.24

------------- Main Menu --------------
1. Display an employee record.
2. Add a new employee.
3. Exit.
--------------------------------------
Make a choice and press a number: 1
Please enter the SSN of the employee: 334-88-1234

---------- Employee Record -----------
ID: 3SAL4
Name: John G. Trainer
Position: Sales Representative
SSN: 334-88-1234
Commission: 0.25
Basic Salary: 500.00
Area: Baton Rouge, LA

------------- Main Menu --------------
1. Display an employee record.
2. Add a new employee.
3. Exit.
--------------------------------------
Make a choice and press a number: 1
Please enter the SSN of the employee: 555-55-5555
SSN not found in file.
Please try again.

------------- Main Menu --------------
1. Display an employee record.
2. Add a new employee.
3. Exit.
--------------------------------------
Make a choice and press a number: 3

(B) Appending records to the file: In the following run, a new record is appended to the payroll file:

------------- Main Menu --------------
1. Display an employee record.
2. Add a new employee.
3. Exit.
--------------------------------------
Make a choice and press a number: 2
Please enter Employee ID: 3SAL6
Name: Barbara Ortiz
Position: Sales Representative
SSN (xxx-xx-xxxx): 347-12-3456
Payroll category: 3
Commission: .15
Basic salary: 450.0
Area: New Orleans, LA

------------- Main Menu --------------
1. Display an employee record.
2. Add a new employee.
3. Exit.
--------------------------------------
Make a choice and press a number: 3

At this point, the new record of “Barbara Ortiz” has been appended to the payroll file and may be displayed using option “2.” Needless to say, you can also add a record at the end of the file using any text editor.

There are some important points in the program:

1.  This program is divided into three procedures:
• “Menu” to display and accept the menu options.
• “ReadRec” to read the file.
• “AddRec” to append records to the file.
2.  When dealing with a variant record, either by reading or writing, you must use the CASE structure.
3.  The flag “Found” is used in the “ReadRec” procedure to check the existence of the required record in the file, and to issue the proper message in each case. Notice that the flag is reset at the beginning of the procedure (Found := 0). When the required record is found, the flag is assigned the value “1”; otherwise, it retains the value “0” and the message “SSN not found..” is issued after the end-of-file has been reached.

Drill 10-1

Write a program to create the payroll file used in the previous example. You understand that this program may be used only once, because each time you run it, a new file is created. You may refer to the program on the companion disk under the name “DRL10-1.PAS.” The program is designed to create a file with the name “pr.txt” in order to avoid rewriting the file “payroll.txt.”


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.