Question

In: Computer Science

In C Programming Create a payroll program to store and calculate the payroll for a small...

In C Programming

Create a payroll program to store and calculate the payroll for a small company as follows: Ask the user for the number of employees and only accept the number if it is between 5 and 40 employees, otherwise prompt the user again and test the input, keep repeating until the user enters an acceptable number.

Create an array of floats that is 4 rows and an number of columns equal to the number of employees in the company. Program parameters are as follows: Create a menu with the following options (use a do-while loop):

A or a to add employee info

D or d to display employee info

T or t to display total payroll

S or s to display the info of all employees

C or c to display the count of employees present in the array

Z or z to exit program

The information for each employee is: employee number, hours worked, pay rate per hour, tax deduction.

Option A or a: ask the user for one employee information at a time and store it in the array.

Please enter employee number: 2190

Please enter hours worked: 32.50

Please enter pay rate: 9.25

Please enter tax rate deduction: 5.50

Option D or d: ask the user for an employee number as integer and display the information for the corresponding employee (cast the employee number in the array to integer and then compare). If employee number does not match, output a msg. indicating “no such employee”. If the employee number is a match, output all the employee information stored in addition to the calculated deduction and salary.

Output sample: Info for employee number: 2190

Hours worked: 32.50Pay rate: $ 9.25

Total earned: $ 300.63

Tax deduction: 5.50 % for an amount of $ 16.53

Paycheck: $ 284.09

Option T or t: calculate and output the sum of the total for the paychecks of all employees.

Option S or s: display the information for all employees in the same format as in option B one employee at a time separated by a line of ------.

Option C or c: Output the number of employees in the array.

Option Z or z: exit the program.

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 <stdlib.h>
#include <ctype.h>
#include <string.h>

// Creating a struct to hold the informatiomn of an employee data
struct employee
{
   int empNo;
double hoursWorked;
double payrate;
double totEarned;
double taxRate;
double taxDeduction;
double payCheck;
};
int main() {
//Declaring variables
int size,i;
char choice;
int count=0;
  
/* This while loop continues to execute
* until the user enters a valid number
*/
while(1)
{
// Getting the inputs entered by the user
   printf("Enter no of employees :");
   scanf("%d",&size);
   if(size<5 || size>40)    
   {
       printf("** Invalid.Must be between 5 - 40 **\n");
   }
   else
   break;
   }
  
   employee emps[size];
  
/* This while loop continues to execute
* until the user enters either 'Z' or 'z' or valid choice
*/
   while(1)
   {
       //displaying the menu
       printf("\nA or a to add employee info\n");
       printf("D or d to display employee info\n");
       printf("T or t to display total payroll\n");
       printf("S or s to display the info of all employees\n");
       printf("C or c to to display the count of employees present in the array\n");
       printf("Z or z to exit program\n");  
      
       //getting the choice entered by the user
       printf("Enter Choice :");  
       scanf(" %c",&choice);
      
       //Based on the user choice the corresponding case will be executed
       switch(choice)
       {
           case 'A':
           case 'a':   {
               if(count<size)
               {
                   //Getting the inputs entered by the user
                   printf("Please enter employee number:");
                   scanf("%d",&emps[count].empNo);
                   printf("Please enter hours worked:");
                   scanf("%lf",&emps[count].hoursWorked);
                   printf("Please enter pay rate:");
                   scanf("%lf",&emps[count].payrate);
                   printf("Please enter tax rate deduction:");
                   scanf("%lf",&emps[count].taxRate);
                  
                   // Performing calculations
                   emps[count].totEarned=emps[count].hoursWorked*emps[count].payrate;
                   emps[count].taxDeduction=emps[count].totEarned*(emps[count].taxRate/100);
                   emps[count].payCheck=emps[count].totEarned-emps[count].taxDeduction;
                   count++;
               }
               continue;
           }
           case 'D':
           case 'd':
             
               {
                   int index=-1;  
           int empNo;
               printf("Enter employee number :");
               scanf("%d",&empNo);
               for(i=0;i<count;i++)
               {
               if(emps[i].empNo==empNo)  
               {
                   index=i;
                   break;
               }
               }
              
               if(index==-1)
               {
                   printf("no such employee\n");
               }
               else
               {
                   // Displaying the employee info
                   printf("Info for employee number: %d\n",emps[index].empNo);
                   printf("Hours worked: %.2f\n",emps[index].hoursWorked);
printf("Pay rate: $ %.2f\n",emps[index].payrate);
printf("Total earned: $ %.2f\n",emps[index].totEarned);
printf("Tax deduction: %.2f for an amount of $ %.2f\n",emps[index].taxRate,emps[index].taxDeduction);
printf("Paycheck: $ %.2f\n",emps[index].payCheck);
               }
               continue;
           }
           case 'T':
           case 't':   {
               double totPaychecks=0.0;
               for(i=0;i<count;i++)
               {
                   totPaychecks+=emps[i].payCheck;
               }
               printf("Total pay checks of all employees : %.2f\n",totPaychecks);
               continue;
           }
           case 'S':
           case 's':   {
               // Displaying all employees info
               for(i=0;i<count;i++)
               {
                   printf("Info for employee number: %d\n",emps[i].empNo);
                   printf("Hours worked: %.2f\n",emps[i].hoursWorked);
printf("Pay rate: $ %.2f\n",emps[i].payrate);
printf("Total earned: $ %.2f\n",emps[i].totEarned);
printf("Tax deduction: %.2f for an amount of $ %.2f\n",emps[i].taxRate,emps[i].taxDeduction);
printf("Paycheck: $ %.2f\n",emps[i].payCheck);
printf("-----------------------------------\n");
               }
               continue;
           }
           case 'C':
           case 'c':   {
               printf("No of employees in the array is %d\n",count);
               continue;
           }
           case 'Z':
           case 'z':   {
               break;
           }
           default:{
               printf("** Invalid Choice **\n");
               continue;
           }
          
          
          
       }
       break;
   }
  
   return 0;
  
}

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

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

Output:

=====================Could you plz rate me well.Thank You


Related Solutions

C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class...
C++ Programming Create a C++ program program that exhibits polymorphism. This file will have three class definitions, one base class and three derived classes. The derived classes will have an inheritance relationship (the “is a” relationship) with the base class. You will use base and derived classes. The base class will have at least one constructor, functions as necessary, and at least one data field. At least one function will be made virtual. Class members will be declared public and...
You are using ONLY Programming Language C for this: In this program you will calculate the...
You are using ONLY Programming Language C for this: In this program you will calculate the average of x students’ grades (grades will be stored in an array). Here are some guidelines to follow to help you out: 1. In your program, be sure to ask the user for the number of students that are in the class. The number will help in declaring your array. 2. Use the function to scan the grades of the array. To say another...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to input 2 numbers, a starting number x and ending number y Implements a while loop that counts from x (start) to y(end). Inside the loop, print to the screen the current number Print rather the current number is even or odd If the number is even , multiply by the number by 3 and print the results to the screen. If the number is...
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$...
C# Programming create a Hash Function
C# Programming create a Hash Function
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
USING C PROGRAMMING ***CODE MUST BE MODULARIZED** Instructions: Create a program that will collect multiple receipts...
USING C PROGRAMMING ***CODE MUST BE MODULARIZED** Instructions: Create a program that will collect multiple receipts from multiple classrooms to accumulate total cookie sales.   Once all receipts have been processed, the program must show what classroom is won and the total amount of cookies they sold. The classrooms that are participating are from the:                 2nd Floor: 201, 202, 203, 204, 205, 206, 207, 208                 3rd Floor: 301,302, 303, 304, 305, 306, 307, 308, 309                 4th Floor: 401,...
Write a program to create a tree randomly. You can use C++ programming language. The input...
Write a program to create a tree randomly. You can use C++ programming language. The input is the number of vertices in the tree, and the output is an adjacent list of the tree. (Managed to complete this assignment with a binary tree. But, was told I needed a general tree instead)
A store has 4 categories A, B, C and D, create a program that asks you...
A store has 4 categories A, B, C and D, create a program that asks you 10 times the sale and the category so that at the end it shows you the total by category, and the sum of all. Code in C # and Python
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT