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
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
Build two arrays[ ] (Integer and String) and convert them to two ArrayLists and write two...
Build two arrays[ ] (Integer and String) and convert them to two ArrayLists and write two overloaded generic static search method to find the index locations of a specified value. One of the search methods applies to the array type while the other (overloaded) search method applies to the collection type. Implement the following generic linear search method and write a client program to display results: (Here is the header) public static <E extends Comparable<E>> int search(E[] list, E key)...
1.Write a function which takes a string that contains two words separated by any amount of...
1.Write a function which takes a string that contains two words separated by any amount of whitespace, and returns a string in which the words are swapped around and the whitespace is preserved. Hint: use regular expressions where \s detects the whitespaces in a string. Example: given "Hello     World", return "World         Hello" 2.Pandas exercises: Write a python program using Pandas to create and display a one-dimensional array-like object containing an array of data. Write a python program using Pandas to...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT