Sort Student Grades Dynamically

GolangBeginner
Practice Now

Introduction

In this challenge, you will create a Go program that manages student grades using a map and implement sorting of the grades in ascending order using the sort.Slice() function. The program should display the sorted student names and grades.

Sort Student Grades Dynamically

In a school management system, efficiently sorting and displaying student grades is crucial for quick performance analysis and reporting.

Tasks

  • Create a Go program that manages student grades using a map
  • Implement sorting of student grades in ascending order using sort.Slice()
  • Display sorted student grades with their names

Requirements

  • Create a file named student_grades.go in the ~/project directory
  • Use a map to store student names as keys and grades as values
  • Use sort.Slice() function to sort the grades
  • Print sorted student names and grades in ascending order
  • Use at least 5 different student entries

Examples

Run the program:

go run student_grades.go

Example output:

Charlie: 78
Alice: 85
Emma: 88
Bob: 92
David: 95

Hints

  • Use a struct to store key-value pairs from the map
  • Remember to import the sort package
  • Use an anonymous function in sort.Slice() for comparison

Summary

In summary, this challenge requires you to create a Go program that manages student grades using a map, implement sorting of the grades in ascending order using the sort.Slice() function, and display the sorted student names and grades. The program should handle at least 5 different student entries.

✨ Check Solution and Practice