Question

In: Computer Science

C++ There is a file, called EmployeeInfo.txt, that contains information about company employees work for a...

C++

There is a file, called EmployeeInfo.txt, that contains information about company employees work for a week. You will write a program that reads the info from the file, and produces an output file called EmployeePay.txt with information about the employees pay amount for that week.


Details:
The input file is called EmployeeInfo.txt
There are 4 lines of input
Each line has the same form
Last Name, first Name, hours worked, pay rate, tax percentage, extra deductions
Example: John Doe 36 17.75 21 5 means that John Doe worked 36 hours, gets paid $17.75 per hour, has 21% taken out as income tax, plus an additional $5 taken out.
Your output file, called EmployeePay.txt, will have the form (for each employee)
Last, First
Total Earned:            amountEarned
Income Tax:            taxAmount
Additional Deduction:    extraDeduction
Pay Amount:            netIncome

Solutions

Expert Solution

Code:

#include<iostream>  // header file for input output operations 
#include<fstream>   // header file for file operations

using namespace std;
    
int main(){ // main function
    fstream file;   // fstream object
    string filename, word, lastname[100], firstname[100]; // variable to store data
    int count = 0, line = 1; // line to keep count of line and array index(in array index each index belong to one person's info)
    float hours[100], payrate[100],tax[100], extra[100], income_tax, extra_amount,total_earned,pay_amount;
    filename = "EmployeeInfo.txt";  // filename
    file.open(filename.c_str());    // opening file
    while (file >> word)    // reading words till end of the file
    {   
        if(count == 0){ // if first word is read
            lastname[line] = word;
        }else if(count == 1){ // if second word is read
            firstname[line] = word;
        }else if( count == 2){ // if third word is read
            hours[line] =  stof(word);
        }else if( count == 3){ // if fourth word is read
            payrate[line] = stof(word);
        }else if(count == 4){ // if fifth word is read
            tax[line] = stof(word);
        }else if( count == 5){ // if sixth word is read
            extra[line] = stof(word);
        }
        count++; // incrementing the word count counter
        if(count == 6){ // if one whlole line is read as there are just 6 word in each line
            count = 0;  // setting to count to zero indicated next worf will be first word
            line++; // increasing the line number
        }
    }
    ofstream my_file; // file object
    my_file.open("EmployeePay.txt");    // opening file
    for(int i=1;i<line;i++){    
        pay_amount = hours[i]*payrate[i];   // calculating the pay amount
        income_tax = (tax[i]*pay_amount)/100;   // calculating the income tax
        extra_amount = (extra[i]*pay_amount)/100;   // calculating the extra amount
        total_earned = pay_amount - income_tax - extra_amount;  // calculate total earned amount
        my_file <<lastname[i]<<", "<<firstname[i]<<"\n";    // writing data to file
        my_file << "Total Earned: " << total_earned << "\n";    // writing data to file
        my_file << "Income Tax: " << income_tax << "\n";    // writing data to file
        my_file << "Additional Deduction: " << extra_amount<< "\n";    // writing data to file
        my_file << "Pay Amount: " << pay_amount<< "\n";    // writing data to file
        
    }
    my_file.close(); // closing the file
}

Coontent of EmployeeInfo.txt:

Content of EmployeePay.txt:

=> size of array is declared as 100 by asuming that there are at max 100 entries inthe EmployeeInfo.txt file. if the entries are more than 100 the change the size accoudingly in all the arrays.

Here array element with index 0 represent data of first person and index 1 represent data of second person and so on.

Note: Please let me know if you have any doubt or there is any change required in the code.


Related Solutions

Chapter 15 contains information about the rights of the employees of a company as well as...
Chapter 15 contains information about the rights of the employees of a company as well as the responsibilities of the employer. A few of the concerns that employees have include the right to privacy and labor unions. Do you believe that drug testing of employees is necessary? Why and why not? Also, include at least 1 pro and 1 con of drug testing and name the occasions drug testing may be used. In addition,  explain how much privacy can employees expect...
Write a C++ program in a file called pop.cpp that opens a file called pop.dat which...
Write a C++ program in a file called pop.cpp that opens a file called pop.dat which has the following data (you’ll have to create pop.dat) AX013 1.0 BX123456 1234.56 ABNB9876152345 99999.99 The data are account numbers and balances. Account numbers are, at most 14 characters. Balances are, at most, 8 characters (no more than 99999.99). Using a loop until the end of file, read an account number and balance then write these to standard output in the following format shown...
Assume there is a file called "mydata". each line of the file contains two data items
how do you read in a file in JAVA Assume there is a file called "mydata". each line of the file contains two data items: hours and rate. hours is the represented by the number of hours the worker worked and rate is represented as hourly rate of pay. The first item of data is count indicating how many lines of data are to follow.Methodspay- accepts the number of hours worked and the rate of pay. returns the dollor and cents...
Overriding the equals Method File Player.java contains a class that holds information about an athlete: name,...
Overriding the equals Method File Player.java contains a class that holds information about an athlete: name, team, and uniform number. File ComparePlayers.java contains a skeletal program that uses the Player class to read in information about two baseball players and determine whether or not they are the same player. Fill in the missing code in ComparePlayers so that it reads in two players and prints “Same player” if they are the same, “Different players” if they are different. Use the...
the assignment folder for this assignment contains a file called values.txt. The first line in the...
the assignment folder for this assignment contains a file called values.txt. The first line in the file contains the total number of integers which comes after it. The length of this file will be the first line plus one lines long. Implement a MinHeap. Your program should read in input from a file, add each value to the MinHeap, then after all items are added, those values are removed from the MinHeap. Create a java class called MinHeap with the...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables:...
Using C# Create a class called Artist that contains 4 pieces of information as instance variables: name (datatype string), specialization – i.e., music, pottery, literature, paintings (datatype string), number of art items (datatype int), country of birth (datatype string). Create a constructor that initializes the 4 instance variables. The Artist class must contain a property for each instance variable with get and set accessors. The property for number should verify that the Artist contributions is greater than zero. If a...
The file Assign1_Data contains data on the hourly wages (Hourly Wage) of all employees of a...
The file Assign1_Data contains data on the hourly wages (Hourly Wage) of all employees of a grocery chain in the Ottawa region. (a) Treating this set of data as the population, use Minitab to calculate the population mean and the population standard deviation for the Hourly Wage variable. (b) Examine a boxplot and histogram of the population data. Explain if the means of all possible random samples of size 40 from this population would form a normal distribution. (c) Using...
Suppose we have an input file that contains information about how many hours each employee of...
Suppose we have an input file that contains information about how many hours each employee of a company has worked. The file looks like the following (Employee's name, Hours): John 6.5 9.5 7.25 9 8.55 Oscar 12.5 13.5 14 16 18.75 Judith 7 7 7 ••• Construct a program that reads this file and calculates the total number of hours worked by each individual. Make sure that the program handles each specific exception that could occur.' python
For c language. I want to read a text file called input.txt for example, the file...
For c language. I want to read a text file called input.txt for example, the file has the form. 4 hello goodbye hihi goodnight where the first number indicates the n number of words while other words are separated by newlines. I want to store these words into a 2D array so I can further work on these. and there are fewer words in the word file than specified by the number in the first line of the file, then...
A header file contains a class template, and in that class there is a C++ string...
A header file contains a class template, and in that class there is a C++ string object. Group of answer choices(Pick one) 1)There should be a #include for the string library AND a using namespace std; in the header file. 2)There should be a #include for the string library. 3)There should be a #include for the string library AND a using namespace std; in the main program's CPP file, written before the H file's include.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT