Write a C++ menu driven Payroll program. Must be user friendly.
Menu
1. Check data file
2. Read Data file
3. Process payroll for one employee
4. Process payroll for all employees
5. Print out to a text or an HTML file
6. Exit
You must use the following Payroll classes, structures,
pointers, arrays, enum, vector, recursive, advance file I/O, STL,
iterators and containers. The program to process an input file
below to calculate tax of 28% and output it to a text or an HTML
file with tables. Heading First name, Last Name, Full name, Salary,
Tax, Net PayWrite a C++ menu driven lottery picker program.
data.txt
Name hours rate of pay
David Shin 35 55.75
Al Smith 21 33.88
Peter Becker 48 25.22
Johnny Tiger 15 27.50
1) I have used STL method stof for converting string to float.
2) Used pointers to process payroll
3) Employee vector is used to store all data
4) Input is read from data.txt file which is the same syntax as shown above, Will also provide sample screenshot of input file.
4) Output is written in text file , whose name is provided by the user, also the file extension can be html too.
5) Read comments in code they will explain purpose of each function
HERE IS THE PROGRAM IN C++
#include<bits/stdc++.h>
using namespace std;
class employee
{
public:
string firstName;
string lastName;
string fullName;
float salary;
float hours;
float rateOfPay;
float tax;
float net;
employee()
{
firstName=lastName=fullName="";
salary=tax=net=-1.0;
}
};
vector<employee> E;
//Check Data file
void checkDataFile()
{
ifstream in("data.txt");
if(!in)
cout<<"DATA FILE NOT
AVAILABLE"<<endl;
else
cout<<"DATA FILE IS
AVAILABLE"<<endl;
in.close();
}
//reading the data file
void readDataFile()
{
ifstream in("data.txt");
if(!in)
{
cout<<"ERROR WHILE READING FILE\n";
return;
}
string data;
employee temp;
while (in >> data) {
temp.firstName=data;
if(in>>data)
temp.lastName=data;
if(in>>data)
temp.hours=stof(data);;
if(in>>data)
temp.rateOfPay=stof(data);;
E.push_back(temp);
}
cout<<"DATA READ FROM FILE"<<endl;
cout<<"First Name "<<"Last Name
"<<"Hours "<<"Rate Per
Hour"<<endl;
for(int i=0;i<E.size();++i)
{
cout<<E[i].firstName<<"
"<<E[i].lastName<<"
"<<E[i].hours<<"
"<<E[i].rateOfPay<<endl;
}
in.close();
}
//Process payroll (USING POINTERS TO PROCESS PAYROLL
void payroll(employee *e)
{
e->salary=e->hours*e->rateOfPay;
e->tax= e->salary -(e->salary*0.28);
e->net=e->salary-e->tax;
}
//Process payroll for one employee
void forOne()
{
string fname;
string lname;
cout<<"ENTER THE FIRST NAME OF EMPLOYEE:";
cin>>fname;
cout<<"ENTER THE LAST NAME OF EMPLOYEE:";
cin>>lname;
for(int i=0;i<E.size();++i)
{
if(E[i].firstName==fname &&
E[i].lastName==lname)
{
payroll(&E[i]);
}
}
}
//print on console
void printConsole()
{
cout<<"First Name
"<<"Last Name "<<"Full Name
"<<"Salary "<<"Tax
"<<"Net Pay"<<endl;
for(int i=0;i<E.size();++i)
{
cout<<E[i].firstName<<"
"<<E[i].lastName<<"
"<<E[i].firstName<<"
"<<E[i].lastName<<"
"<<E[i].salary<<" ";
cout<<E[i].tax<<"
"<<E[i].net<<endl;
}
}
//Process payroll for all employees
void forAll()
{
for(int
i=0;i<E.size();++i)
{
payroll(&E[i]);
}
printConsole();
}
//print out a text file
void print()
{
string fileName;
cout<<"ENTER THE NAME OF FILE WITH
EXTENSION: ";
cin>>fileName;
ofstream out(fileName);
out<<"First Name
"<<"Last Name "<<"Full Name
"<<"Salary "<<"Tax
"<<"Net Pay"<<endl;
for(int i=0;i<E.size();++i)
{
if(E[i].net!=-1.0)
{
out<<E[i].firstName<<"
"<<E[i].lastName<<"
"<<E[i].firstName<<"
"<<E[i].lastName<<"
"<<E[i].salary<<" ";
out<<E[i].tax<<"
"<<E[i].net<<endl;
}
}
out.close();
}
int main()
{
int option=0;
do
{
cout<<"1) Check Data
File"<<endl;
cout<<"2) Read Data
File"<<endl;
cout<<"3) Process payroll for
one employee "<<endl;
cout<<"4) Process payroll for
all employees"<<endl;
cout<<"5) Print out to a text
or an HTML file"<<endl;
cout<<"6)
Exit"<<endl;
cout<<"Enter a valid
choice:";
cin>>option;
switch(option)
{
case 1:
checkDataFile();
break;
case 2:
readDataFile();
break;
case 3:
forOne();
break;
case 4:
forAll();
break;
case 5:
print();
break;
case 6:
break;
default:
cout<<"ENTER A VALID
CHOICE"<<endl;
}
}while(option!=6);
return 0;
}
OUTPUT SCREENSHOT
INPUT FILE SCREENSHOT
CODE SCREENSHOT
Write a C++ menu driven Payroll program. Must be user friendly. Menu 1. Check data file ...
How would I do this problem? Write a C++ menu driven Payroll program. Must be user friendly. Menu 1. Check data file 2. Read Data file 3. Process payroll for one employee 4. Process payroll for all employees 5. Print out to a text or an HTML file 6. Exit You must use the following Payroll classes, structures, pointers, arrays, enum, vector, recursive, advance file I/O, STL, template, iterators and containers. The program to process an input file below to...
In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...
==============C++ or java================Write a modularized, menu-driven program to read a file with unknown number of records.Create a class Records to store the following data: first and last name, GPA , an Id number, and an emailInput file has unknown number of records; one record per line in the following order: first and last names, GPA , an Id number, and emailAll fields in the input file are separated by a tab (‘\t’) or a blank space (up to you)No error...