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...
This C++ program will use arrays, recursion, and pass by reference to calculate 02, 12, 22,...
This C++ program will use arrays, recursion, and pass by reference to calculate 02, 12, 22, 32, 42 and then print a message. Write a driver program (main) that includes the following: An array class (not a built-in-array) of 5 integers initialized to 0,1,2,3,4 the bases An integer initialized to 2 to hold the exponent A string initialized to “Good Job!\n”; A for loop that calls the recursive pow function with all of the bases and the exponent. Call the...
*****In C++***** Exercise #3: Develop a program (name it AddMatrices) that adds two matrices. The matrices...
*****In C++***** Exercise #3: Develop a program (name it AddMatrices) that adds two matrices. The matrices must of the same size. The program defines method Addition() that takes two two-dimensional arrays of integers and returns their addition as a two-dimensional array. The program main method defines two 3-by-3 arrays of type integer. The method prompts the user to initialize the arrays. Then it calls method Addition(). Finally, it prints out the array retuned by method Addition(). Document your code, and...
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.
C++ program Reference: while loop, if....else, for loop, the % operator MARTIAN BOOLEAN MULTIPLICATION OBJECTIVE: To...
C++ program Reference: while loop, if....else, for loop, the % operator MARTIAN BOOLEAN MULTIPLICATION OBJECTIVE: To compute the product of two integers using the Martian method of multiplication. INPUT: 5 pairs of positive integers to be multiplied. To be read in one pair at a time. USE A FOR LOOP TO CONTROL THE READING OF THE INPUT OUTPUT: Submit the following: The psuedocode or notes on how you will attack the problem Hand in the complete C++ program, properly commented...
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT