Question

The function has five parameters: two arrays of the same length one of string type containing...

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

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT