A Visual Basic .NET program is intended to calculate the arithmetic mean of all four force readings in newtons. Its calculation currently contains two logic errors:
Dim forcesN() As Double = {6.0, 8.0, 10.0, 12.0} Dim totalN As Double For i As Integer = 0 To forcesN.Length - 1 totalN = 0.0 totalN += forcesN(i) Next Dim meanN As Double = totalN / (forcesN.Length - 1)
Which change fixes both errors while retaining the existing loop bounds?
Keep totalN = 0.0 inside the loop and divide by forcesN.Length - 1.
Move totalN = 0.0 before the loop and divide by forcesN.Length - 1.
Keep totalN = 0.0 inside the loop and divide by forcesN.Length.
Move totalN = 0.0 before the loop and divide by forcesN.Length.
Unlock full course notes by signing up
A mean from alternate readings
A Visual Basic .NET program selects every second reading from a force sensor, beginning with the first array element. The following statements execute inside Sub Main:
What value is stored in meanN? Give your answer in newtons, to two decimal places.
Tracing overlapping mode ranges
A test program converts a sensor voltage into a force using a mode-dependent gain. Its Visual Basic function contains a selection block, which chooses a branch using the value of mode. The function is declared inside a module.
For each independent test below, the program obtains the gain from GainFor(mode) and calculates force from:
A mean with rejected readings
Write a Visual Basic .NET function named MeanAcceptedForce with two parameters: a Double array named readingsN, containing forces in newtons, and a Double named limitN, also in newtons.
The function must:
Accept readings from zero through limitN, including both endpoints.
Following copied and referenced command values
A test controller uses the following Visual Basic program to update a force command. All numeric command and increment values represent newtons. In the first call, the same caller variable appears in both argument positions.
Find the values stored in afterFirst and afterSecond when Main finishes. Give each answer in N, to one decimal place.