In: Computer Science
USE VISUAL STUDIO/VB
In this assignment, you will create an array of ten elements, one for name, one for hours worked,and the last for hourly rate. The arrays will receive the information from inputs from the screen.For example, you will ask the following three questions:
a) Employee name:
b) Hours worked:
c) Hourly rate:
After you have received all ten records and have inserted them into the array, you will then calculate the hourly rate times the hours worked to get gross pay. You will need to calculate overtime if they work more than 40 hours that week. Overtime will be 1.5 per hour over. These calculations should be done in a subroutine. After each calculation, you will print the employee’s name, the hours worked, the rate per hour and the total pay for the week.
Hints: You will need to create three arrays:
a) Dim name() as Char
b) Dim hoursworked() as Double
c) Dim rate() as Double
You will also need for loops to read the information into the array and to write the information to the screen. For example:
a) For I = 0 To 9
console.write(“Enter employee name: ”)
name(I) = console.readln()
next
You will also use a for loop to write the information in the array back out to the screen.
You will also need to create a subroutine to calculate pay. In order to do this, you will need to pass the arrays through the subroutine call. For example you will have two subroutines. One for employees who work 40 hours or less and one for employees who work more than forty hours:
a) Subroutine1 is called regularpay(ByVal array1() as double, ByVal array2() as double,ByVal I as integer)
* Calculation used for this subroutine is as follows: Total = array1 (I) * array2 (I)
b) Subroutine2 is called overtimepay(ByVal array1() as double, ByVal array2() as double,ByVal I as integer)
* Calculation used for this subroutine is a bit more complex, but is as follows: Total= (40 * array2(I)) + ((array1(I) -40)*array2(I)*1.5)
* Return value back to main program.
VB Code:
Module Module1
Sub Main()
'arrays to store employee data
Dim name() As String = New String(10) {}
Dim hoursworked() As Double = New Double(10) {}
Dim rate() As Double = New Double(10) {}
For I = 0 To 9
Console.Write(“Employee ” + Convert.ToString(I + 1) +
Constants.vbCrLf)
'getting data from the user
Console.Write(“Enter employee name: ”)
name(I) = Console.ReadLine()
Console.Write(“Enter hours worked: ”)
hoursworked(I) = Console.ReadLine()
Console.Write(“Enter hourly rate: ”)
rate(I) = Console.ReadLine()
Console.Write(Constants.vbCrLf)
Next
'outputing the data
Console.Write(Constants.vbCrLf + "Output: ” +
Constants.vbCrLf)
For I = 0 To 9
Console.Write(“Employee ” + Convert.ToString(I + 1) +
Constants.vbCrLf)
Console.Write(“Employee name: ” + name(I) + Constants.vbCrLf)
Console.Write(“Hours worked: ” + Convert.ToString(hoursworked(I)) +
Constants.vbCrLf)
Console.Write(“Hourly rate: ” + Convert.ToString(rate(I)) +
Constants.vbCrLf)
Console.Write(“Gross pay: ”)
'checking if hours worked is greater than 40
If hoursworked(I) > 40 Then
Console.Write(Convert.ToString(overtimepay(hoursworked, rate, I)) +
Constants.vbCrLf)
Else
Console.Write(Convert.ToString(regularpay(hoursworked, rate, I)) +
Constants.vbCrLf)
End If
Console.Write(Constants.vbCrLf + Constants.vbCrLf)
Next
End Sub
'sub routines
Function regularpay(ByVal array1() As Double, ByVal array2() As
Double, ByVal I As Integer)
Dim Total As Double
'calclating regular pay
Total = array1(I) * array2(I)
Return Total
End Function
Function overtimepay(ByVal array1() As Double, ByVal array2() As
Double, ByVal I As Integer)
Dim Total As Double
'calculating gross pay
Total = (40 * array2(I)) + ((array1(I) - 40) * array2(I) *
1.5)
Return Total
End Function
End Module
Sample Output:
Employee 1
Enter employee name: emp1
Enter hours worked: 50
Enter hourly rate: 10
Employee 2
Enter employee name: emp2
Enter hours worked: 35
Enter hourly rate: 10
Employee 3
Enter employee name: emp3
Enter hours worked: 40
Enter hourly rate: 15
Employee 4
Enter employee name: emp4
Enter hours worked: 41
Enter hourly rate: 15
Employee 5
Enter employee name: emp5
Enter hours worked: 30
Enter hourly rate: 20
Employee 6
Enter employee name: emp6
Enter hours worked: 30
Enter hourly rate: 15
Employee 7
Enter employee name: emp7
Enter hours worked: 36
Enter hourly rate: 20
Employee 8
Enter employee name: emp8
Enter hours worked: 50
Enter hourly rate: 20
Employee 9
Enter employee name: emp9
Enter hours worked: 50
Enter hourly rate: 18
Employee 10
Enter employee name: emp10
Enter hours worked: 45
Enter hourly rate: 10
Output:
Employee 1
Employee name: emp1
Hours worked: 50
Hourly rate: 10
Gross pay: 550
Employee 2
Employee name: emp2
Hours worked: 35
Hourly rate: 10
Gross pay: 350
Employee 3
Employee name: emp3
Hours worked: 40
Hourly rate: 15
Gross pay: 600
Employee 4
Employee name: emp4
Hours worked: 41
Hourly rate: 15
Gross pay: 622.5
Employee 5
Employee name: emp5
Hours worked: 30
Hourly rate: 20
Gross pay: 600
Employee 6
Employee name: emp6
Hours worked: 30
Hourly rate: 15
Gross pay: 450
Employee 7
Employee name: emp7
Hours worked: 36
Hourly rate: 20
Gross pay: 720
Employee 8
Employee name: emp8
Hours worked: 50
Hourly rate: 20
Gross pay: 1100
Employee 9
Employee name: emp9
Hours worked: 50
Hourly rate: 18
Gross pay: 990
Employee 10
Employee name: emp10
Hours worked: 45
Hourly rate: 10
Gross pay: 475