Question

In: Computer Science

Summary Three employees in a company are up for a special pay increase. You are given...

Summary

Three employees in a company are up for a special pay increase. You are given a file, say Ch3_Ex5Data.txt, with the following data:

Miller Andrew 65789.87 5

Green Sheila 75892.56 6

Sethi Amit 74900.50 6.1

Each input line consists of an employee’s last name, first name, current salary, and percent pay increase.

For example, in the first input line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87, and the pay increase is 5%.

Instructions

Write a program that reads data from a file specified by the user at runtime (i.e. your program should accept the filename as user input) and stores the output in the file Ch3_Ex5Output.dat. To test your program, use the Ch3_Ex5Data.txt   file.

Your program will not pass all checks if it does not accept a filename as input from the user.

For each employee, the data must be output in the following form: firstName- (Adam) lastName- (Zeb) updatedSalary.

Format the output of decimal numbers to two decimal places.

Since your program handles currency, make sure to use a data type that can store decimals.

Solutions

Expert Solution

C code for above problem

#include<stdio.h>

// function that returns the number of lines in given file
int get_length(char name[])
{
   int len=0;
   char line[100];
   FILE *fp=fopen(name,"r");
   while(fgets(line,sizeof(line),fp))
   {
       len++;
   }
   fclose(fp);
   return len;
}

// tetsing main function
int main()
{
   char name[100];
   printf("Enter the file name: ");
   scanf("%s",name);
   FILE *fin=fopen(name,"r");
   if(fin==NULL)
   {
       printf("File not found\n");
       return 0;
   }
   FILE *fout=fopen("output.txt","w");
   int len=get_length(name);
   for(int i=0;i<len;i++)
   {
       char fname[50],lname[50];
       float amount,percent;
       fscanf(fin,"%s %s %f %f",lname,fname,&amount,&percent);
       amount+=(percent/100)*amount;
       fprintf(fout,"%s - (Adam) %s - (Zeb) %.2f\n",fname,lname,amount);
   }
   fclose(fin);
   fclose(fout);
   return 0;
}

Sample output

if "Ch3_Ex5Data.txt" has following data

Miller Andrew 65789.87 5
Green Sheila 75892.56 6
Sethi Amit 74900.50 6.1

then after running the above code, "output.txt" looks as follows:

Andrew - (Adam) Miller - (Zeb) 69079.36
Sheila - (Adam) Green - (Zeb) 80446.12
Amit - (Adam) Sethi - (Zeb) 79469.43

Mention in comments if any mistakes or errors are found. Thank you.


Related Solutions

Three employees in a company are up for a special pay increase. You are given a...
Three employees in a company are up for a special pay increase. You are given a file, say Ch3_Ex5Data.txt, with the following data: Miller Andrew 65789.87 5 Green Sheila 75892.56 6 Sethi Amit 74900.50 6.1 Each input line consists of an employee’s last name, first name, current salary, and percent pay increase. For example, in the first input line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87, and the pay...
you must research Medicare Fraud on the internet, locate three trustworthy sources, write up three summary...
you must research Medicare Fraud on the internet, locate three trustworthy sources, write up three summary tables (one for each source) then post your summary tables to the discussion. Note: You should not repeatedly use the same source or type of source (e.g., government web site). Rather you should utilize multiple sources. Additionally, dictionaries, although credible, should not be used as sources for this activity. Article 1 Title of Article: Author: Publication/source: URL: Date published: Date accessed: I think this...
Develop a Java application that determines the gross pay for each of three employees.
(Salary Calculator) Develop a Java application that determines the gross pay for each of three employees. The company pays straight time for the first 40 hours worked by each employee and time and a half for all hours worked in excess of 40. You’re given a list of the employees, their number of hours worked last week and their hourly rates. Your program should input this information for each employee, then determine and display the employee’s gross pay. Use class...
Suppose you start up a company that has developed a drug that is supposed to increase...
Suppose you start up a company that has developed a drug that is supposed to increase IQ. You know that the standard deviation of IQ in the general population is 15. You test your drug on 36 patients and obtain a mean IQ of 102.96. Using an alpha value of 0.05, is this IQ significantly different than the population mean of 100? (Two Tailed) State Null and Alternate Hypotheses. Apply test. Write your conclusion using critical value approach and p...
. In your small manufacturing company you prefer to pay the employees under Merricks differential piece-...
. In your small manufacturing company you prefer to pay the employees under Merricks differential piece- rate system. There are three employees; Rahman, Ali, and Mahmood who produced 85 units, 69 units and, 35 units respectively in one particular day. How much would you pay your employees if you have fixed 0.500 Baisa per unit as piece rate, standard output as 50 units per day? The employees normally work for 8 hours a day.
How did employees of Enron (and employees of the utilities company in Oregon) end up losing...
How did employees of Enron (and employees of the utilities company in Oregon) end up losing billions in retirement funds?
Ms.salma is yet to pay the salaries to her employees of last three months. Write a...
Ms.salma is yet to pay the salaries to her employees of last three months. Write a ahort note on accrued expenses with literature review and by providing examples.?
Calculate the following net pay for each of the given set of employees. Task 2: Control...
Calculate the following net pay for each of the given set of employees. Task 2: Control Procedures for Payroll Systems Identify control procedures for payroll systems depending on the execution and recording of the related transactions.
Stark Company has five employees. Employees paid by the hour receive a $11 per hour pay...
Stark Company has five employees. Employees paid by the hour receive a $11 per hour pay rate for the regular 40-hour workweek plus one and one-half times the hourly rate for each overtime hour beyond the 40 hours per week. Hourly employees are paid every two weeks, but salaried employees are paid monthly on the last biweekly payday of each month. FICA Social Security taxes are 6.2% of the first $118,500 paid to each employee, and FICA Medicare taxes are...
Stark Company has five employees. Employees paid by the hour receive a $11 per hour pay...
Stark Company has five employees. Employees paid by the hour receive a $11 per hour pay rate for the regular 40-hour workweek plus one and one-half times the hourly rate for each overtime hour beyond the 40 hours per week. Hourly employees are paid every two weeks, but salaried employees are paid monthly on the last biweekly payday of each month. FICA Social Security taxes are 6.2% of the first $118,500 paid to each employee, and FICA Medicare taxes are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT