Question

Go (programming language) Create a map that uses a string representing a course code as key....

Go (programming language)

Create a map that uses a string representing a course code as key. The value in the map needs to be a structure with basic information about the course. The following main routine:

import "fmt"
    
// Define a suitable structure 

func main() {
        // Create a dynamic map m

        // Add the courses CSI2120 and CSI2110 to the map 

        
        for k, v := range m {
                fmt.Printf("Course Code: %s\n", k)
                fmt.Printf("Number of students: %d\n", v.NStudents)
                fmt.Printf("Professor: %s\n", v.Professor)
                fmt.Printf("Average: %f\n\n", v.Avg)
        }
}

must print:

Course Code: CSI2110
Number of students: 186
Professor: Lang
Average: 79.500000

Course Code: CSI2120
Number of students: 211
Professor: Moura
Average: 81.000000
0 0
Add a comment Improve this question Transcribed image text
Answer #1

package main
import "fmt"
  
// Define a suitable structure
type course struct {
courseCode string
NStudents int
Professor string
Avg float64
}


func main() {
// Create a dynamic map m
var courses = map[string]*course{}

// Add the courses CSI2120 and CSI2110 to the map
courses["CSI2110"] = &course{courseCode: "CSI2110",NStudents: 186,Professor: "Lang",Avg: 79.5}
courses["CSI2120"] = &course{courseCode: "CSI2120",NStudents: 211,Professor: "Moura",Avg: 81}
  

  
for k, v := range courses {
fmt.Printf("Course Code: %s\n", k)
fmt.Printf("Number of students: %d\n", v.NStudents)
fmt.Printf("Professor: %s\n", v.Professor)
fmt.Printf("Average: %f\n\n", v.Avg)
}
}

Add a comment
Know the answer?
Add Answer to:
Go (programming language) Create a map that uses a string representing a course code as key....
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...

    A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...

  • Please use python 3 programming language Write a function that gets a string representing a file...

    Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...

  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS...

    A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...

  • A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 21...

    A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • Java programming course use java import. Follow instructions and comments to explain the code tha...

    java programming course use java import. Follow instructions and comments to explain the code thanks in advance Print L A polymomial can be represented as a linked list, where each node called a polyhede contoins the coefficient and the exponent of a term of the pelynomial For example, The pelynomial 4x-31-5 would be represented as the linked list 3 3xa Write a Polynomial class that has methods for creating a polhynomial, reading and writing a polynomial, and adding a pair...

  • Create C++ program.Convert this string to Tap Code using structures. It is very important to use...

    Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C. The listener only needs to discriminate the timing of the taps to isolate letters. Each letter is communicated by tapping two numbers the first designating the row (Down) the...

  • Overview: In this course, you will be responsible for completing a number of programming-based assignments by...

    Overview: In this course, you will be responsible for completing a number of programming-based assignments by filling in the missing pieces of code. Learning to program in C++ requires developing an understanding of general programming concepts and learning the syntax of the C++ programming language. These exercises will build on each other and help you cultivate you programming knowledge. It is recommended that students do not limit their practice to just that which is graded. The more you write your...

  • Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters repr...

    Create C++ program.Convert this string to Tap Code using structures. It is very important to use structures in this program. The tap code is based on a Polybius square using a 5×5 grid of letters representing all the letters of the Latin alphabet, except for K, which is represented by C. The listener only needs to discriminate the timing of the taps to isolate letters. Each letter is communicated by tapping two numbers the first designating the row (Down) the...

  • Create a hangman program. Sample output from your program should look like the following: Current Status...

    Create a hangman program. Sample output from your program should look like the following: Current Status for userInputs= _ _ _ _ _ _ Enter next letter: a Current Status for userInputs=a _ _ _ _ _ _ Enter next letter: e Current Status for userInputs=ae _ _ _ _ e _ Enter next letter: i Current Status for userInputs=aei _ _ _ _ e _ Enter next letter: o Current Status for userInputs=aeio _ o _ _ e _...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT