Problem

(Creating Data for a File-Matching Program)Write a simple program to create some test data...

(Creating Data for a File-Matching Program)Write a simple program to create some test data for checking out the program of Exercise. Use the following sample account data:

Exercise

(File Matching)Exercise asked the reader to write a series of single statements. Actually, these statements form the core of an important type of file-processing program, namely, a filematching program. In commercial data processing, it’s common to have several files in each system. In an accounts receivable system, for example, there’s generally a master file containing detailed information about each customer such as the customer’s name, address, telephone number, outstanding balance, credit limit, discount terms, contract arrangements and possibly a condensed history of recent purchases and cash payments.

As transactions occur (i.e., sales are made and cash payments arrive in the mail), they’re entered into a file. At the end of each business period (i.e., a month for some companies, a week for others and a day in some cases) the file of transactions (called "trans.dat" in Exercise ) is applied to the master file (called "oldmast.dat" in Exercise ), thus updating each account's record of purchases and payments. After each of these updates runs, the master file is rewritten as a new file ("newmast.dat"), which is then used at the end of the next business period to begin the updating process again.

File-matching programs must deal with certain problems that do not exist in single-file programs. For example, a match does not always occur. A customer on the master file might not have made any purchases or cash payments in the current business period, and therefore no record for this customer will appear on the transaction file. Similarly, a customer who did make some purchases or cash payments might have just moved to this community, and the company may not have had a chance to create a master record for this customer.

Use the statements written in Exercise as the basis for a complete file-matching accounts receivable program. Use the account number on each file as the record key for matching purposes.

Assume that each file is a sequential file with records stored in increasing account-number order. When a match occurs (i.e., records with the same account number appear on both the master file and the transaction file), add the dollar amount on the transaction file to the current balance on the master file and write the "newmast.dat" record. (Assume that purchases are indicated by positive amounts on the transaction file, and that payments are indicated by negative amounts.) When there’s a master record for a particular account but no corresponding transaction record, merely write the master record to "newmast.dat". When there’s a transaction record but no corresponding master record, print the message "Unmatched transaction record for account number …" (fill in the account number from the transaction record).

Exercise

a) ofPtr = fopen( "oldmast.dat", "r" );b) tfPtr = fopen( "trans.dat", "r" );c) nfPtr = fopen( "newmast.dat", "w" );d) fscanf( ofPtr, "%d%s%f", &accountNum, name, ¤tBalance );e) fscanf( tfPtr, "%d%f", &accountNum, &dollarAmount );f) fprintf( nfPtr, "%d %s %.2f", accountNum, name, currentBalance );

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 11
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT