Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5. Using Screen Control write Monthly Budget Structure - A student has established the following monthly budget (please use these budget figures): Housing 500.00, Utilities

5. Using Screen Control write Monthly Budget Structure - A student has established the following monthly budget (please use these budget figures): Housing 500.00, Utilities 150.00, Household expenses 65.00, 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 declares a MonthlyBudget structure with member variables to hold each of these expense categories. The program should create two MonthlyBudget structure variables. The first will hold the budget figures given above. The second will be passed to a function that has the user enter the amounts actually spent in each budget category during the past month. Using Monthly Budget program from DEMO-create a screen form that displays each category name and its budgeted amount, then positions the cursor next to it for the user to enter the amount actually spent in each category. The program should then pass both structure variables to a function that displays a report indicating the amount over or under budget the student spent in each category, as well as the amount over or under for the entire monthly budget.

When it says "Using Monthly Budget program from DEMO-", I have already created the DEMO program , just without using screen control. So I just need a little help with how to position the cursor in the correct place when they are prompted to enter how much they spent on each category

Here is the program without using screen control: #include #include using namespace std;

struct MonthlyBudget { double housing; double utilities; double household; double transportation; double food; double medical; double insurance; double entertainment; double clothing; double misc; double total;

MonthlyBudget(double rent = 0.0, double util = 0.0, double hh = 0.0, double trans = 0.0, double fd = 0.0, double med = 0.0, double insur = 0.0, double fun = 0.0, double cloth = 0.0, double mis = 0.0, double tot = 0.0) { housing = rent; utilities = util; household = hh; transportation = trans; food = fd; medical = med; insurance = insur; entertainment = fun; clothing = cloth; misc = mis; total = tot; }

}; // Function prototypes void displayBudget(const MonthlyBudget&); void getExpenses(MonthlyBudget&); void compareExpenses(const MonthlyBudget&, const MonthlyBudget&);

int main() { // Create a MonthlyBudget structure initialized with actual budget figures MonthlyBudget budget(500, 150, 65, 50, 230, 30, 100, 150, 75, 50, 1400);

MonthlyBudget spent;

displayBudget(budget); getExpenses(spent);

compareExpenses(budget, spent);

return 0; }

void displayBudget(const MonthlyBudget &budget) { cout << "Here is your monthly budget: "; cout << "Housing $" << setw(5) << budget.housing << endl; cout << "Utilities $" << setw(5) << budget.utilities << endl; cout << "Household $" << setw(5) << budget.household << endl; cout << "Transportation $" << setw(5) << budget.transportation << endl; cout << "Food $" << setw(5) << budget.food << endl; cout << "Medical $" << setw(5) << budget.medical << endl; cout << "Insurance $" << setw(5) << budget.insurance << endl; cout << "Entertainment $" << setw(5) << budget.entertainment << endl; cout << "Clothing $" << setw(5) << budget.clothing << endl; cout << "Misc $" << setw(5) << budget.misc << endl; cout << "Total $" << setw(5) << budget.total << endl; }

void getExpenses(MonthlyBudget &spent) { cout << " Enter actual monthly expenditures for each budget category: "; cout << "Rent/Mortage: $"; cin >> spent.housing; cout << "Utilities: $"; cin >> spent.utilities; cout << "Household: $"; cin >> spent.household; cout << "Transportation $"; cin >> spent.transportation; cout << "Food $"; cin >> spent.food; cout << "Medical $"; cin >> spent.medical; cout << "Insurance $"; cin >> spent.insurance; cout << "Entertainment $"; cin >> spent.entertainment; cout << "Clothing $"; cin >> spent.clothing; cout << "Misc $"; cin >> spent.misc; }

void compareExpenses(const MonthlyBudget &budget, const MonthlyBudget &spent) { double totalBudgeted; // Total monthly budget for all categories double totalSpent; // Total spent in all categories double difference; // Monthly amount over or under budget

totalBudgeted = budget.housing + budget.utilities + budget.household + budget.transportation + budget.food + budget.medical + budget.insurance + budget.entertainment + budget.clothing + budget.misc; totalSpent = spent.clothing + spent.entertainment + spent.food + spent.household + spent.housing + spent.insurance + spent.medical + spent.misc + spent.transportation + spent.utilities; difference = totalBudgeted - totalSpent;

cout << " Budgeted Spent Difference "; cout << "============================================" << endl; cout << "Housing " << setw(8) << budget.housing << setw(12) << spent.housing << setw(12) << (budget.housing - spent.housing) << endl; // Need to play with spent.housing - budget.housing cout << "Utilities " << setw(8) << budget.utilities << setw(12) << spent.utilities << setw(12) << (budget.utilities - spent.utilities) << endl; cout << "Household " << setw(8) << budget.household << setw(12) << spent.household << setw(12) << (budget.household - spent.household) << endl; cout << "Transportation " << setw(4) << budget.transportation << setw(12) << spent.transportation << setw(12) << (budget.transportation - spent.transportation) << endl; cout << "Food " << setw(12) << budget.food << setw(12) << spent.food << setw(12) << (budget.food - spent.food) << endl; cout << "Medical " << setw(8) << budget.medical << setw(12) << spent.medical << setw(12) << (budget.medical - spent.medical) << endl; cout << "Insurance " << setw(8) << budget.insurance << setw(12) << spent.insurance << setw(12) << (budget.insurance - spent.insurance) << endl; cout << "Entertainment " << setw(4) << budget.entertainment << setw(12) << spent.entertainment << setw(12) << (budget.entertainment - spent.entertainment) << endl; cout << "Clothing " << setw(8) << budget.clothing << setw(12) << spent.clothing << setw(12) << (budget.clothing - spent.clothing) << endl; cout << "Misc " << setw(12) << budget.misc << setw(12) << spent.misc << setw(12) << (budget.misc - spent.misc) << endl; cout << "============================================" << endl; cout << "Total" << setw(14) << totalBudgeted << setw(12) << totalSpent << setw(12) << difference << endl; cout << "============================================" << endl;

// Compute total amount budgeted, total spent and the difference totalBudgeted = budget.housing + budget.utilities + budget.household + budget.transportation + budget.food + budget.medical + budget.insurance + budget.entertainment + budget.clothing + budget.misc; totalSpent = spent.clothing + spent.entertainment + spent.food + spent.household + spent.housing + spent.insurance + spent.medical + spent.misc + spent.transportation + spent.utilities;

// If else statement to show over/under budget if (totalBudgeted > totalSpent) { cout << "You stayed under budget by $" << difference << " Good job!" << endl; } else if (totalSpent > totalBudgeted) { cout << "You were over budget by $" << difference << endl; } else { cout << "You were right on budget!" << endl; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions