128k views
3 votes
C++ only

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

Miscellaneious $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 indicatin the amount over or under in each category, as well as the amount over or under for the entire monthly budget.

1st test case:

input:

500 125 85 40 225.50 0 100 150 75 52.75
expected output:

Enter housing cost for the month:$↵
Enter utilities cost for the month:$↵
Enter household expenses cost for the month:$↵
Enter transportation cost for the month:$↵
Enter food cost for the month:$↵
Enter medical cost for the month:$↵
Enter insurance cost for the month:$↵
Enter entertainment cost for the month:$↵
Enter clothing cost for the month:$↵
Enter miscellaneous cost for the month:$↵
Housing Even↵
Utilities Under↵
Household Expenses Over↵
Transportation Under↵
Food Under↵
Medical Under↵
Insurance Even↵
Entertainment Even↵
Clothing Even↵
Miscellaneous Over↵
You were $66.75 under budget
2nd test case:

your input:

500 175.25 40 40 225.50 0 100 75.85 50 60.70
expected output:

Enter housing cost for the month:$↵
Enter utilities cost for the month:$↵
Enter household expenses cost for the month:$↵
Enter transportation cost for the month:$↵
Enter food cost for the month:$↵
Enter medical cost for the month:$↵
Enter insurance cost for the month:$↵
Enter entertainment cost for the month:$↵
Enter clothing cost for the month:$↵
Enter miscellaneous cost for the month:$↵
Housing Even↵
Utilities Over↵
Household Expenses Under↵
Transportation Under↵
Food Under↵
Medical Under↵
Insurance Even↵
Entertainment Under↵
Clothing Under↵
Miscellaneous Over↵
You were $152.70 under budget

1 Answer

4 votes

Answer:

See explaination fot program code

Step-by-step explanation:

Below is the program code

#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<<"\\\tCategory\t Over/Under\\";

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 << "\\\\You have successfully stayed below your budget under: $" << under << endl;

}

else

{

int over= spent.gross - actual.gross;

cout << "\\\\You 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);

}

User Steven P
by
5.0k points