|
| 1 | +// File Name: Roster.swift |
| 2 | +// Author: Alex DiStasi |
| 3 | +// Date: 3/3/2020 |
| 4 | + |
| 5 | +var spanish101: Set = ["Angela", "Declan", "Aldany", "Alex", "Sonny", "Alif", "Skyla"] |
| 6 | +var german101: Set = ["Angela", "Alex", "Declan", "Kenny", "Cynara", "Adam"] |
| 7 | +var advancedCalculus: Set = ["Cynara", "Gabby", "Angela", "Samantha", "Ana", "Aldany", "Galina", "Jasmine"] |
| 8 | +var artHistory: Set = ["Samantha", "Vanessa", "Aldrian", "Cynara", "Kenny", "Declan", "Skyla"] |
| 9 | +var englishLiterature: Set = ["Gabby", "Jasmine", "Alex", "Alif", "Aldrian", "Adam", "Angela"] |
| 10 | +var computerScience: Set = ["Galina", "Kenny", "Sonny", "Alex", "Skyla"] |
| 11 | + |
| 12 | +// Write your code below 🍎 |
| 13 | + |
| 14 | +// Task Group: Creating a Roster of All Students |
| 15 | +// Create a set of all students enrolled in at least 1 class |
| 16 | +var allStudents = spanish101.union(german101) |
| 17 | +allStudents = allStudents.union(advancedCalculus) |
| 18 | +allStudents = allStudents.union(artHistory) |
| 19 | +allStudents = allStudents.union(englishLiterature) |
| 20 | +allStudents = allStudents.union(computerScience) |
| 21 | + |
| 22 | +// Print each student Name |
| 23 | +for student in allStudents { |
| 24 | + print(student) |
| 25 | +} |
| 26 | + |
| 27 | +// Print the total number of students |
| 28 | +print("Total number of students: \(allStudents.count)") |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +// Task Group: Language Classes |
| 33 | + |
| 34 | +// Students taking no language class |
| 35 | +var spanishAndGerman = spanish101.union(german101) |
| 36 | +var noLanguages = allStudents.subtracting(spanishAndGerman) |
| 37 | +print("Students taking no languages: \(noLanguages)") |
| 38 | + |
| 39 | +// Students taking Spanish101 OR German101, but not both |
| 40 | +var oneLanguage = spanish101.symmetricDifference(german101) |
| 41 | +print("Students taking only one lanuage: \(oneLanguage)") |
| 42 | + |
| 43 | +// Students taking Spanish101, German101, and English Literature |
| 44 | +var languageAwardWinners = spanish101.intersection(german101).intersection(englishLiterature) |
| 45 | +print("Language award winners: \(languageAwardWinners)") |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +// Task Group: Class Size |
| 50 | + |
| 51 | +var sevenPlus = 0 |
| 52 | + |
| 53 | +// Create a set that contains sets |
| 54 | +var classSet: Set = [spanish101, german101, englishLiterature, computerScience, artHistory, advancedCalculus] |
| 55 | + |
| 56 | +// Loop through classSet to find which sets have >= 7 students |
| 57 | +for aClass in classSet { |
| 58 | + if aClass.count >= 7 { |
| 59 | + sevenPlus += 1 |
| 60 | + } |
| 61 | +} |
| 62 | +print ("There are \(sevenPlus) classes with seven or more students.") |
| 63 | + |
0 commit comments