Question

In: Computer Science

#1    Write  a simple array program that:    Des not use an “external class & demo      program"    [If you wish, you...

#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

Solutions

Expert Solution

#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


Related Solutions

Write a program that uses an array of doubles initialized to whatever values you wish. Write...
Write a program that uses an array of doubles initialized to whatever values you wish. Write methods to calculate and return the minimum and a method to calculate and return the maximum value in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods. Write an additional method that accepts the array as a parameter and then creates and returns a new array with all the same...
JAVA: USE SWITCH METHOD Write a Temperature class using the Demo below. The class will have...
JAVA: USE SWITCH METHOD Write a Temperature class using the Demo below. The class will have three conversion methods: toCelcius(), toKelvin and toFahrenheit(). These methods will return a Temperature in those three scales equal to this temperature. Note that the value of this is not changed int these coversions. In addition to these conversion methods the class will have add(Temperature), subtract(Temperature), multiply(Temperature) and divide(Temperature). These four methods all return a temperature equalled to the respective operation. Note that the this...
C/ C++ Preferably 1. Write a simple program where you create an array of single byte...
C/ C++ Preferably 1. Write a simple program where you create an array of single byte characters. Make the array 100 bytes long. In C this would be an array of char. Use pointers and casting to put INTEGER (4 byte) and CHARACTER (1 byte) data into the array and pull it out. YES, an integer can be put into and retrieved from a character array. It's all binary under the hood. In some languages this is very easy (C/C++)...
1. You are to write a simple program with two classes. One controller class and a class to hold your object definition.
1. You are to write a simple program with two classes. One controller class and a class to hold your object definition. (Similar to what we used in class) 2. Use a package in your project, the package name should be xxxprojectname. xxx is your initials taken from the first three characters of your Cal Poly email address. 3. Read in the following from the JOptionPane input window: a. Customer First Name b. Customer Last Name c. Customer Phone Number...
Write an ARMv8 program to sort an array of elements. As Imentioned in class, this...
Write an ARMv8 program to sort an array of elements. As I mentioned in class, this problem uses a portion of your Programming Assignment 1 where you computed the smallest and largest values in an array. Here we will extend that assignment to find the “index” of the smallest and the index of the largest elements of the array. The following C code segment illustrates how we can sort the element of an array.For this problem, assume an array with...
Write a Java program for a simple bank account. You shall define a Customer class: A...
Write a Java program for a simple bank account. You shall define a Customer class: A customer has a first name, last name, and social security number. The social security number is a String variable and must comply with this format: xxx-xx-xxxx where 'x' is a digit between 0-9. If a customer is supplied with an invalid SSN, a message must be printed stating SSN of the customer is invalid; however, the account still is created. You shall define a...
You are expected to write a program from scratch. In the program, an array will be...
You are expected to write a program from scratch. In the program, an array will be initialized with 23 random integers between 1000 and 1999 (inclusive). The output of the program is 4 lines on the screen, specifically, All elements in the array (line 1) All elements in reverse order (line 2) Every element that is less than 1500 and also at an odd index (line 3) Every odd element that is larger than 1500 (line 4) Note that you...
Write a Java program that will use a two-dimensional array to solve the following tasks: 1....
Write a Java program that will use a two-dimensional array to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5. Create a...
I want the program to use 1- D array and display a table as output. Write...
I want the program to use 1- D array and display a table as output. Write a script to simulate the rolling of two dice. The script should use Math.random to roll the first die and again to roll the second die. The sum of the two values should then be calculated. [Note: Since each die can show an integer value from 1 to 6, the sum of the values will vary from 2 to 12, with 7 being the...
use c++ 1 a)Write a console program that creates an array of size 100 integers. Then...
use c++ 1 a)Write a console program that creates an array of size 100 integers. Then use Fibonacci function Fib(n) to fill up the array with Fib(n) for n = 3 to n = 103: So this means the array looks like: { Fib(3), Fib(4), Fib(5), ...., Fib[102) }. For this part of the assignment, you should first write a recursive Fib(n) function. .For testing, print out the 100 integers. b) For the second part of this assignment, you must...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT