40210: Given an array temps of Doubles, containing temperature data, compute the average temperature. Store the average in a variable called avgTemp. Besides temps and avgTemp, you may use only two other variables -- an Integer variable k and a Double variable named total, which have been declared.
k = 0
total = 0
Do
total += temps(k)
k += 1
Loop Until (k = temps.length)
avgTemp = total / k
40212: Reversing the elements of an array involves swapping the corresponding elements of the array: the first with the last, the second with the next to last, and so on, all the way to the middle of the array. Given an array a and two other Integer variables, k and temp, write a loop that reverses the elements of the array. Do not use any other variables besides a, k, and temp.
For k = 0 to ((a.length-1)/2)
temp = a(k)
a(k) = a((a.length-1)-k)
a((a.length-1)-k) = temp
Next
40213: Given an Integer variable k, an Integer array currentMembers that has been declared and initialized, an Integer variable memberID that has been initialized, and a Boolean variable isAMember, write code that assigns True to isAMember if the value of memberID can be found in currentMembers, and that assigns false to isAMember otherwise. Use only k, currentMembers, memberID and isAMember.
isAMember = false
k = 0
Do
If memberID = currentMembers(k) Then
isAMember = true
End If
k += 1
Loop Until (k = currentMembers.length)
40214: You are given an Integer variable k, an Integer array zipcodeList that has been declared and initialized, and a Boolean Variable duplicates. Write some code that assigns True to duplicates if there are two adjacent elements in the array that have the same value, and that assigns False to duplicates otherwise. Use only k, zipcodeList, and duplicates.
duplicates = false
k = 0
Do
If zipcodeList(k) = zipcodeList(k+1) Then
duplicates = true
End If
k += 1
Loop Until (k = zipcodeList.length - 1)
40215: You are given two Integer variables j and k, an Integer array zipcodeList that has been declared and initialized, and a Boolean variable duplicates. Write some code that assigns True to duplicates if any two elements in the array have the same value, and that assigns False to duplicates otherwise. Use only j, k, zipcodeList, and duplicates.
duplicates = false
k = 0
j = 0
For k = 0 to zipcodeList.length-1
For j = 0 to zipcodeList.length-1
If (zipcodeList(k) = zipcodeList(j)) And (j<>k) Then
duplicates = true
End If
Next
Next
40216: Given an Integer variable k, an Integer array incompletes that has been declared and initialized, an int variable studenID that has been initialized, and an int variable numberOfIncompletes, write code that counts the number of times the value of studentID appears in incompletes and assigns this value to numberOfIncompletes. You may use only k, incompletes, studentID, and numberOfIncompletes.
numberOfIncompletes = 0
For k = 0 to (incompletes.length-1)
If studentID = incompletes(k) Then
numberOfIncompletes += 1
End If
Next
40219: An array of integers named parking Tickets has been declared and initialized to the number of parking tickets given out by the city police each day since the beginning of the current year. (Thus, the first element of the array contains the number of tickets given on January 1; the last element contains the number of tickets given today.) A variable named mostTickets has been declared, along with a variable k. Without using any additional variables, write some code that results in mostTickets containing the largest value found in parkingTickets.
mostTickets = 0
For k = 0 to (parkingTickets.length-1)
If mostTickets < parkingTickets(k) Then
mostTickets = parkingTickets(k)
End If
Next
you have saved me yet again
ReplyDelete