-
Notifications
You must be signed in to change notification settings - Fork 3
/
BUDGET(rohan).CPP
207 lines (200 loc) · 4.64 KB
/
BUDGET(rohan).CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
class BUDGET
{
int BudForEducation;
int BudForHealth;
int BudForTransport;
int BudForElectricity;
int BudForWater;
public:
void GetData2();
void PutData2();
int GetBudget();
int getAverageBud();
};
void BUDGET:: GetData2()
{
cout<<"enter budget for education";
cin>>BudForEducation;
cout<<"enter budget for health";
cin>>BudForHealth;
cout<<"enter budget for transport";
cin>>BudForTransport;
cout<<"enter budget for electricity";
cin>>BudForElectricity;
cout<<"enter budget for water";
cin>>BudForWater;
}
void BUDGET:: PutData2()
{
cout<<BudForEducation<<"\t"<<BudForHealth<<"\t"<<BudForTransport<<"\t"<<BudForElectricity<<"\t"<<BudForWater<<"\t"<<endl;
}
int BUDGET:: getAverageBud()
{
int AverageBudget;
AverageBudget=(BudForEducation+BudForHealth+BudForTransport+BudForElectricity+BudForWater)/5;
cout<<"average budget="<<AverageBudget;
return(AverageBudget);
}
int BUDGET:: GetBudget()
if (c==BudforEducation)
{
cout<<"budget for education";
return(BudForEducation);
}
else if(c==BudForHealth)
{
cout<<"budget for health";
return(BudForHealth);
}
else if(c==BudForTransport)
{
cout<<"budget for transport";
return(BudForTransport);
}
else if(c==BudForElectricity)
{
cout<<"budget for electricity";
return(BudForElectricity);
}
else
{
cout<<"budget for water";
return(BudForWater);
}
}
BUDGET B;
void main()
{
clrscr();
void enterbudget();
void calculatebudget();
void displaybudget();
void searchbudget();
void modifybudget();
void deletebudget();
int c;
do
{
cout<<"\n main menu "<<endl;
cout<<"1. enter the value of all budgets"<<endl;
cout<<"2. calculate average budget "<<endl;
cout<<"3. display all budgets "<<endl;
cout<<"4. search a budget value "<<endl;
cout<<"5. modify a value of budget "<<endl;
cout<<"6. delete a budget value "<<endl;
cout<<"7.exit "<<endl;
cout<<"enter your choice"<<" ";
cin>>c;
switch(c)
{
case 1: enterbudget();
break;
case 2: calculatebudget();
break;
case 3: displaybudget();
break;
case 4: searchbudget();
break;
case 5: modifybudget();
break;
case 6: deletebudget();
break;
}
}while(c!=7);
getche();
}
void enterbudget()
{
ofstream afile("pro.dat",ios::binary|ios::app);
B.GetData2();
afile.write((char*)& B, sizeof(B));
afile.close();
cout<<endl;
getche();
}
void calculatebudget()
{
ifstream gfile("pro.dat",ios::binary);
while(gfile.read((char*)& B, sizeof(B)))
{
B.getAverageBud();
}
gfile.close();
}
void displaybudget()
{
ifstream bfile("pro.dat",ios::binary);
while(bfile.read((char*)& B, sizeof(B)))
{
B.PutData2();
}
bfile.close();
cout<<endl;
getche();
}
void searchbudget()
{
int p=-1,z;
ifstream cfile("pro.dat",ios::binary);
cout<<"please enter budget to be searched:\n";
cin>>z;
while(cfile.read((char*)& B,sizeof(B)))
{
if(B.GetBudget()==z)
{
cout<<"budget";
p++;
}
}
if(p==-1)
cout<<"sorry!record not found\n";
cout<<endl;
cfile.close();
getche();
}
void modifybudget()
{
int g=-1,a=0,t;
cout<<"please enter the budget to be modified:\n";
cin>>t;
fstream dfile("pro.dat",ios::in|ios::binary|ios::out );
while(dfile.read((char*)& B,sizeof(B)))
{
a++;
if(B.GetBudget()==t)
{
B.GetData2();
dfile.seekp((a-1)*sizeof(B),ios::beg);
dfile.write((char*)& B, sizeof(B));
g++;
}
}
if(g==-1)
cout<<"sorry record not found\n";
dfile.close();
getche();
}
void deletebudget()
{
int b;
ifstream efile("pro.dat",ios::binary);
ofstream ffile("Pro.dat",ios::binary);
cout<<"please enter the budget to be deleted\n";
cin>>b;
while(efile.read((char*)& B,sizeof(B)))
{
if(B.GetBudget()!=b)
{
ffile.write((char*)& B,sizeof(B));
}
}
remove("pro.dat");
rename("Pro.dat","pro.dat");
efile.close();
ffile.close();
cout<<endl;
getche();
}