LAB 5 CS 109 ProgrammingII Application of Functions Write a

LAB # 5: CS 109 (Programming-II) Application of Functions Write a proram that would compute income tax of an individual by using two different functions: a) Function Netincome that takes grossincome (double), noofChildren (int) and option (char) as input parameters. Then it computes the netincome using the following formulae. First check if option is s or s (single), then stdDeduction 8000.00 noofExemption- 1+ noofChildren else if option is j or joint), then stdDeduction 12000.00 noOfExemption 2+ noofchildren else Display a message that the option is invalid and quit the program (exitío):) dependentDeduction- noOfExemption 2500.00 totalDeduction stdDeduction + dependentDeduction net income grossincome-tota!Deduction return netincome b) A function Tax that computes the tax by using the netincome as parameter The tax is computed as below If netincome is less than 20000, taxe netincome is above 20000 but less than 50000, tax is 10% of netincome ie. tax- 0.1- netincome f netincome is above 50000, but less than 100000, tax -0.15 netincone f it is above 100000, tax- 0.2\"netincome teturn tax c) Main should get three different user input: gross income, nootchildren, and option Then first call the function Netincome and store the value in vaniable netincome. Now call the tunction Tax using netincoms as argument and store the value in vartlable tax. Display the netincome and tax with suitable utle.

Solution

#include<stdio.h>
#include<stdlib.h>
double NetIncome(double grossIncome, int noOfChildren, char option);
double Tax(double netincome);
int main() {
double grossIncome;
int noOfChildren;
char option;
/*User input for grossIncome , noOfChildren and option*/
scanf(\"%lf\", &grossIncome);
scanf(\" %d\", &noOfChildren);
scanf(\" %c\", &option);
double netincome=NetIncome(grossIncome,noOfChildren,option);
double tax=Tax(netincome);
/*Printing the required data*/
printf(\"Gross income = %lf\",grossIncome);
printf(\"\ No of Children = %d\",noOfChildren);
if(option==\'s\' || option==\'S\') {
printf(\"\ Option type = Single\");
}
else if(option==\'j\' || option==\'J\'){
printf(\"\ Option type = Joint\");
}
printf(\"\ Net income = %lf\",netincome);
printf(\"\ Tax applicable = %lf\",tax);
  
}
/*Function to calculate net income*/
double NetIncome(double grossIncome, int noOfChildren, char option) {
double netincome=0;
double stdDeduction=0;
int noOfExemption=0;
/*Values set depending on the option */
if(option==\'s\' || option==\'S\') {
stdDeduction=8000.00;
noOfExemption=1+noOfChildren;
}
else if(option==\'j\' || option==\'J\'){
stdDeduction=12000.00;
noOfExemption=2+noOfChildren;
}
/*Only s,S,j,J are allowed*/
else {
printf(\"Invalid option\");
exit(0);
}
double dependentDeduction = noOfExemption*2500.00;
double totalDeduction=stdDeduction+dependentDeduction;
netincome=grossIncome-totalDeduction;
return netincome;
}

/*Function to calculate tax*/
double Tax(double netincome) {
double taxAmount=0;
if(netincome<20000)
taxAmount=0;
else if(netincome>=20000 && netincome<50000)
taxAmount=0.1*netincome;
else if(netincome>=50000 && netincome<100000)
taxAmount=0.15*netincome;
else if(netincome>=100000)
taxAmount=0.2*netincome;
return taxAmount;
}

*********************************************************************
END OF PROGRAM
*********************************************************************

Sample Input:
50000
2
j

Sample Output:
Gross income = 50000.000000
No of Children = 2
Option type = Joint
Net income = 28000.000000
Tax applicable = 2800.000000

Sample Input:
70000
1
S

Sample Output:
Gross income = 70000.000000
No of Children = 1
Option type = Single
Net income = 57000.000000
Tax applicable = 8550.000000

Sample Input:
70000
1
m

Sample Output:
Invalid option


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site