Page 1 of 1

65.00 A student has established the following monthly budget: Housing 500.00 Utilities 150.00 Household Expenses Transpo

Posted: Fri May 20, 2022 3:25 pm
by answerhappygod
65 00 A Student Has Established The Following Monthly Budget Housing 500 00 Utilities 150 00 Household Expenses Transpo 1
65 00 A Student Has Established The Following Monthly Budget Housing 500 00 Utilities 150 00 Household Expenses Transpo 1 (79.67 KiB) Viewed 31 times
PLEASE USE THE FOLLOWING CODE WITH SOLUTION IN C++, IT'S INCLUDED WITH THE QUESTION (COMMENTS ARE MADE WITH MISSING PIECES)
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
struct MonthlyBudget {
double housing;
double utilities;
double entertainment;
//default constructor, needed since all-args constructor
//was created, leverage that
MonthlyBudget() {
MonthlyBudget(0,0,0);
}
//all-args constructor
MonthlyBudget(double h, double u, double e) {
housing = h;
utilities = u;
entertainment = e;
}
};
void displayBudget(const MonthlyBudget &budget, const MonthlyBudget &expenses);
void outputCategory(string category, double budget, double expense);
int main() {
MonthlyBudget budget(500, 150, 200);
MonthlyBudget expenses;

cout << "Welcome to the student budget planner" << endl;
cout << "Let's see how your budget worked out for the month" << endl;
cout << "Enter your housing costs: ";
cin >> expenses.housing;
cout<< "Enter your utilities cost: ";
cin >> expenses.utilities;
cout << "Enter your entertainment costs: ";
cin >> expenses.entertainment;
displayBudget(budget, expenses);
return EXIT_SUCCESS;
}
void displayBudget(const MonthlyBudget &budget, const MonthlyBudget &expenses) {
outputCategory("housing", budget.housing, expenses.housing);
outputCategory("utilities", budget.utilities, expenses.utilities);

}
void outputCategory(string category, double budget, double expense) {
string spendState;
if (budget >= expense) {
spendState = "under";
} else {
spendState = "over";
}
cout << fixed << setprecision(2);
cout << "You spent $" << abs(budget - expense)
<< " " << spendState << " budget on " << category << "." << endl;
}
65.00 A student has established the following monthly budget: Housing 500.00 Utilities 150.00 Household Expenses Transportation 50.00 Food 250.00 Medical 30.00 Insurance 100.00 Entertainment 150.00 Clothing 75.00 Miscellaneous 50.00 Write a program that creates a MonthlyBudget structure designed to hold each of these expense categories. Create two monthly Budget variables, one that stores the target values (shown above). The other MonthlyBudget variable should be what the user has actually spent. Do this by prompting the user to enter the amount spent in each budget category for the month. Store each value in this structure. Then pass both structures to a function that displays a report (using cout) indicating the amount over or under in each category, as well as the amount over or under for the entire monthly budget.