Graderpractice for programmers

273387 MAD 63 - C5 Classes

Awaiting submission
Create a class called Student that contains a constructor for the following fields:
- id: Int
- firstName: String
- lastName: String
Test that you can create a Student with the code let peter = Student(id: 5, firstName: "Peter", lastName: "Parker") .

Submit your class file only.
Awaiting submission
Add a function to the Student class that returns the full name of the student. Example:
let peter = Student(id: 5, firstName: "Peter", lastName: "Parker") 
print("Name: " + peter.fullName())
Submit only the class file
Awaiting submission
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"
Awaiting submission
Write a function that returns the student's average grade (as a Float).
let peter = Student(id: 5, firstName: "Peter", lastName: "Parker")
peter.addGrade(2.95)
peter.addGrade(3.45)
print("Average: \(peter.average())")    // Prints "Average: 3.2"
Awaiting submission
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"