Question

In: Computer Science

C PROGRAM ..... NOT C++ PROGRAM 3 (UPDATE TO TWO PRIOR PROGRAMS FOR REFERENCE OF PRIOR...

C PROGRAM ..... NOT C++

PROGRAM 3 (UPDATE TO TWO PRIOR PROGRAMS FOR REFERENCE OF PRIOR PROGRAM INSTRUCTIONS PLEASE SEE BELOW)

PROGRAM 3

Adjust program II to make use of functions. All the same rules from the previous program specifications still apply, for example input gathering, output formatting and breaking on -1 still apply.

Additional requirements.

  • Write a function that prompts the user for hours worked, rate and name. Use parameter passing, and pass by reference.
  • Write a function that calculates the gross, base and overtime pay, pass by reference.
  • Write a function that calculates tax, taking as input the gross pay, returning the tax owed.
  • Calculate the total amount paid (gross pay) for all 5 people. Use the return value from the function that calculates the gross pay.
  • Write a print function that generates the output, including the total amount paid, in addition to the data for each employee.

Example (Sample input & output for one person)

Enter name: Glenn

Enter hourly rate: 2.00

Enter hours worked: 50

Enter name: -1

Pay to: Glenn

Hours worked:                50.0

Hourly rate:                $    2.00

Gross pay:                   $110.00

Base pay:                    $ 80.00

Overtime pay:                         $ 30.00

Taxes paid:                 $ 22.00

Net pay:                      $ 88.00

Total Paid to all employees = $110.00

(The grand total of payments out.)

PROGRAM 1 AND 2 (JUST FOR REFERENCE NO CODE NEEDED)

PROGRAM 1

Payroll application

  1. Write a program that reads in the first name, hourly rate and number of hours worked for 5 people.
  2. Print the following details for each employee.
    1. Name of employee
    2. The number of hours worked
    3. Their weekly gross pay
      1. This is calculated by multiplying hours worked times hourly rate.
        1. If hours worked per week is greater than 40, then overtime needs to also be included.
          1. Overtime pay is calculated as the number of hours worked beyond 40 * rate * 1.5
    4. Taxes withheld
      1. Our tax system is simple, the government gets 20% of the gross pay.
    5. Net paid
      1. The amount of the check issued to the employee.

PROGRAM 2

Payroll 2.0

Update the first program.

  1. Use for loops to process the data for 5 employees.
    1. One loop to load the data
    2. One loop to print the output.
    3. In for loops, if any of the entered fields are –1, break out of the loop immediately after getting -1
  2. Update the output as shown in the sample data.
  3. Use arrays to store the user input.

The program logic will first load all of the data, until the user enters the max number of records, or they input -1 for one of the fields. After the data is loaded, it will then be processed and output generated.

CODE USED FOR PROGRAM 2:

#include <stdio.h>
#include <string.h>
void main()
{
char name[5][30];
float hourly_rate[5], hours_worked[5];
float n, gross;
for (int i = 0; i < 5; i++)
{
printf("\nEnter the first name: ");
scanf("%s", name[i]);
if (!strcmp(name[i], "-1"))
break;
printf("\nEnter the hourly rate: ");
scanf("%f", &hourly_rate[i]);
if (hourly_rate[i] == -1)
break;
printf("\nEnter the hours worked: ");
scanf("%f", &hours_worked[i]);
if (hours_worked[i] == -1)
break;
}
for (int i = 0; i < 5; i++)
{
if (!strcmp(name[i], "-1"))
break;
if (hourly_rate[i] == -1)
break;
if (hours_worked[i] == -1)
break;
printf("\nPay to: %s", name[i]);
printf("\nHours worked: %f", hours_worked[i]);
printf("\nHourly rate: $%f", hourly_rate[i]);
if (hours_worked[i] > 40)
{
n = hours_worked[i] - 40;
gross = (40 * hourly_rate[i]) + (n * hourly_rate[i] * 1.5);
printf("\nGross pay: $ %f", gross);
printf("\nBase pay: $ %f", 40 * hourly_rate[i]);
printf("\nOvertime pay: $ %f", n * hourly_rate[i] * 1.5);
printf("\nTax paid: $ %f", gross * .20);
printf("\nNet paid: $ %f", gross - (gross * .20));
}
else
{
printf("\nGross pay:$ %f", hourly_rate[i] * hours_worked[i]);
printf("\nBase pay: $ %f", hourly_rate[i] * hours_worked[i]);
printf("\nTax paid: $ %f", hourly_rate[i] * hours_worked[i] * .20);
printf("\nNet pay: $ %f", (hourly_rate[i] * hours_worked[i]) - (hourly_rate[i] * hours_worked[i] * .20));
}
}
}

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

#include <stdio.h>
#include <string.h>

// Function Declarations
float calcBasePay(float hours_worked,float hourly_rate);
float calcOverTimePay(float hours_worked,float hourly_rate);
float calcGrossPay(float basepay,float overtime);
float calcTax(float gross);
float calcNetPay(float gross,float tax);

void main()
{
   //Declaring variables
   int i;
char name[5][30];
float hourly_rate[5], hours_worked[5];
float n, gross,basepay,overtime,tax,netPay,totalPayment=0;
for (i = 0; i < 5; i++)
{
printf("\nEnter the first name: ");
scanf("%s", name[i]);
if (!strcmp(name[i], "-1"))
break;
printf("\nEnter the hourly rate: ");
scanf("%f", &hourly_rate[i]);
if (hourly_rate[i] == -1)
break;
printf("\nEnter the hours worked: ");
scanf("%f", &hours_worked[i]);
if (hours_worked[i] == -1)
break;
}
for (i = 0; i < 5; i++)
{
if (!strcmp(name[i], "-1"))
break;
if (hourly_rate[i] == -1)
break;
if (hours_worked[i] == -1)
break;
printf("\n%-30s%s","Pay to:", name[i]);
printf("\n%-30s%.2f","Hours worked: ", hours_worked[i]);
printf("\n%-30s$ %.2f","Hourly rate:", hourly_rate[i]);

   basepay=calcBasePay(hours_worked[i],hourly_rate[i]);
   overtime=calcOverTimePay(hours_worked[i],hourly_rate[i]);
   gross=calcGrossPay(basepay,overtime);
tax=calcTax(gross);
netPay=calcNetPay(gross,tax);
printf("\n%-30s$ %.2f","Gross pay: ", gross);
printf("\n%-30s$ %.2f","Base pay:", basepay);
printf("\n%-30s$ %.2f","Overtime pay:",overtime);
printf("\n%-30s$ %.2f","Tax paid:", tax);
printf("\n%-30s$ %.2f","Net paid:", netPay);
totalPayment+=gross;
}
printf("\n\nTotal Paid to all employees = $%.2f",totalPayment);

}

// Function which calculate Gross pay
float calcGrossPay(float basepay,float overtime)
{
   return basepay+overtime;
}
// Function which calculate Base pay
float calcBasePay(float hours_worked,float hourly_rate)
{
   float basePay=0.0;
   if(hours_worked<=40)
   {
       basePay=hours_worked*hourly_rate;
   }
   else
   {
       basePay=40*hourly_rate;
   }
   return basePay;
}
// Function which calculate Overtime pay
float calcOverTimePay(float hours_worked,float hourly_rate)
{
   float overTime=0.0;
if(hours_worked>40)
   {
       overTime=(hours_worked-40)*hourly_rate*1.5;
   }  
return overTime;
}
// Function which calculate tax
float calcTax(float gross)
{
   return gross*0.20;
}

// Function which calculate net pay
float calcNetPay(float gross,float tax)
{
   return gross-tax;
}

=====================================

Output:

==================================Thank You


Related Solutions

C Programming Language: For this lab, you are going to create two programs. The first program...
C Programming Language: For this lab, you are going to create two programs. The first program (named AsciiToBinary) will read data from an ASCII file and save the data to a new file in a binary format. The second program (named BinaryToAscii) will read data from a binary file and save the data to a new file in ASCII format. Specifications: Both programs will obtain the filenames to be read and written from command line parameters. For example: - bash$...
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not...
A C PROGRAM *Edit/Update I do not need the file loading script, but I am not against it being included in the answer* I must read off of an excel file (comma separated) to input five different things for a book, all comma separated, there are 360 books in the file. The book title, author, ISBN number, number of pages, and finally the year it was published. Now some of the ISBN or Pg numbers may be missing and will...
For C program, convert the 1-D stencil program from lab03 to use array reference (B[I]) to...
For C program, convert the 1-D stencil program from lab03 to use array reference (B[I]) to access array element instead of using pointers. The C program follows these steps: 1) declare two arrays, each has 100 elements; 2) use a for loop to randomly generate 100 integers and store them in one array; 3) use another for loop to do the 1-D stencil and store the result in the other array;
Write C++ programs to perform the following tasks. In the program descriptions below, example input and...
Write C++ programs to perform the following tasks. In the program descriptions below, example input and output is provided. NOTE: You don’t need arrays to solve any of these problems. You should NOT use arrays to solve any of these problems. • stat.cpp: Let the user input a one or more integers, space separated, on a single line (as seen below), then work out and display the sum, average, sum of squares and population variance of the numbers. Remember, you...
Write program logic or pseudocode to create 3 small programs that do the following: The first...
Write program logic or pseudocode to create 3 small programs that do the following: The first should compute the sum of 2 given integers. The second should multiply the 2 integers. The third should triple the sum of the 2 integers.
Find LRU paging A program has the following page reference string 0 1 2 3 3...
Find LRU paging A program has the following page reference string 0 1 2 3 3 4 2 4 5 3 3 4 6 2 5 6 If we allocate 3 page frames to the program, 1. Please draw a figure to show the page allocation/replacement. 2. How many page faults will be generated?
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program,...
In this programming challenge you are to create two Python programs: randomwrite.py and randomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program called randomwrite.py that writes a series of random integers to a file....
C++ Create a program that use the linkedbag 3. Develop a program to maintain a list...
C++ Create a program that use the linkedbag 3. Develop a program to maintain a list of homework assignments. When an assignment is assigned, add it to the list, and when it is completed, remove it. You should keep track of the due date. Your program should provide the following services: • Add a new assignment. • Remove an assignment. • Provide a list of the assignments in the order they were assigned. • Find the assignment(s) with the earliest...
I need to update this program to follow the these requirements please and thank you :...
I need to update this program to follow the these requirements please and thank you : Do not use packages Every class but the main routine class must have a toString method . The toString method for Quadrilateral should display its fields: 4 Points. All instance variables should be declared explicitly private . Area incorrect : enter points no: 1 1 3 enter points no: 2 6 3 enter points no: 3 0 0 enter points no: 4 5 0...
Prior to the withdrawal of AASB 1031 and with reference to the AASB 1031 Materiality (issued...
Prior to the withdrawal of AASB 1031 and with reference to the AASB 1031 Materiality (issued by the Australian Accounting Standards Boards - AASB) and the ASA 320 Materiality in Planning and Performing an Audit and ASA 450 Evaluation of Misstatements Identified during an Audit (issued by the Auditing and Assurance Standards Board – AUASB), : a. Define materiality. b. Outline the qualitative and quantitative guidelines of materiality. c. How the concepts and constructs of “materiality” influence the auditors’ professional...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT