How do I calculate the gross pay of employees using C language?

  

CHARACTER STRINGS
Write a C program that will calculate the gross pay of a set of employees.
The program
should prompt the user to enter the number of hours each employee
worked. When prompted, key in the hours shown below.
The program
determines the overtime hours (anything over 40 hours), the gross pay
and then outputs a table in the following format. Column alignment, leading zeros in Clock#, and zero suppression in float fields is important. Use 1.5 as the overtime pay factor.
This week, adding a Total and Average row is no longer optional, its required for this assignment:
a) Add a Total row at the end to sum up the wage, hours, ot, and gross columnsb) Add an Average row to print out the average of the wage, hours, ot, and gross columns
———————————————————
Name Clock# Wage Hours OT Gross
———————————————————
Connie Cobol 098401 10.60 51.0 11.0 598.90
Mary Apl 526488 9.75 42.5 2.5 426.56
Frank Fortran 765349 10.50 37.0 0.0 388.50
Jeff Ada 034645 12.25 45.0 5.0 581.88
Anton Pascal 127615 10.00 40.0 0.0 400.00
———————————————————

Total: 53.10 215.5 18.5 2395.84
Average: 10.62 43.1 3.7 479.19
You should implement this program using a structure similar to the suggested one below to store the information for each employee. Feel free to tweak it if you wish. For example, its OK to have a first and last name member instead of just a name member, and if you want to use different types, that is OK as well.
struct employee
{
char name [20];
long id_number;
float wage;
float hours;
float overtime;
float gross;
};
Use the following information to initialize your data.
Connie Cobol 98401 10.60
Mary Apl 526488 9.75
Frank Fortran 765349 10.50
Jeff Ada 34645 12.25
Anton Pascal 127615 10.00
Create an array of structures with 5 elements, each being of type struct employee. Initialize the array with the data provided and reference the elements of the array with the appropriate subscripts.

Don't use plagiarized sources. Get Your Custom Essay on
How do I calculate the gross pay of employees using C language?
Just from $13/Page
Order Essay

Introduction:
In the world of programming, character strings are a prominent feature that is used to store and manipulate textual data. In this particular context, we are going to look at how one can use character strings to create a C program that calculates the gross pay for a set of employees. We will also examine how to use a structure to store the relevant information for each employee and output the results in a tabular format.

Description:
The C program we are building is designed to prompt the user to enter the number of hours each employee worked, using the data provided to initialize the calculations. The program will then determine the overtime hours, if any, using 1.5 as the overtime pay factor. After calculating the gross pay for each employee, the program will output the results in a specific table format that requires careful attention to detail, specifically column alignment, and zero suppression.

To achieve this, we will create an array of structures that will store the employee’s name, clock number, wage, hours worked, overtime hours, and gross pay. Additionally, we will add a Total row to sum up the wage, hours, overtime, and gross columns. Moreover, an Average row will be added to print out the average of these values. Finally, we will initialize the array with the provided data and iterate through the elements using appropriate subscripts to output the calculated values.

Solution 1:

C program for calculating the gross pay of employees:

//Header files
#include
#include

//Employee structure
struct employee {
char name[20];
long id_number;
float wage;
float hours;
float overtime;
float gross;
};

