#include <string>
#include <iostream>
struct EmployeeData
{
std::string name;
int hours;
int rate;
};
struct Salary
{
Salary(EmployeeData);
void print(std::ostream&);
private:
EmployeeData employee;
int gross_pay;
int federal_tax;
int state_tax;
int net_pay;
};
Salary::Salary(EmployeeData ed)
: employee(ed)
{
if (employee.hours <= 40)
{
gross_pay = employee.hours * employee.rate;
}
else
{
gross_pay = (40 * employee.rate) + (((employee.hours - 40) * 3 * employee.rate) / 2);
}
federal_tax = gross_pay / 5;
state_tax = gross_pay / 10;
net_pay = gross_pay - federal_tax - state_tax;
}
void Salary::print(std::ostream &out)
{
if (!employee.name.empty())
{
out << std::endl << employee.name << std::endl;
}
out << "Worked " << employee.hours << " hours" << std::endl
<< "$" << employee.rate << " per hour" << std::endl
<< "Gross pay is $" << gross_pay << std::endl
<< "Federal taxed ammount is $" << federal_tax << std::endl
<< "State taxed ammount is $" << state_tax << std::endl
<< "Net pay is $" << net_pay << std::endl;
}
void queryData(EmployeeData *ed)
{
std::cout << "Name:" << std::endl;
std::cin >> ed->name;
std::cout << "Hours:" << std::endl;
std::cin >> ed->hours;
std::cout << "Rate:" << std::endl;
std::cin >> ed->rate;
}
int main(int argc, char** argv)
{
EmployeeData ed;
if (argc == 3)
{
ed.hours = atoi(argv[1]);
ed.rate = atoi(argv[2]);
}
else
{
queryData(&ed);
}
Salary salary(ed);
salary.print(std::cout);
}