Question
Complete swift program. //structure Course struct Course { let name:String //Name of the course let homework1:Double //Grade of homework 1 let homework2:Double //Grade of homework
Complete swift program.
//structure Course struct Course { let name:String //Name of the course let homework1:Double //Grade of homework 1 let homework2:Double //Grade of homework 2 let midterm:Double //Grade of midterm exam let final:Double //Grade of final exam var FinalGrade:Double { //Final grade get{ //Implement your codes here //Final grade is computed by 20% for each homework, 30% for each exam //change return 0.0 to what you need to return 0.0 } } }
//class Student class Student { var name:String = "" //Student's name var courses:[Course] = [] //Student's courses var MaxGrade:Course? { //The course in array courses which has the maximum Final Grade get { //Implement your codes here //change nil to what you need to return nil } } var MinGrade:Course? { //The course in array courses which has the minimum Final Grade get { //Implement your codes here //change nil to what you need to return nil } } var AvgGrade:Double? { //Return the average final grade of all courses of one student get { //Implement your codes here //change nil to what you need to return nil } } //Bonus 1: Get the average final grade of a specific couse name of all students in array "s" class func getStudentAvgFrom(students s:[Student], andCourse c:String) -> Double { return 0.0 } //Bonus 2: Get the average final grade of all couses of all students in array "s" class func getStudentAvgFrom(students s:[Student]) -> Double { return 0.0 } }
//Don't change the following codes //A list of students var students:[Student] = []
//Information of the first student var student1:Student = Student() student1.name = "Peter" student1.courses.append(Course(name: "Physics", homework1: 88, homework2: 77, midterm: 84, final: 83)) student1.courses.append(Course(name: "Math", homework1: 92, homework2: 93, midterm: 90, final: 96)) student1.courses.append(Course(name: "Mobile Computing", homework1: 96, homework2: 94, midterm: 93, final: 99)) students.append(student1) //Add one student to the list
//Information of the second student var student2:Student = Student() student2.name = "Alice" student2.courses.append(Course(name: "Physics", homework1: 92, homework2: 86, midterm: 83, final: 93)) student2.courses.append(Course(name: "Math", homework1: 91, homework2: 88, midterm: 87, final: 96)) student2.courses.append(Course(name: "Mobile Computing", homework1: 91, homework2: 93, midterm: 88, final: 90)) students.append(student2)
//Information of the third student var student3:Student = Student() student3.name = "Bob" student3.courses.append(Course(name: "Physics", homework1: 66, homework2: 78, midterm: 75, final: 84)) student3.courses.append(Course(name: "Math", homework1: 81, homework2: 82, midterm: 86, final: 88)) student3.courses.append(Course(name: "Mobile Computing", homework1: 97, homework2: 96, midterm: 91, final: 99)) students.append(student3)
//Don't change the following codes print("Total: \(students.count) students")
print("\(student1.name)'s Physics final grade is \(student1.courses[0].FinalGrade)")
if student1.MaxGrade != nil { print("\(student1.MaxGrade!.name) is the best couse of \(student1.name), and its grade is \(student1.MaxGrade!.FinalGrade)") } else { print("Errors occured when getting \(student1.name)'s best course.") }
if student1.MinGrade != nil { print("\(student1.MinGrade!.name) is the worse couse of \(student1.name), and its grade is \(student1.MinGrade!.FinalGrade)") } else { print("Errors occured when getting \(student1.name)'s worse course.") }
if student1.AvgGrade != nil { print("The average final grade of \(student1.name) is \(student1.AvgGrade!)") } else { print("Errors occured when getting \(student1.name)'s average grade.") }
print("Bonus 1: The average grade of Physics of all students is \(Student.getStudentAvgFrom(students: students, andCourse: "Physics"))") print("Bonus 2: The average grade all courses of all students is \(Student.getStudentAvgFrom(students: students))")
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started