A student has established the following monthly budget: Housing 500.00 Utilities
ID: 3539134 • Letter: A
Question
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 modular program that declares a MonthlyBudget structure with member variables to hold each of these expense categories. The program should create two MonthlyBudget structure variables. The %uFB01rst will hold the budget %uFB01gures given above. The second will hold the user-enter amounts actually spent during the past month. Using Program 7-19 as a model, the program 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 amount actually spent in that category. Once the user data has all been entered, the program should
compute and display the amount over or under budget the student%u2019s expenditures were in each category, as well as the amount over or under budget for the entire month.
The Program 7-19 to be used as a model is the following:
1 // This program creates a screen form for user input.
2 // from the user.
3 #include <iostream>
4 #include <windows.h> // Needed to set cursor positions
5 #include <string>
6 using namespace std;
7
8 struct UserInfo
9 { string name;
10 int age;
11 char gender;
12 };
13
14 void placeCursor(HANDLE, int, int); // Function prototypes
15 void displayPrompts(HANDLE);
16 void getUserInput(HANDLE, userInfo&);
17 void displayData (HANDLE, userInfo);
18
19 int main()
20 {
21 userInfo input; // input is a UserInfo structure
22 // that has 3 member variables
23
24 // Get the handle to standard output device (the console)
25 HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
26
27 displayPrompts(screen);
28 getUserInput(screen, input);
29 displayData (screen, input);
30
31 return 0;
32 }
33
34 /******************************************************
35 * placeCursor *
36 ******************************************************/
37 void placeCursor(HANDLE screen, int row, int col)
38 { // COORD is a defined C++ structure that
39 COORD position; // holds a pair of X and Y coordinates
40 position.Y = row;
41 position.X = col;
42 SetConsoleCursorPosition(screen, position);
43 }
44
45 /******************************************************
46 * displayPrompts *
47 ******************************************************/
48 void displayPrompts(HANDLE screen)
49 {
50 placeCursor(screen, 3, 25);
51 cout << "******* Data Entry Form *******" << endl;
52 placeCursor(screen, 5, 25);
53 cout << "Name: " << endl;
54 placeCursor(screen, 7, 25);
55 cout << "Age: Gender (M/F): " << endl;
56 }
57
58 /******************************************************
59 * getUserInput *
60 ******************************************************/
61 void getUserInput(HANDLE screen, userInfo &input)
62 {
63 placeCursor(screen, 5, 31);
64 getline(cin, input.name);
65 placeCursor(screen, 7, 30);
66 cin >> input.age;
67 placeCursor(screen, 7, 55);
68 cin >> input.gender;
69 }
70
71 /******************************************************
72 * displayData *
73 ******************************************************/
74 void displayData(HANDLE screen, userInfo input)
75 {
76 placeCursor(screen, 10, 0);
77 cout << "Here is the data you entered. ";
78 cout << "Name : " << input.name << endl;
79 cout << "Age : " << input.age << endl;
80 cout << "Gender: " << input.gender << endl;
81 }
Explanation / Answer
#include<stdio.h>
int main()
{
float rent,food,util,other;
printf("enter expenditure on rent:-");
scanf("%f",&rent);
printf("enter expenditure on food:-");
scanf("%f",&food);
printf("enter expenditure on utilities:-");
scanf("%f",&util);
printf("enter expenditure on other:-");
scanf("%f",&other);
float sum,avg,p1,p2,p3,p4;
sum=rent+food+util+other;
printf("total :- %5.2f",sum);
p1=rent*100/sum;
printf("percentage of rent :- %5.1f ",p1);
p2=food*100/sum;
printf("percentage of food :- %5.1f ",p2);
p3=util*100/sum;
printf("percentage of utilities :- %5.1f ",p3);
p4=other*100/sum;
printf("percentage of other :- %5.1f ",p4);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.