Read the problem carefully, study the pseudocode and add the missing code: Probl
ID: 3841088 • Letter: R
Question
Read the problem carefully, study the pseudocode and add the missing code:
Problem:
Consider a grade-averaging scheme in which the final average of a student’s scores is computed differently from the traditional average if the scores have “improved.” Scores have improved if each score is greater than or equal to the previous score. The final average of the scores is computed as follows.
A student has n scores indexed from 0 to n-1. If the scores have improved, only those scores with indexes greater than or equal to n/2 are averaged. If the scores have not improved, all the scores are averaged.
The following table shows several lists of scores and how they would be averaged using the scheme described above.
Student Scores Improved? Final Average
50, 50, 20, 80, 53 No (50 + 50 + 20 + 80 + 53) / 5.0 = 50.6
20, 50, 50, 53, 80 Yes (50 + 53 + 80) / 3.0 = 61.0
20, 50, 50, 80 Yes (50 + 80) / 2.0 = 65.0
Given an array named 'scores', already populated with a number of scores (as provided by property/variable 'length'), create pseudocode for the following methods/functions (use suggested variable names if provided):
(a). finalAverage: method/function uses (b) and (c) to return either average scheme as described above
(b). average: method/function returns the average of the values in scores given a starting ('first') and an ending ('last') index.
(c). hasImproved: method/function returns TRUE if the score sequence has improved (successive values in scores greater than or equal to the previous value), otherwise return FALSE
To do:
Complete the function definition 'hasImproved'
Follow the general conventions of this pseudocode or use the language from this course.
------------------------------------------------------------------------------------------------------------
//hasImproved definition
hasImproved input: scores as type array of int, length as type int
output: type boolean
// complete this pseudocode ...
Explanation / Answer
PSEUDOCODE:
hasImproved input: scores as type array of int, length as type int
output: type boolean
loop with index starting at 1 and ending at length-1
if scores[index] < socres[index-1] //checking if the previous score is larger than the current one
return FALSE
return TRUE // return false when the control is out of the loop
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.