Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The function has five parameters: two arrays of the same length one of string ty

ID: 3862666 • Letter: T

Question

The function has five parameters: two arrays of the same length one of string type containing names and other of integer type containing scores, the size of the arrays of integer type, minimum score of integer type and a maximum score of integer type (all parameters are in the same order). The function should print all the names and score of the students who achieved a score within the given range (between max_score and min_score including both).

Example:

names array = {"William", "Martin", "Keith", "Larry", "Ryan"}

scores array = {69,66,87,90,78}

size = 5

min_score = 75

max_score = 90

Output:

Keith, 87

Larry, 90

Ryan, 78

Explanation / Answer

Answer:

Since its not mentioned in the question the programming language in which the answer is required, I'll be answering in Java.

public void score_range(String[] names, int[] scores, int size, int min_score, int max_score){
   //HashMap to store the result of students and their respective scores
   HashMap<String, Integer> studentMap = new HashMap<>();
   for(int i=0; i<size; i++){
   if(scores[i] >= min_score && scores[i] <= max_score){
   studentMap.put(names[i], scores[i]);
   }
   }
   //iterator to iterate over the hashmap
   Iterator it = studentMap.entrySet().iterator();
   while(it.hasNext()){
Map.Entry pair = (Map.Entry)it.next();
System.out.println(pair.getKey()+","+pair.getValue());
it.remove();
   }
   }

OUTPUT:

Keith,87
Ryan,78
Larry,90

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote