Need in C language also need full documentation/explanation of each line
A student has established the following monthly budget:
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
----------------------------------------------------
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 should 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 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 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.
A sample test run using the Code::Block IDE-Compiler |
Here is your monthly budget for YEAR 2020: Housing $ 580 Utilities $ 150 Household $ 65 Transportation $ 50 Food $ 250 Medical $ 30 Insurance $ 100 Entertainment $ 150 Clothing $ 75 Miscellaneous $ 50 ================================================= Total Budgeted $ 1500 ================================================= Enter month of expenditure: March Enter actual monthly expenditures for each budget category Housing: $ 580 Utilities: $ 130 Household: $ 50 Transportation:$ 50 Food: $ 230 Medical: $ 30 Insurance: $ 100 Entertainment: $ 120 Clothing: $ -10 ERROR: You must enter a positive number. Clothing: $ 100 Miscellaneous: $ 30 Budgeted Spent Difference ================================================= Housing 580.00 580.00 0.00 Utilities 150.00 130.00 -20.00 Household 65.00 50.00 -15.00 Transportation 50.00 50.00 0.00 Food 250.00 230.00 -20.00 Medical 30.00 30.00 0.00 Insurance 100.00 100.00 0.00 Entertainment 150.00 120.00 -30.00 Clothing 75.00 100.00 25.00 Miscellaneous 50.00 30.00 -20.00 ================================================= Total 1500.00 1420.00 80.00 ================================================= Congratulations! You were $80.00 under budget in March 2020. Process returned 0 (0x0) execution time : 104.850 s Press any key to continue. |
Please make sure to declare your struct above your function prototypes and include appropriate function documentation as needed. You may use pointers or constant reference parameters when passing the structure variables to the functions mentioned above (refer to struct related source code samples: struct1b.cpp
Links to an external site.
, struct3a.cpp
Links to an external site.
and struct3b.cpp
Links to an external site.
). DO NOT use global variables.
#include <iostream>
#include <cmath>
using namespace std;
//declare the structure
struct MonthlyExpenses{
double housing;
double utilities;
double houseHold;
double transport;
double food;
double medical;
double insurance;
double entertainment;
double clothing;
double misc;
};
//function prototype
void getData(MonthlyExpenses &);
void printData(const MonthlyExpenses &,
const MonthlyExpenses &);
double getDifference(double);
void printgoal(const MonthlyExpenses &);
int main()
{
//define a structure with the monthly
//budget as expected by the student
MonthlyExpenses goal = {580, 150, 65, 50,
250, 30, 100, 150,
75, 50};
//define another structure for the user to
//enter his expenses
printgoal(goal);
MonthlyExpenses currentMonth;
//read data into structure using getData()
cout << "Enter data for current month\n";
getData(currentMonth);
//print output using the printData() function
cout << "\n\nNow printing the amount of over";
cout << " or under budget\n";
printData(goal, currentMonth);
//return 0 to mark successful termination
return 0;
}
void getData(MonthlyExpenses &m){
cout << "Housing: ";
cin >> m.housing;
cout << "Utilities: ";
cin >> m.utilities;
cout << "Household expenses: ";
cin >> m.houseHold;
cout << "Transportation: ";
cin >> m.transport;
cout << "Food: ";
cin >> m.food;
cout << "Medical: ";
cin >> m.medical;
cout << "Insurance: ";
cin >> m.insurance;
cout << "Entertainment: ";
cin >> m.entertainment;
cout << "Clothing: ";
cin >> m.clothing;
cout << "Miscellaneous: ";
cin >> m.misc;
}
void printgoal(const MonthlyExpenses &g)
{
cout<<"Housing:";
cout<<g.housing<<endl;
cout << "Utilities: ";
cout<< g.utilities<<endl;
cout << "Household expenses: ";
cout<<g.houseHold<<endl;
cout << "Transportation: ";
cout<<g.transport<<endl;
cout << "Food: ";
cout<<g.food<<endl;
cout << "Medical: ";
cout<<g.medical<<endl;
cout << "Insurance: ";
cout<<g.insurance<<endl;
cout << "Entertainment: ";
cout<<g.entertainment<<endl;
cout << "Clothing: ";
cout<<g.clothing<<endl;
cout << "Miscellaneous: ";
cout<<g.misc<<endl;
int total=g.housing+g.utilities+g.houseHold+g.transport+g.food+g.medical+g.insurance+g.entertainment+g.clothing+g.misc;
cout<<"Total budgeted:"<<total;
}
void printData(const MonthlyExpenses &budget,
const MonthlyExpenses ¤t)
{
double total = 0;
cout << "Housing: ";
cout<<budget.housing<<" "<<current.housing<<" ";
total += getDifference(budget.housing - current.housing);
cout << "\nUtilities: ";
cout<<budget.utilities<<" "<< current.utilities<<" ";
total += getDifference(budget.utilities - current.utilities);
cout << "\nHousehold expenses: ";
cout<<budget.houseHold<<" "<<current.houseHold<<" ";
total += getDifference(budget.houseHold - current.houseHold);
cout << "\nTransportation: ";
cout<<budget.transport<<" "<<current.transport<<" ";
total += getDifference(budget.transport - current.transport);
cout << "\nFood: ";
cout<<budget.food<<" "<<current.food<<" ";
total += getDifference(budget.food - current.food);
cout << "\nMedical: ";
cout<<budget.medical<<" "<<current.medical<<" ";
total += getDifference(budget.medical - current.medical);
cout << "\nInsurance: ";
cout<<budget.insurance<<" "<<current.insurance<<" ";
total += getDifference(budget.insurance - current.insurance);
cout << "\nEntertainment: ";
cout<<budget.entertainment<<" "<<current.entertainment<<" ";
total += getDifference(budget.entertainment - current.entertainment);
cout << "\nClothing: ";
cout<<budget.clothing<<" "<<current.clothing<<" ";
total += getDifference(budget.clothing - current.clothing);
cout << "\nMiscellaneous: ";
cout<<budget.misc<<" "<< current.misc<<" ";
total += getDifference(budget.misc - current.misc);
cout <<"\n\nMonthly: "<<endl;
getDifference(total);
if( getDifference(total)<0)
cout<<"Yes you saved";
else
cout<<"Sorry you exceed";
}
//function getDifference has both a return type,
//so it can be added step by step to an accumulator
//for monthly over or under budget, but it also
//prints the difference appropriately
double getDifference(double diff){
if(diff > 0)
cout << "-$" << diff;
else if(diff < 0)
cout << "+$" << abs(diff);
else
cout << "$" << diff;
return diff;
}
Get Answers For Free
Most questions answered within 1 hours.