In: Computer Science
C++
11.11: Customer Accounts A student has established the following monthly budget: 500.00 Housing 150.00 Utilities 65.00 Household 50.00 Expenses 50.00 Transportation 250.00 Food 30.00 Medical 100.00 Insurance 150.00 Entertainment 75.00 Clothing 50.00 Miscellaneous 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. NOTES: For each of the categories listed above, and in that order, the program prompts the user for the the amount spent on X: where X is a category from the above list (e.g. "Insurance"). Using the values read into the structure, the program generates a table with a heading and in each row there are four items: the category (e.g. "Housing"), followed by the value budgeted for the category (500.00 in the case of Housing), followed by the value that had been read in for that category, followed by the amount that the actual spent was over or under the category budget. Finally, after the table, is an indication of whether the student is over or under budget.
make sure it works with codelab
#include <iostream>
#include <cstring>
#include <string>
#include<bits/stdc++.h>
using namespace std;
//function prototypes
void input( struct MonthlyBudget rec[]);
void printRecord( struct MonthlyBudget r[]);
//structure named player
struct MonthlyBudget
{
float amount;
} ;
int main()
{
//structure array with 12 size
struct MonthlyBudget sarr[10];
//function call to gather information from user
input(sarr);
system("pause"); //console visible purpose
return 0;
}
//function implementation-gathering information from user
void input(struct MonthlyBudget record[])
{
char category[10][20] = {"Housing", "Utilities", "Household", "Expenses","Transportation","Food",
"Medical","Insurance","Entertainment","Clothing"};
int i=0;
//loop to read inputs
for(i=0;i<10;i++)
{
cout<<"\nThe amount spent on "<<category[i]<<":";
cin>>record[i].amount;
//to ignore space in the name
cin.ignore(256, '\n');
//fflush(stdin);
}
//calling the function to print the student records
printRecord(record);
}
//implementing the function to dispplay the player information
void printRecord( struct MonthlyBudget record[])
{
char category[10][20] = {"Housing", "Utilities", "Household", "Expenses","Transportation","Food",
"Medical","Insurance","Entertainment","Clothing"};
float budget[10]={500,150,65,50,50,250,30,100,150,75};
int i;
cout<<"-----------------------------------------------------------------";
//For calculation purpose
int total=0;
string name;
cout<<"\n";
//loop to display the records present in structure
for(i=0;i<10;i++)
{
cout<<category[i]<<"\t";
cout<<record[i].amount<<"\t";
cout<<budget[i]<<"\t";
cout<<budget[i]-record[i].amount<<"\n";
}
//displyaing ouput
cout<<"\n";
}
OUTPUT:
THUMBS UP IF YOU LIKE IT !