P02 Weekly Pay - 10 points (turn in source code and sample output) |
|
This document is very similar to P01 Hello World,
except the source code to enter is different,
and it doesn't have all of the pictures. You may want to have P01 Introduction to Visual Studio .Net
available to use as a reference.
All program files are stored in Projects. This
document will walk you through the process of creating a Project, and adding source files and text files to
it.
|
|
|
Visual C++ 2008 Express Edition:
|
|
//P02 Weekly Pay Calculator - Juan Marquez
/*
This program is used by employees to determine what
their weekly net pay would be based on their hourly rate
and number of hours worked.
*/
#include <iostream>
using namespace std;
void main()
{
//Declare constants using the const modifier.
//Constants are named using all capital letters.
//There are two ways of assigning values; = and ()
const double UNION_DUES = 10.00, FICA_RATE = 0.06,
FEDERAL_RATE (0.15), STATE_RATE = (0.05);
//Define variables
//Variables that change value are in lowercase
int hours;
double rate, gross, fica, federal, state, netpay, netHourly;
//Set the decimal point to 2 positions
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
//Display name and the input prompt
cout << "P02 - Juan Marquez \n\n";
cout << "Enter the hourly rate and the number of hours \n"
<< "worked on the same line, but separated by a space. \n"
<< "Press the enter key after entering both values."
<< endl << endl
<< "Enter the hourly rate and hours worked: ";
//Get the input values
cin >> rate >> hours;
//Calculate gross, taxes, netpay, and netHourly
gross = rate * hours;
fica = gross * FICA_RATE;
federal = gross * FEDERAL_RATE;
state = gross * STATE_RATE;
netpay = gross - (fica + federal + state + UNION_DUES);
netHourly = netpay / hours;
//Display the results and echo the input (rate and hours).
//Display the values stored in constants.
//Use the space bar between : and \t in labels instead of
//the tab key for accurate alignment.
cout << endl
<< "Hourly Rate: \t" << rate << endl
<< "Hours Worked:\t" << hours << endl
<< "Gross Pay: \t" << gross << endl
<< "FICA Tax: \t" << fica << " at " << FICA_RATE << endl
<< "Federal Tax: \t" << federal << " at " << FEDERAL_RATE << endl
<< "State Tax: \t" << state << " at " << STATE_RATE << endl
<< "Union Dues: \t" << UNION_DUES << endl
<< "Net Pay: \t" << netpay << endl
<< "Net Hourly: \t" << netHourly << endl;
cout << "\nThank you!\n\n";
}
//end of main
|
|
|
|
P02 - Juan Marquez Enter the hourly rate and the number of hours worked on the same line, but separated by a space. Press the enter key after entering both values. Enter the hourly rate and hours worked: 9.25 25 Hourly Rate: 9.25 Hours Worked: 25 Gross Pay: 231.25 FICA Tax: 13.88 at 0.06 Federal Tax: 34.69 at 0.15 State Tax: 11.56 at 0.05 Union Dues: 10.00 Net Pay: 161.13 Net Hourly: 6.45 Thank you! Press any key to continue
|
Cases:
Payrate: 12.50 Hours Worked: 40
Payrate: 14.00 Hours Worked: 60
Payrate: 15.00 Hours Worked: 45
You will need to execute the program three additional times to process each case.
Sample Output:
The following output should be generated and captured.
P02 - Juan Marquez
Enter the hourly rate and the number of hours
worked on the same line, but separated by a space.
Press the enter key after entering both values.
Enter the hourly rate and hours worked: 12.50 40
Hourly Rate: 12.50
Hours Worked: 40
Gross Pay: 500.00
FICA Tax: 30.00 at 0.06
Federal Tax: 75.00 at 0.15
State Tax: 25.00 at 0.05
Union Dues: 10.00
Net Pay: 360.00
Net Hourly: 9.00
Thank you!
P02 - Juan Marquez
Enter the hourly rate and the number of hours
worked on the same line, but separated by a space.
Press the enter key after entering both values.
Enter the hourly rate and hours worked: 14 60
Hourly Rate: 14.00
Hours Worked: 60
Gross Pay: 840.00
FICA Tax: 50.40 at 0.06
Federal Tax: 126.00 at 0.15
State Tax: 42.00 at 0.05
Union Dues: 10.00
Net Pay: 611.60
Net Hourly: 10.19
Thank you!
P02 - Juan Marquez
Enter the hourly rate and the number of hours
worked on the same line, but separated by a space.
Press the enter key after entering both values.
Enter the hourly rate and hours worked: 15 45
Hourly Rate: 15.00
Hours Worked: 45
Gross Pay: 675.00
FICA Tax: 40.50 at 0.06
Federal Tax: 101.25 at 0.15
State Tax: 33.75 at 0.05
Union Dues: 10.00
Net Pay: 489.50
Net Hourly: 10.88
Thank you!