-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.cpp
486 lines (467 loc) · 12.6 KB
/
menu.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
#include<iostream>
#include<cstring>
#include<fstream>
#include<cstdlib>
using namespace std;
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void menu();
class person
{
int p_id;
char fname[20], mname[20], lname[20];
int age_ason_1Jan2000;
char disability;
char gender;
public:
void enter_infilep()
{
person p;
ofstream ofs("people.txt", ios :: app);
ofs<<p_id<<'\t'<<fname<<'\t'<<mname<<'\t'<<lname<<'\t'<<age_ason_1Jan2000<<'\t'<<disability<<'\t'<<gender<<'\n';
ofs.close();
}
void enter_newp()
{
char c;
do
{
cout<<"Enter p_id:\n";
cin>>p_id;
cout<<"Enter name: <fname mname lname>\n";
cin>>fname>>mname>>lname;
cout<<"Enter age as on 1st January 2000\n";
cin>>age_ason_1Jan2000;
cout<<"Enter disability status:('n'->no;'s'->severe;)\n";
cin>>disability;
cout<<"Enter gender:('m'->male; 'f'->female)\n";
cin>>gender;
cout<<"Please enter the following information. Once entered, it cannot be updated.\n\n";
displayp();
cout<<"Is the above information correct?(y/n):\t";
cin>>c;
}while(c=='n');
enter_infilep();
}
void displayp()
{
cout<<"ID:\t"<<p_id<<endl
<<"First Name:\t"<<fname<<endl
<<"Middle Name:\t"<<mname<<endl
<<"Last Name:\t"<<lname<<endl
<<"Age as on 1 January 2000:\t"<<age_ason_1Jan2000<<endl
<<"Disability Status:('n'-> no; 's'->severe;)\t"<<disability<<endl
<<"Gender:('m'->male; 'f'->female)\t"<<gender<<endl;
}
friend void cal_tax();
friend person getp(int d);
};
person getp(int d)
{
person p;
ifstream ifs("people.txt");
int i=0;
try
{
do
{
i++;
ifs>>p.p_id>>p.fname>>p.mname>>p.lname>>p.age_ason_1Jan2000>>p.disability>>p.gender;
if(i>99)
{
cout<<"Wrong p_id :(\n";
throw 0;
}
}while(p.p_id != d);
}
catch(int a)
{
ifs.close();
throw 0;
}
ifs.close();
return p;
}
class rules
{
int fin_yr;
float dedAm, dedBm;
float dedCgm, dedCm; //deduction for girlies
float dedDsm, dedDm; //deduction for seniors
float dedEhm, dedEm; //deduction for handicapped
float b1, r1, b2, r2, b3, r3;
public:
void enter_infiler()
{
rules r;
ofstream ofs("rules.txt", ios :: app);
ofs<<fin_yr<<'\t'<<dedAm<<'\t'<<dedBm<<'\t'<<dedCgm<<'\t'<<dedCm<<'\t'<<dedDsm<<'\t'<<dedDm<<'\t'<<dedEhm<<'\t'<<dedEm<<'\t'<<b1<<'\t'<<r1<<'\t'<<b2<<'\t'<<r2<<'\t'<<b3<<'\t'<<r3<<'\n';
ofs.close();
}
void enter_newr()
{
char c;
do
{
cout<<"Enter financial year:\n";
cin>>fin_yr;
cout<<"Enter max deduction of type A and type B, respectively:\n";
cin>>dedAm>>dedBm;
cout<<"Enter maximum deduction of type C for women and men, respectively\n";
cin>>dedCgm>>dedCm;
cout<<"Enter maximum dedution of type D for senior citizens and normal people, respectively\n";
cin>>dedDsm>>dedDm;
cout<<"Enter maximum dedution of type E for disabled and healthy citizens, respectively\n";
cin>>dedEhm>>dedEm;
cout<<"Enter the brackets from and their rates respectively(all at once)<b1 r1 b2 r2 b3 r3>\n";
cin>>b1>>r1>>b2>>r2>>b3>>r3;
cout<<"Please enter the following information. Once entered, it cannot be updated.\n\n";
displayr();
cout<<"Is the above information correct?(y/n):\t";
cin>>c;
}while(c=='n');
enter_infiler();
}
void displayr()
{
cout<<"financial year:\t"<<fin_yr<<endl
<<"dedAm:\t"<<dedAm<<endl
<<"dedBm:\t"<<dedBm<<endl
<<"dedCgm:\t"<<dedCgm<<endl
<<"dedCm:\t"<<dedCm<<endl
<<"dedDsm:\t"<<dedDsm<<endl
<<"dedDm:\t"<<dedDm<<endl
<<"dedEhm:\t"<<dedEhm<<endl
<<"dedEm:\t"<<dedEm<<endl
<<"b1 r1:\t"<<b1<<'\t'<<r1<<endl
<<"b2 r2:\t"<<b2<<'\t'<<r2<<endl
<<"b3 r3:\t"<<b3<<'\t'<<r3<<endl;
}
friend rules getr(int d);
friend void cal_tax();
};
rules getr(int d)
{
rules r;
ifstream ifs("rules.txt");
int i=0;
try
{
do
{
i++;
ifs>>r.fin_yr>>r.dedAm>>r.dedBm>>r.dedCgm>>r.dedCm>>r.dedDsm>>r.dedDm>>r.dedEhm>>r.dedEm>>r.b1>>r.r1>>r.b2>>r.r2>>r.b3>>r.r3;
if(i>99)
{
cout<<"No entries for this year yet :(\n";
throw 0;
}
}while(r.fin_yr != d);
}
catch(int a)
{
ifs.close();
throw 0;
}
ifs.close();
return r;
}
int verify()
{
int i=0,k=0;
char pw[20], check[20], ch, c;
ifstream ifs("password.txt");
while(ifs.get(c))
pw[k++]=c;
pw[k]='\0';
ifs.close();
cout<<"Enter Password:\t";
do
{
ch=getch();
check[i++]=ch;
cout<<'*';
}while(ch!='\t');
check[i]='\0';
system("cls");
if(!strcmp(pw, check))
return 1;
return 0;
}
void new_pw()
{
int i=0;
char a[50], b[50], ch;
cout<<"Enter new Password:\t";
do
{
ch=getch();
a[i++]=ch;
cout<<'*';
}while(ch!='\t');
a[i]='\0';
cout<<"Re-nter new Password:\t";
i=0;
do
{
ch=getch();
b[i++]=ch;
cout<<'*';
}while(ch!='\t');
b[i]='\0';
if(!strcmp(a,b))
{
ofstream ofs("password.txt");
ofs<<a;
ofs.close();
cout<<"\nNew password set!\n";
}
system("cls");
}
void cal_tax()
{
person p;
rules r;
int fy, id;
pid:
cout<<"Enter p_id:\n";
cin>>id;
try
{
p=getp(id);
}
catch(int n)
{
cout<<"No person with such id\nTry enter a person first.(Enter 'm' to goto main menu;'t' to try again)\n";
char ch;
cin>>ch;
switch(ch)
{
case 'm':
menu();
break;
case 't':
goto pid;
break;
default:
menu();
}
}
finyr:
cout<<"Enter fin_yr:\n";
cin>>fy;
try
{
r=getr(fy);
}
catch(int n)
{
cout<<"The rules for this financial year have not been defined yet\nRequest your administrator to enter the rules first.(Enter 'm' to goto main menu;'t' to try again)\n";
char ch;
cin>>ch;
switch(ch)
{
case 'm':
menu();
break;
case 't':
goto finyr;
break;
default:
menu();
}
}
float tot_income, tds, taxable_income, tax=0, tax_payable;
float dedAc, dedBc, dedCc, dedDc, dedEc;
float ltg, stg;
cout<<"You are about to calculate the tax for:\n\n";
p.displayp();
cout<<"\n\nUnder the following rules:\n\n";
r.displayr();
cout<<"\n\nEnter (y/n) to continue:\t";
char ch;
ch=getch();
if(ch!='y')
goto pid;
system("cls");
cout<<"Enter the total income(excluding equity gains):\n";
cin>>tot_income;
cout<<"Enter LTG:\n";
cin>>ltg;
cout<<"Enter STG:\n";
cin>>stg;
cout<<"Enter tds (if any):\n";
cin>>tds;
cout<<"Enter deductions claimed of type A, B, C, D and E(respectively):\n";
cin>>dedAc>>dedBc>>dedCc>>dedDc>>dedEc;
dedAc=dedAc>r.dedAm?r.dedAm:dedAc;
dedBc=dedBc>r.dedBm?r.dedBm:dedBc;
if(p.gender=='f')
dedCc=dedCc>r.dedCgm?r.dedCgm:dedCc;
else
dedCc=dedCc>r.dedCm?r.dedCm:dedCc;
if(p.age_ason_1Jan2000+r.fin_yr-2000>60)
dedDc=dedDc>r.dedDsm?r.dedDsm:dedDc;
else
dedDc=dedDc>r.dedDm?r.dedDm:dedDc;
if(p.disability=='s')
dedEc=dedEc>r.dedEhm?r.dedEhm:dedEc;
else
dedEc=dedEc>r.dedEm?r.dedEm:dedEc;
tot_income +=stg;
taxable_income = tot_income - (dedAc+dedBc+dedCc+dedDc+dedEc);
if(taxable_income<r.b1)
tax=0;
else if(taxable_income <r.b2)
tax+=(taxable_income-r.b1)*r.r1/100;
else if(taxable_income <r.b3)
{
tax+=(r.b2-r.b1)*r.r1/100;
tax+=(taxable_income-r.b2)*r.r2/100;
}
else
{
tax+=(r.b2-r.b1)*r.r1/100;
tax+=(r.b3-r.b2)*r.r2/100;
tax+=(taxable_income-r.b3)*r.r3/100;
}
tax_payable = tax-tds;
if(tax_payable < 0)
tax_payable =0;
system("cls");
cout<<"Transaction details:\n\n";
cout<<"p_id:\t"<<p.p_id<<endl
<<"fincial year:\t"<<r.fin_yr<<endl
<<"STG:\t"<<stg<<endl
<<"LTG:\t"<<ltg<<endl
<<"Income Declared:\t"<<tot_income<<endl
<<"TDS paid:\t"<<tds<<endl
<<"deduction A:\t"<<dedAc<<endl
<<"deduction B:\t"<<dedBc<<endl
<<"deduction C:\t"<<dedCc<<endl
<<"deduction D:\t"<<dedDc<<endl
<<"deduction E:\t"<<dedEc<<endl
<<"taxable income:\t"<<taxable_income<<endl
<<"Tax:\t"<<tax<<endl
<<"tax payable:\t"<<tax_payable<<endl;
ofstream ofs("taxlogs.txt", ios::app);
ofs<<p.p_id<<'\t'<<r.fin_yr<<'\t'<<tot_income<<'\t'<<tds<<'\t'<<taxable_income<<'\t'<<tax<<'\t'<<dedAc<<'\t'<<dedBc<<'\t'<<dedCc<<'\t'<<dedDc<<'\t'<<dedEc<<'\t'<<taxable_income<<'\t'<<tax<<'\t'<<tax_payable<<endl;
ofs.close();
}
void menu()
{
menu:
system("cls");
cout<<"\t\t\t=====MENU=====\n"
<<"\t\t\t1. Enter new person\n"
<<"\t\t\t2. Enter rules for a new year(admin)\n"
<<"\t\t\t3. Calculate taxes\n"
<<"\t\t\t4. Change Administrator password(admin)\n"
<<"\t\t\t5. Display all people(admin)\n"
<<"\t\t\t6. Display all rules\n"
<<"\t\t\t7. Display tax details(admin)\n"
<<"\t\t\t8. Exit\n";
int a,i;
a=getch()-48;
system("cls");
switch(a)
{
case 1:
person p;
p.enter_newp();
cout<<"\n\n\nPress any key to got to menu\n";
getch();
goto menu;
break;
case 2:
i=verify();
if(i==1)
{
rules r;
r.enter_newr();
cout<<"\n\n\nPress any key to got to menu\n";
getch();
goto menu;
}
else
goto menu;
break;
case 3:
cal_tax();
cout<<"\n\n\nPress any key to got to menu\n";
getch();
goto menu;
break;
case 4:
if(verify())
new_pw();
getch();
goto menu;
break;
case 5:
if(verify())
{
system("cls");
cout<<"p_id\tfname\tmname\t\tlname\tAgeIn2k disab sex\n\n";
char c;
ifstream ifs("people.txt");
while(ifs.get(c))
cout<<c;
ifs.close();
cout<<"\n\n\nPress any key to got to menu\n";
getch();
goto menu;
}
else
goto menu;
break;
case 6:
if(1)
{
system("cls");
cout<<"fin_yr dedAm dedBm dedCgm dedCm dedDsm dedDm dedDhm dedHm b1\tr1\tb2\tr2\tb3\tr3\n\n";
char c;
ifstream ifs("rules.txt");
while(ifs.get(c))
cout<<c;
ifs.close();
cout<<"\n\n\nPress any key to got to menu\n";
getch();
goto menu;
}
else
goto menu;
break;
case 7:
if(verify())
{
system("cls");
cout<<"\nP_ID\tfin_yr\tTotalIncome\tTDS\tdedA\tdedB\tdedC\tdedD\tdedE\ttaxable_income\tTax\tTax_payable\n\n";
ifstream ifs("taxlogs.txt");
char c;
while(ifs.get(c))
cout<<c;
ifs.close();
cout<<"\n\n\nPress any key to got to menu\n";
getch();
goto menu;
}
else
goto menu;
break;
case 8:
exit(0);
default:
cout<<"Incorrect choice\n";
goto menu;
}
}
main()
{
cout<<"Hello!\n\n\tThis program is made to help in Income Tax Management!\n\nPress any key for Main Menu!";
getch();
menu:
system("cls");
menu();
}