Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

my code only returns cannot open trans.dat . c programming language . im trying to answer question 11.7 11.8 and 11.9 . the code below

my code only returns cannot open trans.dat .
c programming language . im trying to answer question 11.7 11.8 and 11.9 . the code below is for 11.8 . am i supposed to take the code from 11.8 and add it to 11.7 to get the answer to 11.9. i have included code for 11.7. I also included a pic of 11.3 table and the questions for 11.7-11.9.
code for 11.8 below
#include
#include
int main()
{
int mastAccount;
int transAccount;
double mastBalance;
double transBalance;
char masterName[30];
FILE *odfPtr;
FILE *trfPtr;
FILE *nwfPtr;
if ((odfPtr= fopen (" oldmast.dat","r" ))==NULL)
{
printf(" cant open trans.dat ");
exit(1);
}
if (( nwfPtr= fopen("newmast.dat","w") )==NULL)
{
printf("cant open newmast.dat ");
}
printf("result... ");
fscanf(trfPtr, "%dlf",&transAccount ,&transBalance);
while (!feof(trfPtr))
{
fscanf(odfPtr, "%d%[^0-9-]%lf",&mastAccount,masterName,&mastBalance);
while (mastAccount
{
fprintf(nwfPtr , " %d%s%.2f ",mastAccount,masterName,mastBalance);
fscanf(odfPtr , "%d%[^0-9-]%lf",&mastAccount,masterName,&mastBalance);
}
if (mastAccount==transAccount)
{
mastBalance+=transBalance;
fprintf(nwfPtr, " %d %s %.2f ",
mastAccount,masterName,mastBalance);
printf(" %d %s %.2f ",mastAccount,masterName,mastBalance);
}
else if (mastAccount > transAccount)
{
printf("unmatched transaction account: %d ",transAccount);
}
fscanf(trfPtr,"%d%lf",&transAccount,&transBalance);
}
while (!feof(odfPtr))
{
fscanf(odfPtr,"%d%[^0-9-]%lf",&mastAccount,masterName,&mastBalance);
fprintf(nwfPtr," %d %s %.2f ",mastAccount,masterName,mastBalance);
printf(" %d %s %.2f ",mastAccount,masterName,mastBalance);
}
fclose(odfPtr);
fclose(trfPtr);
fclose(nwfPtr);
return 0;
code for 11.7 below
#include
#include
int main()
{
int masterAccount;
int transacAccount;
double masterBalance;
double transacBalance;
char masterName [30];
FILE *odfptr;
FILE *trfptr;
odfptr=fopen("oldmaster.dat","w" );
trfptr=fopen("transact.dat","w");
printf("sample data for oldmaster.dat: ");
int x ;
do
{
printf(" enter account , name , balance :");
scanf("%d%[^0-9-]% lf",&masterAccount, masterName,&masterBalance);
fprintf(odfptr,"%d %s %.2f ",masterAccount,masterName,masterBalance );
printf(" do you want to add another account? ");
printf(" 1. yes ");
printf(" 0. no ");
getchar();
scanf( " %d ", &x );
} while (x!=0);
fclose(odfptr);
printf (" sample data for transact.dat: ");
int c ;
do
{
printf("enter account and transact amount:");
scanf( " %d %lf", &transacAccount, &transacBalance );
fprintf(trfptr,"%d %.2f ", transacAccount,transacBalance );
printf( " Do you want to add more transactions ? ");
printf(" 1. yes ");
printf(" 0. no ");
getchar();
scanf( " %d ", &c );
}
while (c!=0);
fclose (trfptr);
}
image text in transcribed
image text in transcribed
image text in transcribed
to create some its ture reference. 11.7 (Creating Data for a fi data for checking out the program of Exer (Creating Data for a File-Matching Program) Write a simple program to of Exercise 11.8. Use the following sample accoun Master File: Account number Balance Name 100 300 500 700 Alan Jones Mary Smith Sam Sharp Suzy Green 348.17 27.19 0.00 -14.22 Transaction File: Account number Dollar amount 100 300 400 900 27.14 62.11 100.56 82.17 Exercises 473 1.8 (File Matching Exercise 11.3 asked the reader to write a series of single statements. Actu- ally, these statements form the core of an important type of file-processing program, namely, a file- matching 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, out- standing balance, credit limit, discount terms, contract arrangements and possibly a condensed his- tory 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 11.3) is applied to the master file (called "oldmast.dat" in Exercise 11.3), 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 pro- grams. 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 pur- chases 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 11.3 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 " the master file and write the "newmast.dat" record. (Assume that purchases are indicated by ve amounts on the transaction file, and that payments are indicated by negative amounts en 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 cor- ponding master record, print the message "Unmatched transaction record for account number fill in the account number from the transaction record). e Testing the File Matching Exercises) Run the program of Exercise 11.8 using 11.9 (Testing test data created la created in Exercise 11.7. Check the results carefully. ibla actuallur com spe- 11.3 a) ofPtr = fopen("oldmast.dat", "-"): b) tfptr - fopen('trans.dat", "r"); c) nfptr - fopen("newmast.dat", "w"); d) fscanf(ofPtr. "XX", &account Num, name, ¤tBalance); e) fscanf(tfPtr. "%dxf", &accountNum, &dollarAmount); f) fprintf(nfPtr. "Xd s 5.2F", account Num, nane, currentBalance): hese re- to create some its ture reference. 11.7 (Creating Data for a fi data for checking out the program of Exer (Creating Data for a File-Matching Program) Write a simple program to of Exercise 11.8. Use the following sample accoun Master File: Account number Balance Name 100 300 500 700 Alan Jones Mary Smith Sam Sharp Suzy Green 348.17 27.19 0.00 -14.22 Transaction File: Account number Dollar amount 100 300 400 900 27.14 62.11 100.56 82.17 Exercises 473 1.8 (File Matching Exercise 11.3 asked the reader to write a series of single statements. Actu- ally, these statements form the core of an important type of file-processing program, namely, a file- matching 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, out- standing balance, credit limit, discount terms, contract arrangements and possibly a condensed his- tory 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 11.3) is applied to the master file (called "oldmast.dat" in Exercise 11.3), 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 pro- grams. 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 pur- chases 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 11.3 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 " the master file and write the "newmast.dat" record. (Assume that purchases are indicated by ve amounts on the transaction file, and that payments are indicated by negative amounts en 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 cor- ponding master record, print the message "Unmatched transaction record for account number fill in the account number from the transaction record). e Testing the File Matching Exercises) Run the program of Exercise 11.8 using 11.9 (Testing test data created la created in Exercise 11.7. Check the results carefully. ibla actuallur com spe- 11.3 a) ofPtr = fopen("oldmast.dat", "-"): b) tfptr - fopen('trans.dat", "r"); c) nfptr - fopen("newmast.dat", "w"); d) fscanf(ofPtr. "XX", &account Num, name, ¤tBalance); e) fscanf(tfPtr. "%dxf", &accountNum, &dollarAmount); f) fprintf(nfPtr. "Xd s 5.2F", account Num, nane, currentBalance): hese re

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the International Reference Alphabet?

Answered: 1 week ago