***Please read instructions carefully*** Problem: Write a program in C that will
ID: 3764460 • Letter: #
Question
***Please read instructions carefully***
Problem: Write a program in C that will calculate the salary raise for employees that will use LOOPS (while, do while or for loops may be used)
if salary is between $0 < $30000 the rate is 7.0%
if salary is between $30000 <= $40000 the rate is 5.5%
if salary is more than $40000 the rate is 4.0%
Instructions Given:
1. Use the appropriate functions and pass parameters for this program. Include at least one function that uses the return statement (non-void) and at least one function that does NOT use the return statement (void).
2. Write a function using loops that allows user to input the salaries (as many as they want).
3. Write a function that calculates the raises, the new salaries (raise + salaries), the total of the original salaries, the total of raises and the total of all the new salaries with the raises.
4. Write a function to print the output formatted exactly like the following example
5. You may have more functions than the 3 listed above
6. You must use a Loops in the program- you may either use a while loop, do loop, or for loops. DO NOT USE structs, arrays, etc.
7. Do not include other header files other than stdio.h and stdlib.h
Thank you.
Explanation / Answer
#include<stdio.h>
#include<pthread.h>
struct emp
{
char name[10];
int salary;
int no;
}*t;
int nthread,n;
void *work(void *);
main()
{
pthread_t id;
struct emp e[5];
int i;
printf("Enter The No Of Thread");
scanf("%d",&nthread);
printf("Enter The No of Element");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the Employee Name : ");
scanf("%s",&e[i].name);
printf("Enter the Employee Salary : ");
scanf("%d",&e[i].salary);
}
/*for(i=0;i<n;i++)
{
printf("%s",e[i].name);
printf("%d ",e[i].salary);
}*/
for(i=0;i<nthread;i++)
{
e[0].no=i;
if(0==pthread_create(&id,NULL,work,(void *)&e))
{
continue;
}
else
{
printf("Problem In Thread Creation");
}
}
pthread_join(id,NULL);
printf(" After Updation ");
printf("E_Name E_salary ");
for(i=0;i<n;i++)
{
printf("%s ",e[i].name);
printf("%d ",e[i].salary);
}
}
void *work(void *e)
{
int j,i;
t=(struct emp *)e;
// printf("%d",t[0].no); for(j=t[0].no;j<n;j+=nthread)
{
t[j].salary=t[j].salary+(t[j].salary*0.15);
}
pthread_exit(NULL);
}
/* OUTPUT:
---------
Enter The No Of Thread2
Enter The No of Element6
Enter the Employee Name : rohit
Enter the Employee Salary : 5000
Enter the Employee Name : rakesh
Enter the Employee Salary : 6000
Enter the Employee Name : amit
Enter the Employee Salary : 8000
Enter the Employee Name : amir
Enter the Employee Salary : 9000
Enter the Employee Name : govinda
Enter the Employee Salary : 6000
Enter the Employee Name : ram
Enter the Employee Salary : 80000
After Updation
E_Name E_salary
rohit 5749
rakesh 6899
amit 9199
amir 10349
govinda 6899
ram 91999
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.