PLEASE USE JUST BASIC COMPILER ONLY : NO JAVA, NO C++ CODE!! JUST BASIC COMPILER
ID: 3693487 • Letter: P
Question
PLEASE USE JUST BASIC COMPILER ONLY : NO JAVA, NO C++ CODE!! JUST BASIC COMPILER PLEASE
Write a program where the main part of the program collects the data such as employee hours, hourly rate, state of residence, and marital status.
It then calls the function Calculatewages() function and sends employee hours and hourly rate.
The Calculatewages () function would calculate the wages and sends it back to the main.
The main program would use the wages returned by Calcualewages() function and send it another function called CalcualteFederaltax() along with marital status. The CalcualteFederaltax() function would calculate the federal tax based on marital status and send the fedtax amount back to the main.
Then the main function would call another function called calculatestatetax() and send the wage and state of residence info to that function. Calculatestatetax() function would calculate the state tax based on the state of residence and send stat tax back to the main.
The main then would call the function calcualtenet() function and send wage, fedtax, and statetax returned by the above functions.
The calculate function would calculate the net wages, and display all information such as wage before tax, taxes, and wage after taxes.
You can write your program based on the following program skeleton
--------------------------------------------------------------------------------------
‘main part of the program.
Collect hoursworked, hourlyrate, stateofresidence, maritalstatus from the user.
Call calculatewages() and send hoursworked, and hourlyrate. The caclulatewages() function returns wages.
Call calculatefedtax() function and send marital status and wage returned by calculatewages() function. This function returns fedtax.
Call calculatestatetax() function and send wage, stateofresidence. This function sends back statetax.
Call calculatenet() function and send, wage, fedtax, statetex. Note that fedtax was returned by calculatefedtax() function and statetax was returned by calculatestatetax() function.
End
Function calculatewages() receives hours worked and hourly rate from the main.
Calculate the wages and sends it back to the main.
End function
Function CalcualteFederaltax () receives wages, and maritalstatus from the main.
Calculate the fed tax based on the marital satus.
Calculate the fed tax at 20% for “Married” and at 25% for “Single”. For others calculate it at 22%
End function
Function calculatestatetax () receives wages and state of residence from the main.
Calculate the statetax sends it back to the main.
Statetax is calculated based on the following criteria.
For those who are from “CA”, “NV”, “SD”, “WA”, “AZ”, calculate the state tax at 8%
For those who are from “TX”, “IL”, “MO”, “OH”, “VA”, calculate the state tax at 7%
For those who are from “NM”, “OR”, “IN”, calculate the state tax at 6%
For the rest calculate the state tax at 5%
Send back the state tax to the main.
End function
Function calcualtenet () receives wages, fedtax, statetax from the main.
Calculate the netwages.
Display the wages, fedtax, statetax, netwages.
End function
Explanation / Answer
#include #include #include #include struct emprec { int empid; char *name; }; typedef struct emprec emp; void insert(char *a); void display(char *a); void update(char *a); int count; void main(int argc, char *argv[]) { int choice; while (1) { printf("Enter the choice "); printf("1-Insert a new record into file 2-Display the records "); printf("3-Update the record 4-Exit "); scanf("%d", &choice); switch (choice) { case 1: insert(argv[1]); break; case 2: display(argv[1]); break; case 3: update(argv[1]); break; case 4: exit(0); default: printf("Enter the correct choice "); } } } /* To insert a new recored into the file */ void insert(char *a) { FILE *fp1; emp *temp1 = (emp *)malloc(sizeof(emp)); temp1->name = (char *)malloc(200 * sizeof(char)); //allocating memory for pointer fp1 = fopen(a, "a+"); if (fp1 == NULL) perror(""); else { printf("Enter the employee id "); scanf("%d", &temp1->empid); fwrite(&temp1->empid, sizeof(int), 1, fp1); printf("Enter the employee name "); scanf(" %[^ ]s", temp1->name); fwrite(temp1->name, 200, 1, fp1); count++; } fclose(fp1); free(temp1); free(temp1->name); } /* To display the records in the file */ void display(char *a) { FILE *fp1; char ch; int var = count; emp *temp = (emp *)malloc(sizeof(emp)); temp->name = (char *)malloc(200*sizeof(char)); fp1 = fopen(a, "r"); if (count == 0) { printf("no records to display "); return; } if (fp1 == NULL) perror(""); else { while(var) // display the employee records { fread(&temp->empid, sizeof(int), 1, fp1); printf("%d", temp->empid); fread(temp->name, 200, 1, fp1); printf(" %s ", temp->name); var--; } } fclose(fp1); free(temp); free(temp->name); } /* To Update the given record */ void update(char *a) { FILE *fp1; char ch, name[200]; int var = count, id, c; emp *temp = (emp *)malloc(sizeof(emp)); temp->name = (char *)malloc(200*sizeof(char)); fp1 = fopen(a, "r+"); if (fp1 == NULL) perror(""); else { while (var) //displaying employee records so that user enter correct employee id { fread(&temp->empid, sizeof(int), 1, fp1); printf("%d", temp->empid); fread(temp->name, 200, 1, fp1); printf(" %s ", temp->name); var--; } printf("enter which employee id to be updated "); scanf("%d", &id); fseek(fp1, 0, 0); var = count; while(var) //loop to update the name of entered employeeid { fread(&temp->empid, sizeof(int), 1, fp1); if (id == temp->empid) { printf("enter employee name for update:"); scanf(" %[^ ]s", name); c = fwrite(name, 200, 1, fp1); break; } fread(temp->name, 200, 1, fp1); var--; } if (c == 1) printf("update of the record succesfully "); else printf("update unsuccesful enter correct id "); fclose(fp1); free(temp); free(temp->name); } }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.