Graderpractice for programmers

Back to 273387 MAD 63 - C5 Classes

C. Adding grades

Problem

In your Student class, add a new variable called grades which is an array of Float values. In your constructor, set the grades to []. Add two new functions, addGrade will append a Float to the array, and numberOfGrades will return the number of grades in the array. Example:

let peter = Student(id: 5, firstName: "Peter", lastName: "Parker") 
print("Grades: \(peter.numberOfGrades())")    // Prints "Grades: 0"
peter.addGrade(2.95)
peter.addGrade(3.15)
print("Grades: \(peter.numberOfGrades())")    // Prints "Grades: 2"

Examples

Submit your solution

swift