Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will read records from a file (create your data file by usi

ID: 3681454 • Letter: W

Question

Write a program that will read records from a file (create your data file by using data from sample below) and store them in a binary file. That file will then be used as input to create an output file of the information. The data file contains employee information consisting of name, social security, department ID, years employed, and salary. In addition to displaying the information of each record, the program will also calculate the average salary and years employed of all the records. This additional information is stored in the same output file.

Info that should be in data file:

Bill Tarpon 182460678 789 8 30600

Fred Caldron 456905434 789 10 40700

Sally Bender 203932239 790 8 50000

David Kemp 568903493 790 9 60000

Explanation / Answer

#include #include #include // a structure to read and write struct customer { char fname[20],lname[20]; int acct_num; float acct_balance; }; /**************************************/ void main () { FILE *outfile; struct customer input; // open Accounts file for writing outfile = fopen ("accounts.dat","w"); if (outfile == NULL) { fprintf(stderr, " Error opening accounts.dat "); exit (1); } // instructions to user printf("Enter "stop" for First Name to end program."); // endlessly read from keyboard and write to file while (1) { // prompt user printf(" First Name: "); scanf ("%s", input.fname); // exit if no name provided if (strcmp(input.fname, "stop") == 0) exit(1); // continue reading from keyboard printf("Last Name : "); scanf ("%s", input.lname); printf("Acct Num : "); scanf ("%d", &input.acct_num); printf("Balance : "); scanf ("%f", &input.acct_balance); // write entire structure to Accounts file fwrite (&input, sizeof(struct customer), 1, outfile); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote