C++ Example Application: Payroll Evaluation - 2 Weeks
C++ Example Application: Payroll Evaluation - 2 Weeks
Introduction
The C++ language is good for many things such as the ability to learn programming. Probably the best way to learn programming is to write programs, a lot of them. In this exercise, we are expanding on our payroll application with more values for a 2-week time frame.
Practical Learning: Creating the Application
#include <iostream> int main() { std::cout << "Payroll Evaluation\n"; std::cout << "-------------------------------------------------------------"; std::cout << "\nEnter the following pieces of information"; std::cout << "\n============================================================="; std::cout << "\nEmployee Information"; std::cout << "\n-------------------------------------------------------------"; std::cout << "\nFirst Name: "; char firstName[20]; std::cin >> firstName; std::cout << ""; std::cout << "Last Name: "; char lastName[20]; std::cin >> lastName; std::cout << "Hourly Salary: "; double hSalary; std::cin >> hSalary; std::cout << "============================================================="; std::cout << "\nTime worked - First Week"; std::cout << "\n-------------------------------------------------------------\n"; std::cout << "Monday: "; double wk1Monday; std::cin >> wk1Monday; std::cout << "Tuesday: "; double wk1Tuesday; std::cin >> wk1Tuesday; std::cout << "Wednesday: "; double wk1Wednesday; std::cin >> wk1Wednesday; std::cout << "Thursday: "; double wk1Thursday; std::cin >> wk1Thursday; std::cout << "Friday: "; double wk1Friday; std::cin >> wk1Friday; std::cout << "============================================================="; std::cout << "\nTime worked - Second Week"; std::cout << "\n-------------------------------------------------------------\n"; std::cout << "Monday: "; double wk2Monday; std::cin >> wk2Monday; std::cout << "Tuesday: "; double wk2Tuesday; std::cin >> wk2Tuesday; std::cout << "Wednesday: "; double wk2Wednesday; std::cin >> wk2Wednesday; std::cout << "Thursday: "; double wk2Thursday; std::cin >> wk2Thursday; std::cout << "Friday: "; double wk2Friday; std::cin >> wk2Friday; double wk1TimeWorked = wk1Monday + wk1Tuesday + wk1Wednesday + wk1Thursday + wk1Friday; double wk2TimeWorked = wk2Monday + wk2Tuesday + wk2Wednesday + wk2Thursday + wk2Friday; double wk1RegTime = wk1TimeWorked; double wk1Overtime = 0.00; double wk1OverPay = 0.00; double wk1RegPay = hSalary * wk1TimeWorked; double wk2RegTime = wk2TimeWorked; double wk2Overtime = 0.00; double wk2OverPay = 0.00; double wk2RegPay = hSalary * wk2TimeWorked; if (wk1TimeWorked > 40.00) { wk1RegTime = 40.00; wk1RegPay = hSalary * 40.00; wk1Overtime = wk1TimeWorked - 40.00; wk1OverPay = hSalary * 1.50 * wk1Overtime; } if (wk2TimeWorked > 40.00) { wk2RegTime = 40.00; wk2RegPay = hSalary * 40.00; wk2Overtime = wk2TimeWorked - 40.00; wk2OverPay = hSalary * 1.50 * wk2Overtime; } double wk1NetPay = wk1RegPay + wk1OverPay; double wk2NetPay = wk2RegPay + wk2OverPay; double netPay = wk1NetPay + wk2NetPay; std::cout << "\n============================================================="; std::cout << "\nPayroll Evaluation"; std::cout << "\n============================================================="; std::cout << "\nEmployee Information"; std::cout << "\n-------------------------------------------------------------"; std::cout << "\nFull Name: " << firstName << " " << lastName; printf("\nHourly Salary: %.2f", hSalary); std::cout << "\n============================================================="; std::cout << "\nTime Worked Summary"; std::cout << "\n--------+--------+----------+-----------+----------+---------"; std::cout << "\n | Monday | Tuesday | Wednesday | Thursday | Friday"; std::cout << "\n--------+--------+----------+-----------+----------+---------"; printf("\n Week 1 | %6.2f | %7.2f | %7.2f | %6.2f | %5.2f", wk1Monday, wk1Tuesday, wk1Wednesday, wk1Thursday, wk1Friday); std::cout << "\n--------+--------+----------+-----------+----------+---------"; printf("\n Week 2 | %6.2f | %7.2f | %7.2f | %6.2f | %5.2f", wk2Monday, wk2Tuesday, wk2Wednesday, wk2Thursday, wk2Friday); std::cout << "\n============================================================="; std::cout << "\n\t\t\t\t\tPay Summary"; std::cout << "\n-------------------------------------------------------------"; std::cout << "\n\t\t\t\t\tTime Pay"; std::cout << "\n-------------------------------------------------------------"; printf("\n\tFirst Week\tRegular:\t%4.2f\t%8.2f", wk1RegTime, wk1RegPay); std::cout << "\n-------------------------------------------------------------"; printf("\n\t\t\tOver Time:\t%5.2f\t%8.2f", wk1Overtime, wk1OverPay); printf("\n-------------------------------------------------------------"); printf("\n\t\t\tWeekly Pay:\t%16.2f", wk1NetPay); std::cout << "\n============================================================="; printf("\n\tSecond Week\tRegular:\t%4.2f\t%8.2f", wk2RegTime, wk2RegPay); std::cout << "\n-------------------------------------------------------------"; printf("\n\t\t\tOver Time:\t%5.2f\t%8.2f", wk2Overtime, wk2OverPay); printf("\n-------------------------------------------------------------"); printf("\n\t\t\tWeekly Pay:\t%16.2f", wk2NetPay); std::cout << "\n============================================================="; printf("\n\t\t\tNet Pay:%24.2f", netPay); std::cout << "\n============================================================="; }
First Name: Michael Last Name: Carlock Hourly Salary: 28.46 Week 1 Monday: 7 Tuesday: 8 Wednesday: 6.5 Thursday: 8.5 Friday: 7.5 Week 2 Monday: 9.5 Tuesday: 8.5 Wednesday: 10.5 Thursday: 9 Friday: 8Here are are the results:
Payroll Evaluation ------------------------------------------------------------- Enter the following pieces of information ============================================================= Employee Information ------------------------------------------------------------- First Name: Michael Last Name: Carlock Hourly Salary: 28.46 ============================================================= Time worked - First Week ------------------------------------------------------------- Monday: 7 Tuesday: 8 Wednesday: 6.5 Thursday: 8.5 Friday: 7.5 ============================================================= Time worked - Second Week ------------------------------------------------------------- Monday: 9.5 Tuesday: 8.5 Wednesday: 10.5 Thursday: 9 Friday: 8 ============================================================= Payroll Evaluation ============================================================= Employee Information ------------------------------------------------------------- Full Name: Michael Carlock Hourly Salary: 28.46 ============================================================= Time Worked Summary --------+--------+----------+-----------+----------+--------- | Monday | Tuesday | Wednesday | Thursday | Friday --------+--------+----------+-----------+----------+--------- Week 1 | 7.00 | 8.00 | 6.50 | 8.50 | 7.50 --------+--------+----------+-----------+----------+--------- Week 2 | 9.50 | 8.50 | 10.50 | 9.00 | 8.00 ============================================================= Pay Summary ------------------------------------------------------------- Time Pay ------------------------------------------------------------- First Week Regular: 37.50 1067.25 ------------------------------------------------------------- Over Time: 0.00 0.00 ------------------------------------------------------------- Weekly Pay: 1067.25 ============================================================= Second Week Regular: 40.00 1138.40 ------------------------------------------------------------- Over Time: 5.50 234.79 ------------------------------------------------------------- Weekly Pay: 1373.20 ============================================================= Net Pay: 2440.45 ============================================================= Press any key to close this window . . .
|
|||
Home | Copyright © 2001-2025, FunctionX | Sunday 22 December 2024, 10:03 | Home |
|