Here\'s my edited code for the monthly budget BUT I have to meet the following r
ID: 3691047 • Letter: H
Question
Here's my edited code for the monthly budget BUT I have to meet the following requirements: -math library functions. - loops - files -parameters passed to functions; overloaded function. - input validation -arrays. Can somebody help me with this I don't want to rewrite the program because it might messed up everything. Thank you. #include <iostream>
#include<iomanip>
#include<fstream>
using namespace std;
float getIncome();
float getBudgetLiving();
float getActualLiving();
float getActualOther();
float computeTithing(float);
float computeTax(float);
float getActualTithing();
float getActualTax();
float difference(float, float, float);
float difference(float, float, float, float);
void chartDisplay();
void saveChart(float, float, float, float, float, float, float, float, float, float);
//Main display
int main() {
cout << " This program keeps track of your monthly budget ";
cout<> income; return income;
}
//gets users total budgeted living expenses
float getBudgetLiving()
{
float budgetLiving;
cout << " Enter your budgeted living expenses: $";
cin >> budgetLiving; return budgetLiving;
}
//Gets users total actual expenses
float getActualLiving()
{
float actualLiving;
cout << " Enter your actual/total living expenses: $";
cin >> actualLiving;
return actualLiving;
}
//gets users other/miscellaneous expenses
float getActualOther()
{
float other;
cout << " Enter your actual other expenses: $";
cin >> other; return other;
}
//computes tithing
float computeTithing(float income)
{
return income * 0.10;
}
//Computes Tax
float computeTax(float a)
{
float yearlyIncome;
float yearlyTax;
float monthlyTax;
yearlyIncome = a * 12;
if (a > 336550) yearlyTax = 91043 + 0.35*(yearlyIncome - 336550);
else if (336550 >= a > 188450) yearlyTax = 42170 + 0.33*(yearlyIncome - 188450);
else if (188450 >= a > 123700) yearlyTax = 24040 + 0.28*(yearlyIncome - 123700);
else if (123770 >= a > 61300) yearlyTax = 8440 + 0.25*(yearlyIncome - 61300);
else if (61300 >= a > 15100) yearlyTax = 15100 + 0.15*(yearlyIncome - 15100);
else (15100 >= a > 0);
yearlyTax = yearlyIncome*0.10;
monthlyTax = yearlyTax / 12;
return monthlyTax;
}
//gets users actual tithe paid
float getActualTithing()
{
float tithing;
cout << " Enter your actual tithe offerings/charity/donations:$ ";
cin >> tithing; return tithing;
}
//Gets users actual Tax Paid
float getActualTax()
{
float tax;
cout << " What is your estimated/budgeted taxes withheld: $";
cin >> tax; return tax;
}
float difference(float income, float budgetLiving, float other)
{
float computeBudgetDifference; float monthlyTax = computeTax(income);
float tithe = computeTithing(income);
computeBudgetDifference = income - (budgetLiving + tithe + monthlyTax + other); return computeBudgetDifference;
}
float difference(float income, float other, float actualLiving, float tax)
{
float computeActualDifference; float tithing = computeTithing(income);
computeActualDifference = income - (other + tithing + actualLiving + tax); return computeActualDifference;
}
//displays budget Chart void chartDisplay()
{
void chartDisplay()
{
cout<<fixed<<showpoint<<setprecision(2);
float income = getIncome();
float budgetLiving = getBudgetLiving();
float actualLiving = getActualLiving();
float other = getActualOther();
float tithing = getActualTithing();
float tithe = computeTithing(income);
float tax = getActualTax();
float monthlyTax = computeTax(income);
float computeBudgetDifference = difference(income, budgetLiving, other);
float computeActualDifference = difference(income, other, actualLiving, tax);
cout << " The following is a report on your monthly expenses" << endl;
cout << " Item" << setw(24) << "Budget" << setw(16) << "Actual" << endl;
cout << " =============== =============== ===============" << endl;
cout << " Income" << setw(11) << "$" << setw(11) << income << setw(5)
<< "$" << setw(11) << income << endl;
cout << " Taxes" << setw(12) << "$" << setw(11) << tax << setw(5) << "$"
<< setw(11) << monthlyTax << endl;
cout << " Tithing" << setw(10) << "$" << setw(11) << tithe << setw(5)
<< "$" << setw(11) << tithing << endl;
cout << " Living" << setw(11) << "$" << setw(11) << budgetLiving << setw(5)
<< "$" << setw(11) << actualLiving << endl;
cout << " Other" << setw(12) << "$" << setw(11) << other << setw(5)
<< "$" << setw(11) << other << endl;
cout << " =============== =============== ===============" << endl;
cout << " Difference" << setw(7) << "$" << setw(11)
<< computeBudgetDifference << setw(5) << "$" << setw(11)
<< computeActualDifference << endl;
saveChart(income, tax, monthlyTax, tithe, tithing, budgetLiving, actualLiving, other, computeBudgetDifference, computeActualDifference);
}
void saveChart(float income, float tax, float monthlyTax, float tithe, float tithing, float budgetLiving, float actualLiving, float other, float budgetDifference, float actualDifference)
{
ofstream outFile;
outFile.open("budget.txt");
if(!outFile)
{
cout << "Error Opening output file." << endl;
}
else
{
outFile<<fixed<<showpoint<<setprecision(2);
outFile << " The following is a report on your monthly expenses" << endl;
outFile << " Item" << setw(24) << "Budget" << setw(16) << "Actual" << endl;
outFile << " =============== =============== ===============" << endl;
outFile << " Income" << setw(11) << "$" << setw(11) << income << setw(5)
<< "$" << setw(11) << income << endl;
outFile << " Taxes" << setw(12) << "$" << setw(11) << tax << setw(5) << "$"
<< setw(11) << monthlyTax << endl;
outFile << " Tithing" << setw(10) << "$" << setw(11) << tithe << setw(5)
<< "$" << setw(11) << tithing << endl;
outFile << " Living" << setw(11) << "$" << setw(11) << budgetLiving << setw(5)
<< "$" << setw(11) << actualLiving << endl;
outFile << " Other" << setw(12) << "$" << setw(11) << other << setw(5)
<< "$" << setw(11) << other << endl;
outFile << " =============== =============== ===============" << endl;
outFile << " Difference" << setw(7) << "$" << setw(11)
<< budgetDifference << setw(5) << "$" << setw(11)
<< actualDifference << endl;
outFile.close();
}
}
Explanation / Answer
#include <iostream>
#include<iomanip>
#include<fstream>
using namespace std;
float getIncome();
float getBudgetLiving();
float getActualLiving();
float getActualOther();
float computeTithing(float);
float computeTax(float);
float getActualTithing();
float getActualTax();
float difference(float, float, float);
float difference(float, float, float, float);
void chartDisplay();
void saveChart(float, float, float, float, float, float, float, float, float, float);
//Main display
int main() {
cout << " This program keeps track of your monthly budget ";
// cin>> income;
chartDisplay();
}
float getIncome()
{
float income;
cout << " Enter your Income: $";
cin >> income; return income;
}
//gets users total budgeted living expenses
float getBudgetLiving()
{
float budgetLiving;
cout << " Enter your budgeted living expenses: $";
cin >> budgetLiving; return budgetLiving;
}
//Gets users total actual expenses
float getActualLiving()
{
float actualLiving;
cout << " Enter your actual/total living expenses: $";
cin >> actualLiving;
return actualLiving;
}
//gets users other/miscellaneous expenses
float getActualOther()
{
float other;
cout << " Enter your actual other expenses: $";
cin >> other; return other;
}
//computes tithing
float computeTithing(float income)
{
return income * 0.10;
}
//Computes Tax
float computeTax(float a)
{
float yearlyIncome;
float yearlyTax;
float monthlyTax;
yearlyIncome = a * 12;
if (a > 336550) yearlyTax = 91043 + 0.35*(yearlyIncome - 336550);
else if (336550 >= a > 188450) yearlyTax = 42170 + 0.33*(yearlyIncome - 188450);
else if (188450 >= a > 123700) yearlyTax = 24040 + 0.28*(yearlyIncome - 123700);
else if (123770 >= a > 61300) yearlyTax = 8440 + 0.25*(yearlyIncome - 61300);
else if (61300 >= a > 15100) yearlyTax = 15100 + 0.15*(yearlyIncome - 15100);
else (15100 >= a > 0);
yearlyTax = yearlyIncome*0.10;
monthlyTax = yearlyTax / 12;
return monthlyTax;
}
//gets users actual tithe paid
float getActualTithing()
{
float tithing;
cout << " Enter your actual tithe offerings/charity/donations:$ ";
cin >> tithing; return tithing;
}
//Gets users actual Tax Paid
float getActualTax()
{
float tax;
cout << " What is your estimated/budgeted taxes withheld: $";
cin >> tax; return tax;
}
float difference(float income, float budgetLiving, float other)
{
float computeBudgetDifference; float monthlyTax = computeTax(income);
float tithe = computeTithing(income);
computeBudgetDifference = income - (budgetLiving + tithe + monthlyTax + other); return computeBudgetDifference;
}
float difference(float income, float other, float actualLiving, float tax)
{
float computeActualDifference; float tithing = computeTithing(income);
computeActualDifference = income - (other + tithing + actualLiving + tax); return computeActualDifference;
}
//displays budget Chart void chartDisplay()
void chartDisplay()
{
cout<<fixed<<showpoint<<setprecision(2);
float income = getIncome();
float budgetLiving = getBudgetLiving();
float actualLiving = getActualLiving();
float other = getActualOther();
float tithing = getActualTithing();
float tithe = computeTithing(income);
float tax = getActualTax();
float monthlyTax = computeTax(income);
float computeBudgetDifference = difference(income, budgetLiving, other);
float computeActualDifference = difference(income, other, actualLiving, tax);
cout << " The following is a report on your monthly expenses" << endl;
cout << " Item" << setw(24) << "Budget" << setw(16) << "Actual" << endl;
cout << " =============== =============== ===============" << endl;
cout << " Income" << setw(11) << "$" << setw(11) << income << setw(5)
<< "$" << setw(11) << income << endl;
cout << " Taxes" << setw(12) << "$" << setw(11) << tax << setw(5) << "$"
<< setw(11) << monthlyTax << endl;
cout << " Tithing" << setw(10) << "$" << setw(11) << tithe << setw(5)
<< "$" << setw(11) << tithing << endl;
cout << " Living" << setw(11) << "$" << setw(11) << budgetLiving << setw(5)
<< "$" << setw(11) << actualLiving << endl;
cout << " Other" << setw(12) << "$" << setw(11) << other << setw(5)
<< "$" << setw(11) << other << endl;
cout << " =============== =============== ===============" << endl;
cout << " Difference" << setw(7) << "$" << setw(11)
<< computeBudgetDifference << setw(5) << "$" << setw(11)
<< computeActualDifference << endl;
saveChart(income, tax, monthlyTax, tithe, tithing, budgetLiving, actualLiving, other, computeBudgetDifference, computeActualDifference);
}
void saveChart(float income, float tax, float monthlyTax, float tithe, float tithing, float budgetLiving, float actualLiving, float other, float budgetDifference, float actualDifference)
{
ofstream outFile;
outFile.open("budget.txt");
if(!outFile)
{
cout << "Error Opening output file." << endl;
}
else
{
outFile<<fixed<<showpoint<<setprecision(2);
outFile << " The following is a report on your monthly expenses" << endl;
outFile << " Item" << setw(24) << "Budget" << setw(16) << "Actual" << endl;
outFile << " =============== =============== ===============" << endl;
outFile << " Income" << setw(11) << "$" << setw(11) << income << setw(5)
<< "$" << setw(11) << income << endl;
outFile << " Taxes" << setw(12) << "$" << setw(11) << tax << setw(5) << "$"
<< setw(11) << monthlyTax << endl;
outFile << " Tithing" << setw(10) << "$" << setw(11) << tithe << setw(5)
<< "$" << setw(11) << tithing << endl;
outFile << " Living" << setw(11) << "$" << setw(11) << budgetLiving << setw(5)
<< "$" << setw(11) << actualLiving << endl;
outFile << " Other" << setw(12) << "$" << setw(11) << other << setw(5)
<< "$" << setw(11) << other << endl;
outFile << " =============== =============== ===============" << endl;
outFile << " Difference" << setw(7) << "$" << setw(11)
<< budgetDifference << setw(5) << "$" << setw(11)
<< actualDifference << endl;
outFile.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.