Question

In: Computer Science

Many universities pay their teaching assistants (TA) or associate instructors (AI) as weekly workers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 10 hours they work and “time-and-a-half”

Needs to be written in C

Many universities pay their teaching assistants (TA) or associate instructors (AI) as weekly workers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 10 hours they work and “time-and-a-half”- i.e., 1.5 times their hourly wage - for overtime hours worked), commission workers (who receive $250 plus 7.1 times their gross weekly work hours), or pieceworkers (who receive a fixed amount of money for each of the items they produce - each pieceworker in the university works on only one type of item). Some TAs may be international students who are not authorized to work more than 20 hours per week. Write a program to compute the weekly pay for each worker. You do not know the number of employees in advance. Each type of worker has its own pay code: AIs have paycode ‘W’, hourly workers have code ‘H’, commission workers have code ‘C’ and pieceworkers have code ‘P’. Use a switch statement to compute each employee’s pay based on that employee’s paycode. Within the switch, prompt the user (i.e., the payroll clerk) to enter the number of employees of each paycode (minimum of 2), and the appropriate facts your program needs to calculate each employee’s pay based on that employee’s paycode. [Note: You can input values of type double using the conversion specifier %lf with scanf.]. The program should start by displaying a ‘Menu’ like option where you user can enter the appropriate paycode first along with the number of employees of that type. Only acceptable paycodes are ‘W’, ‘H’, ‘C’, and ‘P’. User may enter ‘Q’ to quit the program. Any other choice should display the menu again. Also display the following statistics:
• Weekly salary paid to workers who are international students,
• Weekly salary paid to workers who are domestic students,
• Weekly salary paid to workers with different paycodes.
• Total weekly salary paid to all workers
Note 1: Loops can be written using ‘while’, ‘for’ and ‘do-while’ statements. For this question, you can’t use same loop statement more than once (For example: if you have to use double nested loop, you can’t use ‘for’ loop inside a ‘for’ loop. It has to be ‘for’ loop inside a ‘while’ or vice versa or some other combination)!
Note 2: Your program should be case insensitive. Uppercase and lowercase inputs will be considered correct!
Note 3: After displaying the salary amounts, show the menu again automatically. Notice that there will be no other way to stop the program until user enters Q.

Solutions

Expert Solution

Screenshot

-----------------

Code

----------------

////////////////////////////////////////////////////////////////////////////////////////////////////

#include
#include
#include
#include
#include

struct employee
{
   char name[20];
   double salary;
   char wtype;
   char ltype;
   struct employee *next;  
};

void add(struct employee** head_ref,char* name, double salary, char wtype, char ltype)
{
struct employee* new_employee = (struct employee*) malloc(sizeof(struct employee));
  
strcpy(new_employee->name,name);
new_employee->salary=salary;
new_employee->wtype=wtype;
new_employee->ltype=ltype;
  
new_employee->next = (*head_ref);
  
(*head_ref) = new_employee;
}

