Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- For project two you are to write a program that uses structs. Your program will prompt for and read in the amount spent on various living expenses for a student who must maintain a strict budget. The 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
- These values are to be defined by constant identifiers in your program. The program keeps the monthly budget for each category in a struct designed to hold each of the expense categories. The program is to use a function that references back the struct created when the user is asked to enter the amount spent in each budget category during the month. The program is to then pass this struct to a function that displays a report indicating the amount over or under in each category in a tabular format, as well as the amount over or under for the entire monthly budget. The results are sent to both the screen and to an external text file.
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- using namespace std;
- struct Budget //declare a global type
- {
- double housing;
- double utilities;
- double household_exp;
- double transportation;
- double food;
- double medical;
- double insurance;
- double entertainment;
- double clothing;
- double misc;
- };
- int main()
- {
- void describe_program();
- Budget set_budget();
- Budget get_spent();
- Budget calculate_spent();
- void output();
- describe_program();
- set_budget();
- get_spent();
- calculate_spent();
- output();
- system("PAUSE");
- return 0;
- }
- void describe_program() //describes program
- {
- cout<<"This program will prompt you for how much you have spent on areas "
- "in which you\nhave spent money in accordance to a budget. After it"
- " has collected this\ninformation it will calculate how much over or "
- "under budget you are.\n\n";
- return;
- }
- Budget set_budget()
- {
- Budget set = {500.00, 150.00, 65.00, 50.00, 250.00, 30.00, 100.00,
- 150.00, 75.00, 50.00};
- return(set);
- }
- Budget get_spent() //returns a budget spent structure
- {
- Budget spent;
- cout<<"Enter in Housing Expense:";
- cin>>spent.housing;
- cout<<"Enter in Utilities Expense:";
- cin>>spent.utilities;
- cout<<"Enter in Household Expenses:";
- cin>>spent.household_exp;
- cout<<"Enter in Transportation Expense:";
- cin>>spent.transportation;
- cout<<"Enter in Food Expense:";
- cin>>spent.food;
- cout<<"Enter in Medical Expense:";
- cin>>spent.medical;
- cout<<"Enter in Insurance Expense:";
- cin>>spent.insurance;
- cout<<"Enter in Entertainment Expense:";
- cin>>spent.entertainment;
- cout<<"Enter in Clothing Expense:";
- cin>>spent.clothing;
- cout<<"Enter in Miscellaneous Expenses:";
- cin>>spent.misc;
- return(spent);
- }
- Budget calculate_spent()
- {
- Budget total;
- Budget spent;
- Budget fixed;
- Budget set_budget();
- Budget get_spent();
- fixed = set_budget();
- spent = get_spent();
- total.housing = (fixed.housing - spent.housing);
- total.utilities = (fixed.utilities - spent.utilities);
- total.household_exp = (fixed.household_exp - spent.household_exp);
- total.transportation = (fixed.transportation - spent.transportation);
- total.food = (fixed.food - spent.food);
- total.medical = (fixed.medical - spent.medical);
- total.insurance = (fixed.insurance - spent.insurance);
- total.entertainment = (fixed.entertainment - spent.entertainment);
- total.clothing = (fixed.clothing - spent.clothing);
- total.misc = (fixed.misc - spent.misc);
- return(total);
- }
- void output()
- {
- Budget fixed;
- Budget set_budget();
- fixed = set_budget();
- Budget spent;
- Budget get_spent();
- spent = get_spent();
- Budget total;
- Budget calculate_spent();
- total = calculate_spent();
- cout<<"Category\t\t"<<"Budgeted\t"<<"Spent\t"<<"Over(-)/Under\n"
- "------------------------------------------------------------\n"
- "Housing\t\t"<<fixed.housing<<"\t"<<spent.housing<<"\t\t";
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment