C++:Problem5

Problem:
Write a C++ program that prompts the user to input the pay rat an hour and the number of working hours each week. The program then outputs the income before and after taxes, the money spend on clothes and other accessories, the money spent on school supplies, the money spent on savings bonds and the money spent on additional bonds.

Software Design:
A. Problem: You have an exciting summer job for five weeks. You want to calculate your gross and net income; expenses, including clothes, accessories and supplies for the next school year. You also want to calculate the amount of money you spend on savings bonds and the amount your parents spend on “matching” savings bonds.

B. Analysis:

GIVEN:
A. Your job is for five weeks.
B. Total income tax rate is 14%.
C. You spend 10% of your net income to buy clothes and accessories for the next school year.
D. You spend 1% of your net income to buy clothes and accessories for the next school year.
E. You spend 25% of your remaining income to buy savings bonds.
F. Parents match every $1.00 you spend on savings bonds with $0.50 to buy additional savings bonds.
G. User enters the hourly pay rate and the total number of hours worked each week

FIND:
• Income before taxes
• Income after taxes
• Money spent on clothes and accessories
• Money spent on school supplies
• Money spent on savings bonds
• Money spent by your parents on additional savings bonds

C. Data types:
1. Input variables
• double hourly_pay_rate
• double hours_worked_per_week
2. Output variables
• double gross_income
• double net_income
• double budget_clothes_accessories
• double budget_school_supplies
• double budget_savings_bonds
• double parents_matching_savings_bonds
3. Program variables
• const int WEEKS_WORKED = 5
• const double TOTAL_TAX_RATE = 0.14
• const double CLOTHES_ACCESSORIES_PERCENT = 0.10
• const double SCHOOL_SUPPLIES_PERCENT = 0.01
• const double SAVINGS_BOND_PERCENT = 0.25
• const double PARENT_MATCHING_RATE = 0.50
• double total_hours_worked
• double remaining_income

D. Formulas
• All equations are simple calculations


E. Algorithm

1. Introduction
2. Ask user for hourly pay rate and average number of hours worked each week
3. Calculations
a. Gross income
b. Net income
c. Total money budgeted for clothes and accessories
d. Total money budgeted for school supplies
e. Remaining income
f. Total money budgeted for savings bonds
g. Total money matched by parents for savings bonds
4. Output results
5. Closing

F. Workspace:

If user inputs pay rate as $15.50 and number of hours worked each week as 20

total hours worked = 5 * 20 = 100

gross income = 100 * $15.50 = $1550.00

net income = (1 - .14) * $1550.00 = $1333.00

total money budgeted for clothes and accessories = .10 * $1333.00 = $133.30

total money budgeted for school supplies = .01 * $1333.00 = $13.33

remaining income = $1333.00 - $133.30 - $ 13.33 = $1186.37
total money budgeted for savings bonds = 0.25 * $1186.37 = $296.59

total money matched by parents for savings bonds = 0.50 * $296.59 = $148.30

Display:
Enter your hourly rate: 15.5
hours week 1: 40
hours week 2: 39
hours week 3: 38.5
hours week 4: 39.5
hours week 5: 37.5

Income before tax = $3014.75
Net income = $2592.68
Clothes and accessories money = $259.27
Supplies money = $25.93
Savings bonds money = $576.87
Additional saving bonds money = $288.00
End of Program

Code:
#include
#include
using namespace std;

int main ()
{

//Input variables
double rateperhour;
double hoursweek1, hoursweek2, hoursweek3, hoursweek4, hoursweek5;

//Output variables
double incomebeforetax, netincome, clothmoney, suppliesmoney, moneyonbonds, additionalbonds, remain;

//Format demical place
cout << fixed << showpoint << setprecision (2);

//Prompt the user for input
cout << "Enter your hourly rate: " << rateperhour;
cin >> rateperhour;
cout << "hours week 1: " << hoursweek1;
cin >> hoursweek1;
cout << "hours week 2: " << hoursweek2;
cin >> hoursweek2;
cout << "hours week 3: " << hoursweek3;
cin >> hoursweek3;
cout << "hours week 4: " << hoursweek4;
cin >> hoursweek4;
cout << "hours week 5: " << hoursweek5;
cin >> hoursweek5;

//Calculation
incomebeforetax = rateperhour * (hoursweek1 + hoursweek2 + hoursweek3 + hoursweek4+
hoursweek5) ;
netincome = incomebeforetax - incomebeforetax * 0.14;
clothmoney = netincome * 0.1;
suppliesmoney = netincome * 0.01;
remain = netincome - clothmoney - suppliesmoney;
moneyonbonds = remain * 0.25;
additionalbonds = static_cast(moneyonbonds) * .50;

//Display output
cout << endl << "Income before tax = $" << incomebeforetax << endl
<< "Net income = $" << netincome << endl << "Clothes and accessories money = $"
<< clothmoney << endl << "Supplies money = $"<< suppliesmoney << endl
<< "Savings bonds money = $" << moneyonbonds << endl
<< "Additional saving bonds money = $" << additionalbonds;


//closing
cout << "\nEnd of Program\n\n";
return 0;
}