Use the notepad program to create a payroll file for 20 records as follow: Employee’s First name, Last
name, Social Security Number, Hours worked and Hourly rate.
Save this file and place it in the folder where your .CPP file is located in your program.
Write a C++ program to read this file into your program and do the proper calculation including overtime
if any. Overtime is times and half of the pay rate. Deduct 2% for Social Security, 5% retirement plan, 3%
Federal tax
(total of 10% deduction) Create a report as follow: Last four digits of SSN, Employee’s first initial
and last name, Hours worked, Hourly rate, Gross pay, Total deductions, and Net pay. You may have to use “substr” for SSN and Employees first initial.
Make sure you have number of records and thank you note as a summary at the bottom
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string filename = "employee.txt";
ofstream outputFile;
ifstream inFile;
int numEmployees;
int socialSecurity = 0;
string name;
double netpay=0;
double grossPay = 0, hours = 0, rate = 0;
double overtime=0;
//determine number of employees
cout << "How many employees do you have? ";
cin >> numEmployees;
inFile.open(filename.c_str()); //create and open file
if (outputFile.fail())
{
cout << "The file was not successfully opened" << endl;
exit(1);
}
int i;
inFile.open("employee.txt");
cout << "Reading data from file.\n\n";
cout << "Social \nSecurity \nNumber \t\t Name \t\t Gross Pay\n";
cout << "-------- \t ----- \t\t ----------\n";
for (int count = 1; count <= numEmployees; count++)
{
inFile >> name; //Receive employee name
inFile >> socialSecurity; // receive employee SS num
cout << socialSecurity << "\t"; // display SS num
cout << name << "\t"; // display employee name
inFile >> rate; // receive employee rate
inFile >> hours; // receive total hours
grossPay = hours * rate; // calculate gross pay
inFile >>netpay;
cout << grossPay << endl; // display gross pay
cout<<overtime;
if(overtime>1){
cout<<"overtime=";
}
else{
cout<<endl;
}
}
inFile.close();
system("pause");
return 0;
}
Comments
Leave a comment