CONVERTING STRUCTURES TO CLASS

I had this question for class:

A student has established the following monthly budget:
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 has a MonthlyBudget structure designed to hold each of these expense categories. The program should pass the structure to a function that asks the user to enter the amounts spent in each budget category during a month. The program should then pass the structure to a function that displays a report indicating the amount over or under in each category, as well as the amount over or under for the entire monthly budget.

SO I wrote the program at the bottom, but now I have this question based off of the other, and I'm having trouble with this question, so any help is appreciated:

Convert the structure in PROG5a to a class MonthlyBudget with two functions:
First function that asks the user to enter the amounts spent in each budget category during a month and the second function that displays a report indicating the amount over or under in each category, as well as the amount over or under for the entire monthly budget. Also, implement the class in a program.


THIS IS THE PROGRAM FOR PART ONE:
#include <iostream>
#include <iomanip>
using namespace std;
struct MonthlyBudget {
int house;
int util;
int he;
int trans;
int food;
int med;
int ins;
int ent;
int cloth;
int misc;
int gross;
};
void getSpentBudget(MonthlyBudget &spent)
{
cout << "Enter amount for housing: ";
cin >> spent.house;
cout << "Enter amount for utilities: ";
cin >> spent.util;
cout << "Enter amount for household expenses: ";
cin >> spent.he;
cout << "Enter amount for transportation: ";
cin >> spent.trans;
cout << "Enter amount for food: ";
cin >> spent.food;
cout << "Enter amount for medical: ";
cin >> spent.med;
cout << "Enter amount for insurance: ";
cin >> spent.ins;
cout << "Enter amount for entertainment: ";
cin >> spent.ent;
cout << "Enter amount for clothing: ";
cin >> spent.cloth;
cout << "Enter amount for miscellaneous: ";
cin >> spent.misc;
}
void reportBudget(MonthlyBudget spent, MonthlyBudget actual)
{
//Calculate the student's expenditures for the month
spent.gross = spent.house + spent.util + spent.he + spent.trans + spent.food + spent.med + spent.ins
+ spent.ent + spent.cloth + spent.misc;
cout<<"\n\tCategory\t Over/Under\n";
cout<<setw(20)<<"Housing" <<setw(8)<< actual.house - spent.house <<endl;
cout<<setw(20)<<"Uitlities" <<setw(8)<< actual.util - spent.util <<endl;
cout<<setw(20)<<"Household Expenses"<<setw(8) << actual.he - spent.he <<endl;
cout<<setw(20)<<"Transportation"<<setw(8) << actual.trans - spent.trans <<endl;
cout<<setw(20)<<"Food"<<setw(8) << actual.food - spent.food <<endl;
cout<<setw(20)<<"Medical" <<setw(8)<< actual.med - spent.med <<endl;
cout<<setw(20)<<"Insurance"<<setw(8) << actual.ins - spent.ins <<endl;
cout<<setw(20)<<"Entertainment"<<setw(8) << actual.ent - spent.ent <<endl;
cout<<setw(20)<<"Clothing"<<setw(8) << actual.cloth - spent.cloth <<endl;
cout<<setw(20)<<"Miscellaneous"<<setw(8) << actual.misc - spent.misc <<endl;
if (spent.gross <= actual.gross)
{
int under = actual.gross - spent.gross;
cout << "\n\nYou have successfully stayed below your budget under: $" << under << endl;
}
else
{
int over= spent.gross - actual.gross;
cout << "\n\nYou are over your monthly budget by: $ " << over <<endl;
}
}
int main()
{
MonthlyBudget actual;
actual.house = 500;
actual.util = 150;
actual.he =65;
actual.trans = 50;
actual.food = 250;
actual.med = 30;
actual.ins = 100;
actual.ent = 150;
actual.cloth = 75;
actual.misc = 50;
actual.gross = 1420;
MonthlyBudget spent;
getSpentBudget(spent);
reportBudget(spent, actual);
}

Topic archived. No new replies allowed.