Question

In C program Consider a file that contains employee records, called "empstat.txt." The data for each...

In C program

Consider a file that contains employee records, called "empstat.txt." The data for each employee consist of the employee’s last name (up to 20 characters), employee id number (up to 11 characters), gross pay for the week (double), taxes deducted (double) for the week, and net pay (double) for the week.

Create a struct to hold the employee information.

Write a void function called writeEmpFile that prompts the user to enter last name, id number, gross pay and taxes, then calculates the net pay, and writes the employee information to the employee data file.

Write a void function called readEmpFile that reads the data from the file just created and displays it nicely formatted.

We'll store the data in tab delimited format. Each line in the file will hold the information for one employee. Each item of employee information will be separated by a tab character. For example:

Smith<tab>0123456<tab>12000.00<tab>2000.00<tab>10000.00

The file will have 1 header line before the employee data. The format for the header line should be:

NAME<tab>IDNUM<tab>GROSS<tab>TAXES<tab>NET

Write a program that uses your functions to create and read the empstat.txt file. Allow the user to enter employee data until the the employee name "EXIT" is entered...then close the file. After all the data is entered and written to the file, use your readEmpFile function to read all the lines of the file and display the data.

For Example:

Enter Last Name (no spaces): Jones
Enter ID Number: 123009
Enter Gross Pay: 12000.01
Enter Taxes: 2000.37
Enter Last Name (no spaces): Smith
Enter ID Number: Abc2378
Enter Gross Pay: 10000.00
Enter Taxes: 2345.01
Enter Last Name (no spaces): EXIT

                 NAME          IDNUM       GROSS           TAXES             NET
                Jones         123009    12000.01        02000.37        09999.64
                Smith        Abc2378    10000.00        02345.01        07654.99

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey,

Below is the code to your question

#include <stdio.h>
#include <stdlib.h>
int flag=0;
void writeEmpFile(FILE* fptr)
{
char name[1000],id[100];
double pay,tax,net;
printf("Enter Last Name (no spaces): ");
scanf("%s",name);
if(strcmp(name,"EXIT")==0)
{
flag=1;
return;
}
printf("Enter ID Number: ");
scanf("%s",id);
printf("Enter Gross Pay: ");
scanf("%lf",&pay);
printf("Enter Taxes: ");
scanf("%lf",&tax);
net=pay-tax;
fprintf(fptr,"%s\t%s\t%.2lf\t0%.2lf\t0%.2lf\n", name,id,pay,tax,net);


}
void readEmpFile(FILE* fptr)
{
char ch;
ch = fgetc(fptr);
while (ch != EOF)
{
printf ("%c", ch);
ch = fgetc(fptr);
}
}
int main()
{
FILE *fptr;

fptr = fopen("empstat.txt", "w");
if(fptr == NULL)
{
printf("Error!");
return -1;
}
fprintf(fptr,"NAME\tIDNUM\tGROSS\t\tTAXES\t\tNET\n");
while(flag==0)
{
writeEmpFile(fptr);
}

fclose(fptr);

fptr = fopen("empstat.txt", "r");
if (fptr == NULL)
{
printf("Cannot open file \n");
return 0;
}
readEmpFile(fptr);
fclose(fptr);
return 0;
}

Add a comment
Know the answer?
Add Answer to:
In C program Consider a file that contains employee records, called "empstat.txt." The data for each...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In the data file employees.dat we have employee records with the following fields of information ...

    Unix/Linux In the data file employees.dat we have employee records with the following fields of information (ID, FN, LN, D, #) where ID: Employee identification number FN: Employee first name LN: Employee last name 8: Office number Write a shell script for processing employees.dat in such a way that we get the list of records (ID, FN, LN) and the total number of employees in the standard output as well as the file employees_by office.dat that contains emplayee records with...

  • C++ Program The Ward Bus Manufacturing Company has recently hired you to help them convert their...

    C++ Program The Ward Bus Manufacturing Company has recently hired you to help them convert their manual payroll system to a computer-based system. Write a program to produce a 1-week payroll report for only one employee to serve as a prototype (model) for the administration to review. Input for the system will be the employee’s 4-digit ID number, the employee’s name, hours worked that week, and the employee’s hourly pay rate. Output should consist of the employee’s ID number, the...

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

  • C++ Simple Employee Tracking System

    This assignment involves creating a program to track employee information.  Keep the following information on an employee:1.     Employee ID (string, digits only, 6 characters)2.     Last name (string)3.     First Name (string)4.     Birth date (string as MM/DD/YYYY)5.     Gender (M or F, single character)6.     Start date (string as MM/DD/YYYY)7.     Salary per year (double)Thus you must create a class that has all of this, and get/set methods for each of these fields.  Note: The fields that are designated as string should use the string...

  • In header file (.h) and c++ file format (.cpp). A local company has asked you to...

    In header file (.h) and c++ file format (.cpp). A local company has asked you to write a program which creates an Employee class, a vector of Employee class objects, and fills the objects with employee data, creating a "database" of employee information. The program allows the user to repeatedly search for an employee in the vector by entering the employee's ID number and if found, display the employee's data. The Employee_C class should have the following data and in...

  • You are given a file that contains employee data. The first entry in the file indicates...

    You are given a file that contains employee data. The first entry in the file indicates the number of employees stored in the file. After that, each entry in the file consists of the name of the employee, job title, number of promotions since hiring on, and the years the promotions occured. For example, one possible entry in the employee data file might be Mario Speedwagon Systems Engineer 2 2003 2006 which indicates that Mario Speedwagon is a Systems Engineer...

  • J Inc. has a file with employee details. You are asked to write a C++ program...

    J Inc. has a file with employee details. You are asked to write a C++ program to read the file and display the results with appropriate formatting. Read from the file a person's name, SSN, and hourly wage, the number of hours worked in a week, and his or her status and store it in appropriate vector of obiects. For the output, you must display the person's name, SSN, wage, hours worked, straight time pay, overtime pay, employee status and...

  • Lab exercise Computing III 9 1. There is text file (testl.txt) which contains multi-line data including...

    Lab exercise Computing III 9 1. There is text file (testl.txt) which contains multi-line data including the name "John" at multiple lines as follows. John is a good student. He studies regularly for 8 hours daily and attends to every lecture in school. John wants to be a computer programmer John is also a great sportsman. Open a new file (test2.txt) replacing the name “John" with "Smith" 2. Assume that a text file (text3.txt) stores employee data as follows. 1001,...

  • In C++, You are given a file of customer data with records in the following format...

    In C++, You are given a file of customer data with records in the following format : account number, last name, first name, middle name. Write a program to convert the input data and display it to the monitor in the following format : Accout Name     Logon ID Initial Pswd 21-88282712-B Keith S. Adams ADAM21 Adam88282 08-36847734-A John R. Sturm STUR08 Stur36847    etc. Notes :     1) The account number on the input is 10 digits     2)  The names on...

  • Write a C++ program Write a class named Employee that has the following member variables: name...

    Write a C++ program Write a class named Employee that has the following member variables: name A string that holds the employee name idNumber An int to hold employee id number department A string to hold the name of the department position A string to hold the job position The class will have three constructors: 1. A constructor that accepts all the internal data such as: Employee susan("Susan Meyers", 47899, "Accounting", "Vice President"); 2. A constructor that accepts some of...

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
ADVERTISEMENT
ADVERTISEMENT