Graderpractice for programmers

Back to 273387 MAD 2562 - Classes

E. Comparing grades

Problem

Write a function that returns true if the student has a higher average grade than another student given as a parameter.

let peter = Student(id: 5, firstName: "Peter", lastName: "Parker")
peter.addGrade(2.95)
peter.addGrade(3.45) 
let lois = Student(id: 6, firstName: "Lois", lastName: "Lane")
lois.addGrade(4.0)
lois.addGrade(3.2)

if lois.hasHigherAverageThan(peter) { 
    print("\(lois.firstName) beats \(peter.firstName)") 
}                                 // Prints "Lois beats Peter"

Examples

Submit your solution

swift