Advertisement
Hiteshw11

Write a Dart function that takes a map of student names and their grades, and returns a new map with

Nov 19th, 2024
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.86 KB | Source Code | 0 0
  1. /*Grading scale:
  2.  
  3. A: 90-100
  4.  
  5. B: 80-89
  6.  
  7. C: 70-79
  8.  
  9. D: 60-69
  10.  
  11. F: Below 60
  12.  
  13. Example Input:
  14.  
  15. dart
  16. {'Alice': 85, 'Bob': 92, 'Charlie': 78, 'Diana': 89}
  17. Expected Output:
  18.  
  19. dart
  20. {'Alice': 'B', 'Bob': 'A', 'Charlie': 'C', 'Diana': 'B'}
  21. */
  22.  
  23. void main() {
  24.   Map<String, int> grades = {
  25.     'Alice': 85,
  26.     'Bob': 92,
  27.     'Charlie': 78,
  28.     'Diana': 89
  29.   };
  30.  
  31.  
  32.   Map<String,String> mapOne={};
  33.  
  34.   for(MapEntry<String,int> e in grades.entries)
  35.   {
  36.     if(e.value>=90)
  37.     {
  38.       mapOne[e.key]='A';
  39.      
  40.     }
  41.    
  42.     if(e.value>=80 && e.value<90)
  43.     {
  44.        mapOne[e.key]='B';
  45.     }
  46.    
  47.     if(e.value>=70 && e.value<80)
  48.     {
  49.        mapOne[e.key]='C';
  50.     }
  51.    
  52.     if(e.value>=60 && e.value<70)
  53.     {
  54.        mapOne[e.key]='D';
  55.     }
  56.     if(e.value<60)
  57.     {
  58.       mapOne[e.key]='F';
  59.     }
  60.   }
  61.   print(mapOne);
  62.  
  63.  
  64. }
  65.  
Tags: dart
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement