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:
Dim forcesN() As Double = {2.4, 3.1, 2.8, 3.7, 3.0} Dim totalN As Double = 0.0 Dim selectedCount As Integer = 0 For i As Integer = 0 To forcesN.Length - 1 Step 2 totalN += forcesN(i) selectedCount += 1 Next Dim meanN As Double = totalN / selectedCount
What value is stored in meanN? Give your answer in newtons, to two decimal places.
Unlock full course notes by signing up
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:
Repairing an averaging routine
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:
Which change fixes both errors while retaining the existing loop bounds?
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.