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 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 Pay.
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
-------------------- I Used Visual Studio 2013, C++ Language, Console Application --------------------
--------------------OUTPUT--------------------
INPUT DATA ::
--------------------CODE--------------------
--------------------Payroll.h--------------------
#include "stdafx.h"
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
using namespace std;
const double tax = 0.28;
struct empDetail
{
string fname;
string lname;
int hours;
double payRate;
double salary;
double tax;
double netPay;
};
class Payroll
{
private:
vector<empDetail> empDetails;
empDetail *processedSingleEmp;
bool alreadyPrinted;
public:
Payroll();
void checkDataFile(string filename);
void readDataFile(string filename);
void processSingleEmployeePayroll(string name);
void processAllEmployeePayroll();
void printToConsole();
void printToTextFile(string filename);
void printToHTMLFile(string filename);
string convertToLower(string str);
string print(empDetail emp);
string header();
string toRound(double val);
};
--------------------Payroll.cpp--------------------
#include "stdafx.h"
#include "Payroll.h"
Payroll::Payroll()
{
processedSingleEmp = nullptr;
alreadyPrinted = false;
}
void Payroll::checkDataFile(string filename)
{
ifstream inFile(filename);
if (inFile.is_open())
cout << "File exist."
<< endl;
else
cout << "File doesn't exist."
<< endl;
}
void Payroll::readDataFile(string filename)
{
empDetail emp;
fstream countFile(filename);
fstream file(filename);
string word,line;
int count, lineCount;
count = lineCount = 0;
if (countFile.is_open())
{
while (getline(countFile,
line))
{
lineCount++;
}
}
else
{
cout << "File doesn't exist."
<< endl;
return;
}
if (lineCount > 0)
{
while (file >> word)
{
count++;
if (count ==
1)
{
emp.fname = word;
}
else if (count
== 2 || count == 3)
{
if (isdigit(word[0]))
{
emp.hours = stoi(word);
}
else
{
emp.lname = word;
}
}
else
{
emp.payRate = stoi(word);
empDetails.push_back(emp);
count = 0;
}
}
cout << lineCount << "
lines received successfully" << endl;
}
else
cout << "No lines to read"
<< endl;
}
void Payroll::processSingleEmployeePayroll(string
name)
{
alreadyPrinted = false;
name = convertToLower(name);
bool processed = false;
for (int i = 0; i < empDetails.size(); i++)
{
string fn =
convertToLower(empDetails[i].fname);
string ln =
convertToLower(empDetails[i].lname);
if (name == fn || name == ln ||
name == (fn + " " + ln))
{
empDetails[i].salary =
empDetails[i].hours*empDetails[i].payRate;
empDetails[i].tax = (empDetails[i].salary*tax);
empDetails[i].netPay = empDetails[i].salary -
empDetails[i].tax;
processedSingleEmp = &empDetails[i];
processed =
true;
}
}
if (processed)
cout << "Processed." <<
endl;
else
cout << "No information to
process." << endl;
}
void Payroll::processAllEmployeePayroll()
{
alreadyPrinted = false;
int size = empDetails.size();
if (size > 0)
{
for (int i = 0; i <
empDetails.size(); i++)
{
empDetails[i].salary =
empDetails[i].hours*empDetails[i].payRate;
empDetails[i].tax = empDetails[i].salary*tax;
empDetails[i].netPay = empDetails[i].salary -
empDetails[i].tax;
}
cout << "Processed." <<
endl;
}
else
cout << "No information to
process." << endl;
}
void Payroll::printToConsole()
{
string head = header();
if (processedSingleEmp == nullptr
&& alreadyPrinted==false)
{
cout << head;
for (int i = 0; i <
empDetails.size(); i++)
{
cout <<
print(empDetails[i]);
}
}
else if (alreadyPrinted == false)
{
empDetail ed =
*processedSingleEmp;
cout << head;
cout << print(ed) <<
endl;
}
}
void Payroll::printToTextFile(string fn)
{
ofstream outFile(fn);
if (outFile.is_open())
{
string head =
header();
if (processedSingleEmp
== nullptr && alreadyPrinted==false)
{
outFile <<
head;
for (int i = 0;
i < empDetails.size(); i++)
{
outFile << print(empDetails[i]) <<
endl;
}
}
else if (alreadyPrinted ==
false)
{
empDetail ed =
*processedSingleEmp;
outFile <<
head;
outFile <<
print(ed) << endl;
}
printToConsole();
outFile.close();
processedSingleEmp = nullptr;
alreadyPrinted = true;
cout << "\nSuccessfully saved
to file " << fn << endl;
}
else
cout << "Unable to open
file";
}
void Payroll::printToHTMLFile(string fn)
{
stringstream ss;
ss << "<!DOCTYPE html>" <<
endl
<< "<html>" <<
endl
<< "<head>" <<
endl
<< "<style>" <<
endl
<< "table{" <<
endl
<<
"font-family:arial,sans-serif;" << endl
<< "border-collapse:collapse;
" << endl
<< "width:100%;" <<
endl
<< "}" << endl
<< "td,th{" <<
endl
<< "border:1px solid
#dddddd;" << endl
<< "text-align:left;"
<< endl
<< "padding:8px;" <<
endl
<< "}" << endl
<< "tr:nth-child(even){"
<< endl
<< "background-color:
#dddddd;" << endl
<< "}" << endl
<< "</style>" <<
endl
<< "</head>" <<
endl
<< "<body>" <<
endl
<< "<h2>Payroll
Details</h2>" << endl
<< "<table>" <<
endl
<< "<tr>" <<
endl
<< "<th>First
Name</th>" << endl
<< "<th>Last
Name</th>" << endl
<< "<th>Full
Name</th>" << endl
<<
"<th>Salary</th>" << endl
<< "<th>Tax</th>"
<< endl
<< "<th>Net
Pay</th>" << endl
<< "</tr>" <<
endl;
ofstream outFile(fn);
if (outFile.is_open())
{
if (processedSingleEmp == nullptr
&& alreadyPrinted == false)
{
for (int i = 0;
i < empDetails.size(); i++)
{
string fullname = empDetails[i].fname + " " +
empDetails[i].lname;
ss << "<tr>" << endl
<<
"<td>"<<empDetails[i].fname<<"</td>"
<< endl
<< "<td>"
<< empDetails[i].lname << "</td>" <<
endl
<< "<td>"
<< fullname << "</td>" << endl
<< "<td>"
<< empDetails[i].salary << "</td>" <<
endl
<< "<td>"
<< empDetails[i].tax << "</td>" <<
endl
<< "<td>"
<< empDetails[i].netPay << "</td>" <<
endl
<< "</tr>"
<< endl;
}
}
else if (alreadyPrinted ==
false)
{
empDetail ed =
*processedSingleEmp;
string fullname
= ed.fname + " " + ed.lname;
ss <<
"<tr>" << endl
<< "<td>" << ed.fname <<
"</td>" << endl
<< "<td>" << ed.lname <<
"</td>" << endl
<< "<td>" << fullname <<
"</td>" << endl
<< "<td>" << ed.salary
<< "</td>" << endl
<< "<td>" << ed.tax <<
"</td>" << endl
<< "<td>" << ed.netPay
<< "</td>" << endl
<< "</tr>" << endl;
}
ss << "</table>"
<< endl
<<
"</body>" << endl
<<
"</html>
--------------------Main Function Class--------------------
#include "stdafx.h"
#include "Payroll.h"
#include <iostream>
using namespace std;
void Menu();
void SubMenu();
int main()
{
Payroll payroll;
string name,filename;
int choice = 0;
int choice2 = 0;
while (choice!=6)
{
Menu();
cin >> choice;
switch (choice)
{
case 1:
cout <<
"Enter filename : ";
cin.ignore();
getline(cin,
filename);
payroll.checkDataFile(filename);
break;
case 2:
cout <<
"Enter filename : ";
cin.ignore();
getline(cin,
filename);
payroll.readDataFile(filename);
break;
case 3:
cout <<
"Enter employee name : ";
cin.ignore();
getline(cin,
name);
payroll.processSingleEmployeePayroll(name);
break;
case 4:
payroll.processAllEmployeePayroll();
break;
case 5:
SubMenu();
cin >>
choice2;
if (choice2 ==
1)
{
cout << "Enter filename : ";
cin.ignore();
getline(cin, filename);
payroll.printToTextFile(filename);
}
else if
(choice2==2)
{
cout << "Enter filename : ";
cin.ignore();
getline(cin, filename);
payroll.printToHTMLFile(filename);
}
else
{
cout << "Invalid Input." <<
endl;
}
break;
case 6:
cout <<
"Exiting..."<<endl;
break;
default:
cout <<
"Invalid Input" << endl;
break;
}
}
return 0;
}
void Menu()
{
cout << "\nMain Menu" << endl;
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
employee" << endl;
cout << "<5> Print out to a text or an
HTML file" << endl;
cout << "<6> Exit" << endl;
cout << "Enter your choice : ";
}
void SubMenu()
{
cout << "\nSub Menu" << endl;
cout << "<1> Save to Text File" <<
endl;
cout << "<2> Save to HTML File" <<
endl;
cout << "Enter your choice : ";
}
------------------------------------------------------------
------------------------------------------------------------
How would I do this problem? Write a C++ menu driven Payroll program. Must be user...
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...