In: Computer Science
#1 Write a simple array program that: Des not use an “external class & demo program" [If you wish, you may break it down into methods, but that is NOT required.]
a. Set up 4 arrays which each hold 6 employee’s data:
int[ ] empid
int[ ] hours
double[ ] rate
double[ ] wages
b. Set up loops to load the empid, hours and rate arrays
c. Set up a loop to calculate values for the wages array.
TAKE OVERTIME [hours > 40], INTO CONSIDERATION,
thru the use of the IF statement
[overtime is time and a half as usual]
d. Set up a loop to print the empid and wages for each employee
#include<stdio.h>
#include<conio.h>
void main()
{ //Arrays to hold employee data
int empid[10];
int hours[10];
double rate[10];
double wages[10];
int i;
clrscr();
//loop to load data into empid, hours and rate
for (i=1;i<=6;i++)
{
printf("\n Enter ID of employee%d",i);
scanf("%d",&empid[i]);
printf("\n Enter working hours of
employee%d",i);
scanf("%d",&hours[i]);
printf("\n Enter rate of employee%d",i);
scanf("%lf",&rate[i]);
}
//loop to calculate values for wages array
for (i=1;i<=6;i++)
{
if (hours[i]<=40) //Checking whether overtime is
taken or not
wages[i]=hours[i]*rate[i]; //if no
overtime , calculate the wage as no.of working hours * rate
else
wages[i]=40*rate[i]+(hours[i]-40)*(rate[i]+rate[i]/2); //if
overtime is taken, the wage is calculated as normal for // less
than 40 hours and for remaining hours rate will be // rate and
half.
}
//loop tp print the empid and wage of each employee
printf("\nEmployeeID\twage");
for (i=1;i<=6;i++)
{
printf("\n %d\t\t%f",empid[i],wages[i]);
}
getch();
}
output
Enter ID of employee11
Enter working hours of employee130
Enter rate of employee150
Enter ID of employee22
Enter working hours of employee240
Enter rate of employee250
Enter ID of employee33
Enter working hours of employee350
Enter rate of employee350
Enter ID of employee44
Enter working hours of employee430
Enter rate of employee4100
Enter ID of employee55
Enter working hours of employee540
Enter rate of employee5100
Enter ID of employee66
Enter working hours of employee650
Enter rate of employee6100
0
EmployeeID wage
1 1500.000000
2 2000.000000
3 2750.000000
4 3000.000000
5 4000.000000
6 5500.000000