int main()
{  
   struct employee* head = NULL;
   char choice;
   double weekly_I=0;
   double weekly_D=0;
   double weekly_W=0;
   double weekly_H=0;
   double weekly_C=0;
   double weekly_P=0;
   double weekly_total=0;
   char name[20];
   double week_salary;
   char wtype;
   char ltype;  
   while(1>0)
   {
       printf("\n\n\t\tMENU\n");
       printf("Enter W for Weekly Workers\n");
       printf("Enter H for Hours Workers\n");
       printf("Enter C for Commission Workers\n");
       printf("Enter P for Piece Workers\n");
       printf("Enter Q to Quit\n");
       printf("Enter your choice: ");
       scanf(" %c",&choice);
       choice=toupper(choice);
      
       switch(choice)
       {
           case 'W':   printf("Enter the name of employee: ");
                       scanf("%s",name);
                       printf("Enter The weekly Salary of the employee: ");
                       scanf("%lf",&week_salary);
                       wtype='W';
                       printf("Enter 0 if the employee is Internationa else enter any other key: ");
                       scanf(" %c",<ype);
                       if(ltype=='0')
                       {
                           ltype='I';
                       }
                       else
                       {
                           ltype='D';
                       }
                       add(&head,name,week_salary,wtype,ltype);                      
                       break;
                      
           case 'H':   printf("Enter the name of employee: ");
                       scanf("%s",name);
                       double hourly_salary;
                       float overtime;
                       printf("Enter The hourly Salary of the employee: ");
                       scanf("%lf",&hourly_salary);
                       printf("Enter The overtime hours of the employee: ");
                       scanf("%f",&overtime);
                       week_salary=((hourly_salary*10)+(hourly_salary*overtime*1.5))*7;
                       wtype='H';
                       printf("Enter 0 if the employee is International else enter any other key: ");
                       scanf(" %c",<ype);
                       if(ltype=='0')
                       {
                           ltype='I';
                       }
                       else
                       {
                           ltype='D';
                       }
                       add(&head,name,week_salary,wtype,ltype);
                       break;
                      
           case 'C':   printf("Enter the name of employee: ");
                       scanf("%s",name);
                       float gross_week_hours;
                       printf("Enter The gross weekly work hours of the employee: ");
                       scanf("%lf",&gross_week_hours);
                       week_salary=250+7.1*gross_week_hours;
                       wtype='C';
                       printf("Enter 0 if the employee is International else enter any other key: ");
                       scanf(" %c",<ype);
                       if(ltype=='0')
                       {
                           ltype='I';
                       }
                       else
                       {
                           ltype='D';
                       }
                       add(&head,name,week_salary,wtype,ltype);
                       break;
                      
           case 'P':   printf("Enter the name of employee: ");
                       scanf("%s",name);
                       printf("Enter The amount paid for the production of the employee in one week: ");
                       scanf("%lf",&week_salary);
                       wtype='W';
                       printf("Enter 0 if the employee is International else enter any other key: ");
                       scanf(" %c",<ype);
                       if(ltype=='0')
                       {
                           ltype='I';
                       }
                       else
                       {
                           ltype='D';
                       }
                       add(&head,name,week_salary,wtype,ltype);
                       break;
                      
           case 'Q':  
                       exit(0);
           default :
                       printf("\n\nPlease Choose correct option");
                      
       }
      
       if(wtype=='W')
       {
           weekly_W+=week_salary;
       }
       if(wtype=='H')
       {
           weekly_H+=week_salary;
       }
       if(wtype=='C')
       {
           weekly_C+=week_salary;
       }
       if(wtype=='P')
       {
           weekly_P+=week_salary;
       }
       if(ltype=='I')
       {
           weekly_I+=week_salary;
       }
       if(ltype=='D')
       {
           weekly_D+=week_salary;
       }
       weekly_total+=week_salary;
       printf("\nWeekly salary paid to workers who are international students: %lf",weekly_I);
       printf("\nWeekly salary paid to workers who are domestic students: %lf",weekly_D);
       printf("\nWeekly salary paid to workers with different paycodes are as follows\n");
       printf("Paycode W: %lf\n",weekly_W);
       printf("Paycode H: %lf\n",weekly_H);
       printf("Paycode C: %lf\n",weekly_C);
       printf("Paycode P: %lf\n",weekly_P);
       printf("\nTotal weekly salary paid to all workers: %lf",weekly_total);
      
      
   }
}

//////////////////////////////////////////////////////////////////////////////////////////////////

Output

---------------


Related Solutions

A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time- and -a-half “—1.5 times their hourly wage — for overtime hours worked )
USING C++A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time- and -a-half “—1.5 times their hourly wage — for overtime hours worked ), commission workers (who receive $250 plus 5.7 percent of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce). Write a program...
Problem Description A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work
Programming Language: C++Problem Description A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time-and-a-half,” i.e. 1.5 times their hourly wage, for overtime hours worked), commission workers (who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce-each pieceworker in this company...
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who...
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time-and-a-half”—i.e., 1.5 times their hourly wage—for overtime hours worked), commission workers (who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers (who receive a fixed amount of money for each of the items they produce—each pieceworker in this company works on only one type of item). Write...
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who...
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time-and-a-half,” i.e. 1.5 times their hourly wage, for overtime hours worked), commission workers (who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce-each pieceworker in this company works on only one...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT