Question

In: Computer Science

Designing and implementing a C++ structure data type - Monthly Budget Remember to use correct code...

Designing and implementing a C++ structure data type - Monthly Budget

Remember to use correct code formatting and documentation.

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-CompilerHere 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. DO NOT use global variables.

Solutions

Expert Solution

#include<iostream>
#include<iomanip>
using namespace std;
//structure defintion
struct MonthlyBudget
{
string categories[10];
float cost[10];
  
};
float diff[20],d_total=0,b_total=0,s_total=0;
string month;
//function prototypes
void displayBudget(MonthlyBudget);
void getExpenses(MonthlyBudget *);
void compareExpenses(MonthlyBudget,MonthlyBudget);
int main()
{
struct MonthlyBudget budget,spent;
//assigns the value of categories for budget structure variable
budget={{"Housing","Utilities","Household Expenses","Transportation","Food","Medical","Insurance","Entertainment","Clothing","Miscellaneous" },{580,150,65,50,250,30,100,150,75,50}};
displayBudget(budget);
//assigns same values to spent structure variable's categories member
for(int i=0;i<10;i++)
{
spent.categories[i]=budget.categories[i];
}
cout<<"Enter the month of expenditure : ";
cin>>month;
//function call by reference so that updations at the function will reflect in the spent structure varible
getExpenses(&spent);
//function call by value
compareExpenses(budget,spent);
return 0;
}
void displayBudget(MonthlyBudget p)
{
cout<<left<<setw(50)<<"Budget Categories"<<"Budgeted Amount";
cout<<"\n===================================================================\n";
for(int i=0;i<10;i++)
{
b_total=b_total+p.cost[i];
cout<<left<<setw(50)<<p.categories[i]<<"$"<<p.cost[i]<<"\n";
}
cout<<"\n===================================================================\n";
cout<<left<<setw(50)<<"Total Budgeted"<<"$"<<b_total;
cout<<"\n===================================================================\n";
}
void getExpenses(MonthlyBudget *p)
{
cout<<"Enter actual monthly expenditures for each budget category\n";
int i=0;
while(i<10)
{
cout<<left<<setw(50)<<p->categories[i];
cout<<"$";
cin>>p->cost[i];
if(p->cost[i]<0)
{
cout<<"ERROR:You must enter a positive number.\n";
}
else
{
i++;
}
}
}
void compareExpenses(MonthlyBudget budget,MonthlyBudget spent)
{
cout<<left<<setw(25)<<"Categories"<<left<<setw(25)<<"Budgeted"<<left<<setw(25)<<"Spent"<<"Difference";
cout<<"\n=========================================================================================\n";
for(int i=0;i<10;i++)
{
diff[i]=(budget.cost[i]-spent.cost[i]);
d_total=d_total+diff[i];
s_total=s_total+spent.cost[i];
cout<<left<<setw(25)<<budget.categories[i]<<left<<setw(25)<<budget.cost[i]<<left<<setw(25)<<spent.cost[i]<<diff[i]<<"\n";
}
cout<<"============================================================================================\n";
cout<<left<<setw(25)<<"Total"<<left<<setw(25)<<b_total<<left<<setw(25)<<s_total<<d_total;
cout<<"\n============================================================================================\n";
if(d_total>0)
{
cout<<"Congratulations! You were "<<d_total<<" under budget in "<<month<<" 2020.";
}
else if(d_total<0)
{
cout<<"Ooopss ! You were "<<-1*d_total<<" over budget in "<<month<<" 2020." ;
}
else
{
cout<<"Not bad ! You have balanced budget in "<<month<<" 2020." ;
}
}

OUTPUT

Budget Categories Budgeted Amount
===================================================================
Housing $580
Utilities $150
Household Expenses $65
Transportation $50
Food $250
Medical $30
Insurance $100
Entertainment $150
Clothing $75
Miscellaneous $50

===================================================================
Total Budgeted $1500
===================================================================
Enter the month of expenditure : March
Enter actual monthly expenditures for each budget category
Housing $580
Utilities $130
Household Expenses $50
Transportation $50
Food $230
Medical $30
Insurance $12 00
Entertainment $120
Clothing $-10
ERROR:You must enter a positive number.
Clothing $100
Miscellaneous $30
Categories Budgeted Spent Difference
=========================================================================================
Housing 580 580 0
Utilities 150 130 20
Household Expenses 65 50 15
Transportation 50 50 0
Food 250 230 20
Medical 30 30 0
Insurance 100 100 0
Entertainment 150 120 30
Clothing 75 100 -25
Miscellaneous 50 30 20
============================================================================================
Total 1500 1420 80
============================================================================================
Congratulations! You were 80 under budget in March 2020.


Related Solutions

C++: Write correct C++ code for a nested if-else if-else structure that will output a message...
C++: Write correct C++ code for a nested if-else if-else structure that will output a message based on the logic below. A buyer can pay immediately or be billed. If paid immediately, then display "a 5% discount is applied." If billed, then display "a 2% discount is applied" if it is paid in 30 days. If between 30 and 60 days, display "there is no discount." If over 60 days, then display "a 3% surcharge is added to the bill."...
Write a program that uses a structure to store the following data: (Remember to use proper...
Write a program that uses a structure to store the following data: (Remember to use proper formatting and code documentation) Member Name Description name student name idnum Student ID number Scores [NUM_TESTS] an array of test scores Average Average test score Grade Course grade Declare a global const directly above the struct declaration const int NUM_TESTS = 4; //a global constant The program should ask the user how many students there are and should then dynamically allocate an array of...
Java code for creating an Inventory Management System of any company - designing the data structure(stack,...
Java code for creating an Inventory Management System of any company - designing the data structure(stack, queue, list, sort list, array, array list or linked list) (be flexible for future company growth Java code for creating an initial list in a structure. Use Array (or ArrayList) or Linkedlist structure whichever you are confident to use. - Implement Stack, Queue, List type structure and proper operation for your application. Do not use any database. All data must use your data structures....
In this programming project, you will be implementing the data structure min-heap. You should use the...
In this programming project, you will be implementing the data structure min-heap. You should use the C++ programming language, not any other programming language. Also, your program should be based on the g++ compiler on general.asu.edu. All programs will be compiled and graded on general.asu.edu, a Linux based machine. If you program does not work on that machine, you will receive no credit for this assignment. You will need to submit it electronically at the blackboard, in one zip file,...
C++ PROGRAM Code a generic (with templates) Queue structure (linear Data structure with FIFO functionality) and...
C++ PROGRAM Code a generic (with templates) Queue structure (linear Data structure with FIFO functionality) and create a test to validate its functionality. The data consists of persons with the attributes of name, last name, age, height and weight. - Remembrer that, Their structure consists of: Head: Pointer to the first element of the queue Tail: Pointer to the last element of the queue And the following operations: Pop: Removes the element at the head Top: Returns the current element...
Give the algorithms in pseudo code of the enqueue and dequeue procedures. Constraint: the structure implementing...
Give the algorithms in pseudo code of the enqueue and dequeue procedures. Constraint: the structure implementing the queue must only be pointed to by a single field (example: head, tail or number of elements, etc.)
C++ CODE PLEASE MAKE SURE TO USE STRINGSTREAM AND THAT THE OUTPUT NUMBER ARE CORRECT 1....
C++ CODE PLEASE MAKE SURE TO USE STRINGSTREAM AND THAT THE OUTPUT NUMBER ARE CORRECT 1. You must call all of the defined functions above in your code. You may not change function names, parameters, or return types. 2. You must use a switch statement to check the user's menu option choice. 3. You may create additional functions in addition to the required functions listed above if you would like. 4. If user provides option which is not a choice...
1. What is the structure data type in C? 2. What is the value ranges of...
1. What is the structure data type in C? 2. What is the value ranges of data type of unsigned char, unsigned short, respectively? 3. How many regular resisters are in this X-CPU? 4. How does the X-CPU access the memory? 5. What is the maximum memory address? 6. Which statements in the code is to increase the PC value? 7. What is the minimal cycle number that is just needed to print “Hello world!” 4 times? 8. what is...
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches....
(MUST BE DONE IN C (NOT C++)) For this program, remember to use feet and inches. First, ask the user for the name of students they have in their class. Then, using a loop, you will ask for each student’s height. However, you will have to use two separate variables, one for feet and one for inches. Then, you will have to call two functions. The first function will check if the values entered are valid (check if number of...
What type of budget is best to use when configuring productivity data to get actual data?
What type of budget is best to use when configuring productivity data to get actual data?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT