diff --git a/Git_ Exercise.xcodeproj/project.pbxproj b/Git_ Exercise.xcodeproj/project.pbxproj index 424a5e0..945cc85 100644 --- a/Git_ Exercise.xcodeproj/project.pbxproj +++ b/Git_ Exercise.xcodeproj/project.pbxproj @@ -8,6 +8,13 @@ /* Begin PBXBuildFile section */ 2768CA08294F453B00990B98 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2768CA07294F453B00990B98 /* main.swift */; }; + 90D3F153294FFCB300CEA3F8 /* Modules.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90D3F152294FFCB300CEA3F8 /* Modules.swift */; }; + 90D3F156294FFFA200CEA3F8 /* AddStudent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90D3F155294FFFA200CEA3F8 /* AddStudent.swift */; }; + 90D3F15C294FFFC600CEA3F8 /* UpdateGrade.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90D3F157294FFFC500CEA3F8 /* UpdateGrade.swift */; }; + 90D3F15D294FFFC600CEA3F8 /* DeleteStudent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90D3F158294FFFC500CEA3F8 /* DeleteStudent.swift */; }; + 90D3F15E294FFFC600CEA3F8 /* Exit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90D3F159294FFFC600CEA3F8 /* Exit.swift */; }; + 90D3F15F294FFFC600CEA3F8 /* RemoveGrade.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90D3F15A294FFFC600CEA3F8 /* RemoveGrade.swift */; }; + 90D3F160294FFFC600CEA3F8 /* ReportCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90D3F15B294FFFC600CEA3F8 /* ReportCard.swift */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -25,6 +32,13 @@ /* Begin PBXFileReference section */ 2768CA04294F453B00990B98 /* Git_ Exercise */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "Git_ Exercise"; sourceTree = BUILT_PRODUCTS_DIR; }; 2768CA07294F453B00990B98 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + 90D3F152294FFCB300CEA3F8 /* Modules.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modules.swift; sourceTree = ""; }; + 90D3F155294FFFA200CEA3F8 /* AddStudent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddStudent.swift; sourceTree = ""; }; + 90D3F157294FFFC500CEA3F8 /* UpdateGrade.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateGrade.swift; sourceTree = ""; }; + 90D3F158294FFFC500CEA3F8 /* DeleteStudent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeleteStudent.swift; sourceTree = ""; }; + 90D3F159294FFFC600CEA3F8 /* Exit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Exit.swift; sourceTree = ""; }; + 90D3F15A294FFFC600CEA3F8 /* RemoveGrade.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoveGrade.swift; sourceTree = ""; }; + 90D3F15B294FFFC600CEA3F8 /* ReportCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReportCard.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -57,11 +71,34 @@ 2768CA06294F453B00990B98 /* Git_ Exercise */ = { isa = PBXGroup; children = ( + 90D3F154294FFF8000CEA3F8 /* Utils */, + 90D3F151294FFCA200CEA3F8 /* Modules */, 2768CA07294F453B00990B98 /* main.swift */, ); path = "Git_ Exercise"; sourceTree = ""; }; + 90D3F151294FFCA200CEA3F8 /* Modules */ = { + isa = PBXGroup; + children = ( + 90D3F152294FFCB300CEA3F8 /* Modules.swift */, + ); + path = Modules; + sourceTree = ""; + }; + 90D3F154294FFF8000CEA3F8 /* Utils */ = { + isa = PBXGroup; + children = ( + 90D3F155294FFFA200CEA3F8 /* AddStudent.swift */, + 90D3F158294FFFC500CEA3F8 /* DeleteStudent.swift */, + 90D3F159294FFFC600CEA3F8 /* Exit.swift */, + 90D3F15A294FFFC600CEA3F8 /* RemoveGrade.swift */, + 90D3F15B294FFFC600CEA3F8 /* ReportCard.swift */, + 90D3F157294FFFC500CEA3F8 /* UpdateGrade.swift */, + ); + path = Utils; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -120,7 +157,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 90D3F15F294FFFC600CEA3F8 /* RemoveGrade.swift in Sources */, + 90D3F160294FFFC600CEA3F8 /* ReportCard.swift in Sources */, 2768CA08294F453B00990B98 /* main.swift in Sources */, + 90D3F15E294FFFC600CEA3F8 /* Exit.swift in Sources */, + 90D3F153294FFCB300CEA3F8 /* Modules.swift in Sources */, + 90D3F15D294FFFC600CEA3F8 /* DeleteStudent.swift in Sources */, + 90D3F15C294FFFC600CEA3F8 /* UpdateGrade.swift in Sources */, + 90D3F156294FFFA200CEA3F8 /* AddStudent.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Git_ Exercise.xcodeproj/project.xcworkspace/xcuserdata/bagjaeu.xcuserdatad/UserInterfaceState.xcuserstate b/Git_ Exercise.xcodeproj/project.xcworkspace/xcuserdata/bagjaeu.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..a6edea9 Binary files /dev/null and b/Git_ Exercise.xcodeproj/project.xcworkspace/xcuserdata/bagjaeu.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/Git_ Exercise.xcodeproj/xcuserdata/bagjaeu.xcuserdatad/xcschemes/xcschememanagement.plist b/Git_ Exercise.xcodeproj/xcuserdata/bagjaeu.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..9cab2b7 --- /dev/null +++ b/Git_ Exercise.xcodeproj/xcuserdata/bagjaeu.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + Git_ Exercise.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/Git_ Exercise/Modules/Modules.swift b/Git_ Exercise/Modules/Modules.swift new file mode 100644 index 0000000..9966f62 --- /dev/null +++ b/Git_ Exercise/Modules/Modules.swift @@ -0,0 +1,91 @@ +// +// Modules.swift +// Git_ Exercise +// +// Created by 박재우 on 2022/12/19. +// + +import Foundation + +typealias Student = String + +class Management { + var students: [Student: [ReportCard]] = [:] +} + +struct ReportCard { + var subject: String + var grade: String +} + +enum Pattern: String { + case input = "^[0-9a-zA-Z+]*$" +} + +enum Score: Double { + case APlus = 4.5 + case AZero = 4.0 + case BPlus = 3.5 + case BZero = 3.0 + case CPlus = 2.5 + case CZero = 2.0 + case DPlus = 1.5 + case DZero = 1.0 + case F = 0.0 +} + +enum Grade: String { + case APlus = "A+" + case AZero = "A0" + case BPlus = "B+" + case BZero = "B0" + case CPlus = "C+" + case CZero = "C0" + case DPlus = "D+" + case DZero = "D0" + case F = "F" +} + +enum Commands: String { + case addStudent = "1" + case deleteStudent = "2" + case updateGrade = "3" + case removeGrade = "4" + case reportCard = "5" + case exit = "X" +} + +enum Errors: String { + case main = "뭔가 입력이 잘못되었습니다. 1~5 사이의 숫자 혹은 X를 입력해주세요." + case input = "입력이 잘못되었습니다. 다시 확인해주세요." + case containStudent = "은 이미 존재하는 학생입니다. 추가하지 않습니다." + case searchStudent = " 학생을 찾지 못했습니다." + case searchSubject = " 과목을 찾지 못했습니다." +} + +enum Questions: String { + case main = "원하는 기능을 입력해주세요\n1: 학생추가, 2: 학생삭제, 3: 성적추가(변경), 4: 성적삭제, 5: 평점보기, X: 종료" + case addStudent = "추가할 학생의 이름을 입력해주세요." + case deleteStudent = "삭제할 학생의 이름을 입력해주세요" + case updateGrade = "성적을 추가할 학생의 이름, 과목 이름, 성적(A+, A0, F 등)을 띄어쓰기로 구분하여 차례로 작성해주세요." + case removeGrade = "성적을 삭제할 학생의 이름, 과목 이름을 띄어쓰기로 구분하여 차례로 작성해주세요." + case reportCard = "평점을 알고 싶은 학생의 이름을 입력해주세요" +} + +class Operations { + func addStudent(_ student: Student) { + print("\(student) 학생을 추가했습니다.") + } + func deleteStudent(_ student: Student) { + print("\(student) 학생을 삭제하였습니다.") + } + func updateGrade(_ reportCard: ReportCard, of student: Student) { + print("\(student) 학생의 \(reportCard.subject) 과목이 \(reportCard.grade)로 추가(변경)되었습니다.") + } + func removeGrade(_ subject: String, of student: Student) { + print("\(student) 학생의 \(subject) 과목의 성적이 삭제되었습니다.") + } + var exit: String { + return "프로그램을 종료합니다..." + } +} diff --git a/Git_ Exercise/Utils/AddStudent.swift b/Git_ Exercise/Utils/AddStudent.swift new file mode 100644 index 0000000..343f0a6 --- /dev/null +++ b/Git_ Exercise/Utils/AddStudent.swift @@ -0,0 +1,25 @@ +// +// AddStudent.swift +// Git_ Exercise +// +// Created by 박재우 on 2022/12/19. +// + +import Foundation + +func addStudent() { + print(Questions.addStudent.rawValue) + guard let student = readLine() else { return } + guard let _ = student.range(of: Pattern.input.rawValue, options: .regularExpression), + student.isEmpty == false else { + print(Errors.input.rawValue) + return + } + let isContain = manager.contains { $0.key == student } + guard isContain == false else { + print("\(student)\(Errors.containStudent.rawValue)") + return + } + manager[student] = [] + Operations().addStudent(student) +} diff --git a/Git_ Exercise/Utils/DeleteStudent.swift b/Git_ Exercise/Utils/DeleteStudent.swift new file mode 100644 index 0000000..1a2b46f --- /dev/null +++ b/Git_ Exercise/Utils/DeleteStudent.swift @@ -0,0 +1,25 @@ +// +// DeleteStudent.swift +// GradeManagement +// +// Created by 박재우 on 2022/12/19. +// + +import Foundation + +func deleteStudent() { + print(Questions.deleteStudent.rawValue) + guard let student = readLine() else { return } + guard let _ = student.range(of: Pattern.input.rawValue, options: .regularExpression), + student.isEmpty == false else { + print(Errors.input.rawValue) + return + } + let isContain = manager.contains { $0.key == student } + guard isContain else { + print("\(student)\(Errors.searchStudent.rawValue)") + return + } + manager.removeValue(forKey: student) + Operations().deleteStudent(student) +} diff --git a/Git_ Exercise/Utils/Exit.swift b/Git_ Exercise/Utils/Exit.swift new file mode 100644 index 0000000..38a5f0c --- /dev/null +++ b/Git_ Exercise/Utils/Exit.swift @@ -0,0 +1,12 @@ +// +// Exit.swift +// GradeManagement +// +// Created by 박재우 on 2022/12/19. +// + +import Foundation + +func exit() { + print(Operations().exit) +} diff --git a/Git_ Exercise/Utils/RemoveGrade.swift b/Git_ Exercise/Utils/RemoveGrade.swift new file mode 100644 index 0000000..40e1536 --- /dev/null +++ b/Git_ Exercise/Utils/RemoveGrade.swift @@ -0,0 +1,41 @@ +// +// RemoveGrade.swift +// GradeManagement +// +// Created by 박재우 on 2022/12/19. +// + +import Foundation + +func removeGrade() { + print(Questions.removeGrade.rawValue) + guard let answer = readLine() else { return } + var inputs = answer.components(separatedBy: " ") + guard 2 == inputs.count else { + print(Errors.input.rawValue) + return + } + for input in inputs { + guard let _ = input.range(of: Pattern.input.rawValue, options: .regularExpression), + input.isEmpty == false else { + print(Errors.input.rawValue) + return + } + } + let student = inputs.removeFirst() + let isStudent = manager.contains { $0.key == student } + guard isStudent else { + print("\(student)\(Errors.searchStudent.rawValue)") + return + } + let subject = inputs.removeFirst() + guard let reports = manager[student] else {return} + for index in 0..