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

Project 3A: Designing and implementing a C++ structure data type: Monthly Budget

ID: 3918222 • Letter: P

Question

Project 3A: Designing and implementing a C++ structure data type: Monthly Budget

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 budgetand 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: Assertions and Dataflow comments) 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. Prior to submitting your completed source code, make sure your test-run output is similar to sample outputs provided. Submit your "source code" to the programming challenge above Turn in your source code by saving it as a .cpp file and attaching it to the file upload submission area.

4 points per correct function name/procedures for the following: (1) displayBudget (2) getExpenses (3) compareExpenses. Appropriate input validation routine must be included during user input of actual expenditures.

MonthlyBudget structure declared with appropriate members and two struct variables of type MonthlyBudget defined

Program shows correct output, properly formatted when it is compiled/run with sample data similar to the output shown

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

#include<iostream>

using namespace std;

typedef struct MonthlyBudget{

double Housing,Utilities,Household,Trasport,Food,Medical,Insurance,Entertainment,Clothing,Mis;

}MonthlyBudget;

void Display(MonthlyBudget first){

cout<<"Housing $"<<first.Housing<<" ";

cout<<"Utilities $"<<first.Utilities<<" ";

cout<<"Household $"<<first.Household<<" ";

cout<<"Transport $"<<first.Trasport<<" ";

cout<<"Food $"<<first.Food<<" ";

cout<<"Medical $"<<first.Medical<<" ";

cout<<"Insurance $"<<first.Insurance<<" ";

cout<<"Entertainment $"<<first.Entertainment<<" ";

cout<<"Clothing $"<<first.Clothing<<" ";

cout<<"Miscelleneous $"<<first.Mis<<" ";

cout<<"Total $"<<first.Clothing+first.Entertainment+first.Food+first.Household

+first.Housing+first.Insurance+first.Medical+first.Mis+first.Trasport+first.Utilities<<" ";

}

void getExpense(MonthlyBudget second){

double val;

while(1){

cout<<"Housing $";

cin>>val;

if(val<0)

cout<<"ERROR:You must enter a positive number ";

else{

second.Housing=val;

break;

}

}

while(1){

cout<<"Utilities $";

cin>>val;

if(val<0)

cout<<"ERROR:You must enter a positive number ";

else{

second.Utilities=val;

break;

}

}

while(1){

cout<<"Household $";

cin>>val;

if(val<0)

cout<<"ERROR:You must enter a positive number ";

else{

second.Household=val;

break;

}

}

while(1){

cout<<"Transport $";

cin>>val;

if(val<0)

cout<<"ERROR:You must enter a positive number ";

else{

second.Trasport=val;

break;

}

}

while(1){

cout<<"Food $";

cin>>val;

if(val<0)

cout<<"ERROR:You must enter a positive number ";

else{

second.Food=val;

break;

}

}

while(1){

cout<<"Medical $";

cin>>val;

if(val<0)

cout<<"ERROR:You must enter a positive number ";

else{

second.Medical=val;

break;

}

}

while(1){

cout<<"Insurance $";

cin>>val;

if(val<0)

cout<<"ERROR:You must enter a positive number ";

else{

second.Insurance=val;

break;

}

}

while(1){

cout<<"Entertainment $";

cin>>val;

if(val<0)

cout<<"ERROR:You must enter a positive number ";

else{

second.Entertainment=val;

break;

}

}

while(1){

cout<<"Clothing $";

cin>>val;

if(val<0)

cout<<"ERROR:You must enter a positive number ";

else{

second.Clothing=val;

break;

}

}

while(1){

cout<<"Miscellaneous $";

cin>>val;

if(val<0)

cout<<"ERROR:You must enter a positive number ";

else{

second.Mis=val;

break;

}

}

}

void compareExpense(MonthlyBudget first,MonthlyBudget second){

double totalfirst=first.Clothing+first.Entertainment+first.Food+first.Household

+first.Housing+first.Insurance+first.Medical+first.Mis+first.Trasport+first.Utilities;

double totalsecond=second.Clothing+second.Entertainment+second.Food+second.Household

+second.Housing+second.Insurance+second.Medical+second.Mis+second.Trasport+second.Utilities;

cout<<" Budgeted Spent Difference ";

cout<<"Housing "<<first.Housing<<" "<<second.Housing<<" "<<first.Housing-second.Housing<<" ";

cout<<"Utilities "<<first.Utilities<<" "<<second.Utilities<<" "<<first.Utilities-second.Utilities<<" ";

cout<<"Household "<<first.Household<<" "<<second.Household<<" "<<first.Household-second.Household<<" ";

cout<<"Transportation "<<first.Trasport<<" "<<second.Trasport<<" "<<first.Trasport-second.Trasport<<" ";

cout<<"Food "<<first.Food<<" "<<second.Food<<" "<<first.Food-second.Food<<" ";

cout<<"Medical "<<first.Medical<<" "<<second.Medical<<" "<<first.Medical-second.Medical<<" ";

cout<<"Insurance "<<first.Insurance<<" "<<second.Insurance<<" "<<first.Insurance-second.Insurance<<" ";

cout<<"Entertainment "<<first.Entertainment<<" "<<second.Entertainment<<" "<<first.Entertainment-second.Entertainment<<" ";

cout<<"Clothing "<<first.Clothing<<" "<<second.Clothing<<" "<<first.Clothing-second.Clothing<<" ";

cout<<"Miscellaneous "<<first.Mis<<" "<<second.Mis<<" "<<first.Mis-second.Mis<<" ";

cout<<"Total "<<totalfirst<<" "<<totalsecond<<" "<<totalfirst-totalsecond<<" ";

double val=totalfirst-totalsecond;

if(val>0)

cout<<"Congratulation!You were $"<<val<<" under the budget ";

else cout<<"You were $"<<val*(-1)<<" over the budget ";

}

int main(){

MonthlyBudget first={580,150,65,50,250,30,100,150,75,50},second;

Display(first);

cout<<" Enter actual expense ";

getExpense(second);

cout<<" ";

compareExpense(first,second);

return 0;

}

for any query please comment.

please upvote if find it helpful.

Thankyou.