Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project#3(a)-Designing and implementing a C++ structure data type: Monthly Budge

ID: 3689930 • Letter: P

Question

Project#3(a)-Designing and implementing a C++ structure data type: Monthly Budget (20 points)

A student has established the following monthly budget:

Write a program that declares a MonthlyBudget structure designed with member variables to hold each of these expense categories. The program should define two MonthlyBudget structure variables budget and spent. The first MonthlyBudget structure variable budget will contain (ie., be assigned) the budget figures given above. Pass this first structure budget variable to a function displayBudget that will display the budget categories along with the budgeted amounts.

The second MonthlyBudget structure variable spent will be passed to another function getExpenses that has the user enter the amounts actually spent in each budget category during the past month. Finally, the program should then pass both structure variables budget and spent to a function compareExpenses 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.

You may design your own user-input interface but you must use a structure and must implement the three functions listed above. The format of the monthly budgeted report should appear as similar as possible to the sample output shown below.

HINT: Use the setw and right manipulators (Gaddis 7EO, Chapter 3) to right-justify dollar value outputs in function compareExpenses.

INPUT VALIDATION: Do not accept negative values for the users actual expenditure inputs in function getExpenses.

Please make sure to include appropriate function documentation as needed (see handout on function documentation) and separate your functions with at least 1/2 inch of whitespace. You may use parameterized constructors for the initial budget amounts and constant reference parameters when passing the structure variables to the functions mentioned above (refer to struct related source code samples: struct1b.cpp,  struct3a.cpp and struct3b.cpp).  DO NOT use global variables. Turn in your source code followed by your program output. A single test-run output is sufficient.

Budget Categories Budgeted amount Housing $ 580.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 *(DO NOT use arrays, pointers or an array of structs)

Explanation / Answer

Hi below i have written the code for your reference,

#include <iostream> #include <iomanip> using namespace std; struct MonthlyBudget { double Housing, Utilities, HouseholdExpense, Transportation, Food, Medical, Insurance, Entertainment, Clothing, Miscellaneous; }; // Function Prototypes void getSpent(MonthlyBudget &); void displayReport(MonthlyBudget A, MonthlyBudget B); void displayReportHelper(double B, double S); double total(MonthlyBudget); //--------------------------- Main ------------------------------- int main() { MonthlyBudget Budget = {580.00, 150.00, 65.00, 50.00, 250.00, 30.00, 100.00, 150.00, 75.00, 50.00}; MonthlyBudget Spent; getSpent(Spent); displayReport(Budget, Spent); return 0; } /***************************************************************** * getSpent * * This function has the user enter the amounts actually spent * * in each budget category during the past month. * *****************************************************************/ void getSpent(MonthlyBudget &B) { cout << "During the past month: "; cout << "How much was spent on Housing? "; cin >> B.Housing; cout << "How much was spent on Utilities? "; cin >> B.Utilities; cout << "How much was spent on Household expenses? "; cin >> B.HouseholdExpense; cout << "How much was spent on Transportation? "; cin >> B.Transportation; cout << "How much was spent on Food? "; cin >> B.Food; cout << "How much was spent on Medical? "; cin >> B.Medical; cout << "How much was spent on Insurance? "; cin >> B.Insurance; cout << "How much was spent on Entertainment? "; cin >> B.Entertainment; cout << "How much was spent on Clothing? "; cin >> B.Clothing; cout << "How much was spent on Miscellaneous? "; cin >> B.Miscellaneous; } /******************************************************************** * displayReport * * This function accepts both MonthlyBudget variables as arguments. * * Displays a report indicating the amount over or under budget the * * student spent in each category and the amount over or under the * * entire budget. * ********************************************************************/ void displayReport(MonthlyBudget B, MonthlyBudget S) { double TotalBudget, TotalSpent; cout << " Monthly budget report "; cout << "------------------------------------------ "; cout << "Housing: $"; displayReportHelper(B.Housing, S.Housing); cout << "Utilities: $"; displayReportHelper(B.Utilities, S.Utilities); cout << "Household expenses: $"; displayReportHelper(B.HouseholdExpense, S.HouseholdExpense); cout << "Transportation: $"; displayReportHelper(B.Transportation, S.Transportation); cout << "Food: $"; displayReportHelper(B.Food, S.Food); cout << "Medical: $"; displayReportHelper(B.Medical, S.Medical); cout << "Insurance: $"; displayReportHelper(B.Insurance, S.Insurance); cout << "Entertainment: $"; displayReportHelper(B.Entertainment, S.Entertainment); cout << "Clothing: $"; displayReportHelper(B.Clothing, S.Clothing); cout << "Miscellaneous: $"; displayReportHelper(B.Miscellaneous, S.Miscellaneous); TotalBudget = total(B); TotalSpent = total(S); cout << "Entire budget: $"; displayReportHelper(TotalBudget, TotalSpent); } /******************************************************************* * displaReportHelper * * This function accepts two MonthlyBudget member variables as * * arguments and displays the amount over or under budget the * * the student spent. * *******************************************************************/ void displayReportHelper(double B, double S) { cout << fixed << showpoint << setprecision(2); if (B > S) { cout << setw(7) << B - S; cout << " under. "; } else { cout << setw(7) << S - B; cout << " over. "; } } /******************************************************************* * total * * This function accepts a MonthlyBudget structure variable as an * * argument and returns the sum of it member values. * *******************************************************************/ double total(MonthlyBudget B) { return B.Housing + B.Utilities + B.HouseholdExpense + B.Transportation + B.Food + B. Medical + B.Insurance + B.Entertainment + B.Clothing + B. Miscellaneous; }