int main()
{
//Array of structures containing employee data
struct employee emp[5] = {{“Connie Cobol”, 98401, 10.60, 51.0, 0,0},
{“Mary Apl”, 526488, 9.75, 42.5, 0,0},
{“Frank Fortran”, 765349, 10.50, 37.0, 0,0},
{“Jeff Ada”, 34645, 12.25, 45.0, 0,0},
{“Anton Pascal”, 127615, 10.00, 40.0,0,0}};
float ot_pay_factor = 1.5;
float ot_hours = 0;
float reg_pay = 0;
float ot_pay = 0;
float gross_pay = 0;
float total_wage = 0;
float total_hours = 0;
float total_ot = 0;
float total_gross = 0;
float avg_wage = 0;
float avg_hours = 0;
float avg_ot = 0;
float avg_gross = 0;
int i;

//Calculate and display the gross pay
printf(“Name Clock# Wage Hours OT Grossn”);
printf(“————————————————–n”);
for(i=0; i<5; i++) { if(emp[i].hours > 40)
{
ot_hours = emp[i].hours – 40.0;
ot_pay = ot_hours * (ot_pay_factor * emp[i].wage);
reg_pay = 40.0 * emp[i].wage;
gross_pay = reg_pay + ot_pay;
}
else
{
gross_pay = emp[i].hours * emp[i].wage;
}
emp[i].overtime = ot_hours;
emp[i].gross = gross_pay;
total_wage += emp[i].wage;
total_hours += emp[i].hours;
total_ot += emp[i].overtime;
total_gross += emp[i].gross;
printf(“%-15s%06li %4.2f %4.1f %2.1f %6.2fn”, emp[i].name, emp[i].id_number, emp[i].wage, emp[i].hours, emp[i].overtime, emp[i].gross);
}
printf(“————————————————–n”);
printf(“Total: %4.2f %4.1f %2.1f %6.2fn”, total_wage, total_hours, total_ot, total_gross);
printf(“Average: %4.2f %4.1f %2.1f %6.2fn”, total_wage/5, total_hours/5, total_ot/5, total_gross/5);

return 0;
}

Solution 2:

Gross Pay Calculator – A C Program:

//Header files
#include
#include

//Employee structure
struct employee {
char name[20];
long id_number;
float wage;
float hours;
float overtime;
float gross;
};

int main()
{
//Array of structures containing employee data
struct employee emp[5] = {{“Connie Cobol”, 98401, 10.60, 51.0, 0,0},
{“Mary Apl”, 526488, 9.75, 42.5, 0,0},
{“Frank Fortran”, 765349, 10.50, 37.0, 0,0},
{“Jeff Ada”, 34645, 12.25, 45.0, 0,0},
{“Anton Pascal”, 127615, 10.00, 40.0,0,0}};
float ot_pay_factor = 1.5;
float ot_hours = 0;
float reg_pay = 0;
float ot_pay = 0;
float gross_pay = 0;
float total_wage = 0;
float total_hours = 0;
float total_ot = 0;
float total_gross = 0;
float avg_wage = 0;
float avg_hours = 0;
float avg_ot = 0;
float avg_gross = 0;
int i;

//Calculate and display the gross pay
printf(“Gross Pay Calculatorn”);
printf(“————————————-n”);
printf(“The following are the employee details:n”);
printf(“Name Clock# Wage Hours OT Grossn”);
printf(“————————————————–n”);
for(i=0; i<5; i++) { if(emp[i].hours > 40)
{
ot_hours = emp[i].hours – 40.0;
ot_pay = ot_hours * (ot_pay_factor * emp[i].wage);
reg_pay = 40.0 * emp[i].wage;
gross_pay = reg_pay + ot_pay;
}
else
{
gross_pay = emp[i].hours * emp[i].wage;
}
emp[i].overtime = ot_hours;
emp[i].gross = gross_pay;
total_wage += emp[i].wage;
total_hours += emp[i].hours;
total_ot += emp[i].overtime;
total_gross += emp[i].gross;
printf(“%-15s%06li %4.2f %4.1f %2.1f %6.2fn”, emp[i].name, emp[i].id_number, emp[i].wage, emp[i].hours, emp[i].overtime, emp[i].gross);
}
printf(“————————————————–n”);
printf(“Total: %4.2f %4.1f %2.1f %6.2fn”, total_wage, total_hours, total_ot, total_gross);
printf(“Average: %4.2f %4.1f %2.1f %6.2fn”, total_wage/5, total_hours/5, total_ot/5, total_gross/5);

return 0;
}

Suggested Resources/Books:
1. “C Programming Absolute Beginner’s Guide (3rd Edition)” by Greg Perry and Dean Miller
2. “C Programming for the Absolute Beginner, Second Edition” by Michael Vine
3. “Programming in C (4th Edition)” by Stephen G. Kochan
4. “Learn C the Hard Way: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C) (Zed Shaw’s Hard Way Series)” by Zed A. Shaw
5. “Effective C: An Introduction to Professional C Programming” by Robert C. Seacord

Similar asked questions:
1. How do I create a C program that calculates gross pay for employees?
2. How can I prompt the user to enter the number of hours each employee worked in a C program?
3. How do I determine overtime hours in a C program and calculate overtime pay?
4. How can I use structures in C to store information for each employee?
5. What is the best way to initialize an array of structures in C with data provided?

Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more
× How can I help you?