diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..6b1af1d Binary files /dev/null and b/.DS_Store differ diff --git a/MyCreditManager_2_wogur1212.xcodeproj/project.pbxproj b/MyCreditManager_2_wogur1212.xcodeproj/project.pbxproj new file mode 100644 index 0000000..40917fd --- /dev/null +++ b/MyCreditManager_2_wogur1212.xcodeproj/project.pbxproj @@ -0,0 +1,285 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + E32900772A91675D002E8EB4 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = E32900762A91675D002E8EB4 /* main.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + E32900712A91675D002E8EB4 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + E32900732A91675D002E8EB4 /* MyCreditManager_2_wogur1212 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = MyCreditManager_2_wogur1212; sourceTree = BUILT_PRODUCTS_DIR; }; + E32900762A91675D002E8EB4 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + E32900702A91675D002E8EB4 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + E329006A2A91675D002E8EB4 = { + isa = PBXGroup; + children = ( + E32900752A91675D002E8EB4 /* MyCreditManager_2_wogur1212 */, + E32900742A91675D002E8EB4 /* Products */, + ); + sourceTree = ""; + }; + E32900742A91675D002E8EB4 /* Products */ = { + isa = PBXGroup; + children = ( + E32900732A91675D002E8EB4 /* MyCreditManager_2_wogur1212 */, + ); + name = Products; + sourceTree = ""; + }; + E32900752A91675D002E8EB4 /* MyCreditManager_2_wogur1212 */ = { + isa = PBXGroup; + children = ( + E32900762A91675D002E8EB4 /* main.swift */, + ); + path = MyCreditManager_2_wogur1212; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + E32900722A91675D002E8EB4 /* MyCreditManager_2_wogur1212 */ = { + isa = PBXNativeTarget; + buildConfigurationList = E329007A2A91675D002E8EB4 /* Build configuration list for PBXNativeTarget "MyCreditManager_2_wogur1212" */; + buildPhases = ( + E329006F2A91675D002E8EB4 /* Sources */, + E32900702A91675D002E8EB4 /* Frameworks */, + E32900712A91675D002E8EB4 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = MyCreditManager_2_wogur1212; + productName = MyCreditManager_2_wogur1212; + productReference = E32900732A91675D002E8EB4 /* MyCreditManager_2_wogur1212 */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + E329006B2A91675D002E8EB4 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1430; + LastUpgradeCheck = 1430; + TargetAttributes = { + E32900722A91675D002E8EB4 = { + CreatedOnToolsVersion = 14.3.1; + }; + }; + }; + buildConfigurationList = E329006E2A91675D002E8EB4 /* Build configuration list for PBXProject "MyCreditManager_2_wogur1212" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = E329006A2A91675D002E8EB4; + productRefGroup = E32900742A91675D002E8EB4 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + E32900722A91675D002E8EB4 /* MyCreditManager_2_wogur1212 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + E329006F2A91675D002E8EB4 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E32900772A91675D002E8EB4 /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + E32900782A91675D002E8EB4 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 13.3; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + E32900792A91675D002E8EB4 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 13.3; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + E329007B2A91675D002E8EB4 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + E329007C2A91675D002E8EB4 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + E329006E2A91675D002E8EB4 /* Build configuration list for PBXProject "MyCreditManager_2_wogur1212" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E32900782A91675D002E8EB4 /* Debug */, + E32900792A91675D002E8EB4 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + E329007A2A91675D002E8EB4 /* Build configuration list for PBXNativeTarget "MyCreditManager_2_wogur1212" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E329007B2A91675D002E8EB4 /* Debug */, + E329007C2A91675D002E8EB4 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = E329006B2A91675D002E8EB4 /* Project object */; +} diff --git a/MyCreditManager_2_wogur1212.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/MyCreditManager_2_wogur1212.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/MyCreditManager_2_wogur1212.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/MyCreditManager_2_wogur1212.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/MyCreditManager_2_wogur1212.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/MyCreditManager_2_wogur1212.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/MyCreditManager_2_wogur1212.xcodeproj/project.xcworkspace/xcuserdata/jaehyeoksim.xcuserdatad/UserInterfaceState.xcuserstate b/MyCreditManager_2_wogur1212.xcodeproj/project.xcworkspace/xcuserdata/jaehyeoksim.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..488878a Binary files /dev/null and b/MyCreditManager_2_wogur1212.xcodeproj/project.xcworkspace/xcuserdata/jaehyeoksim.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MyCreditManager_2_wogur1212.xcodeproj/xcuserdata/jaehyeoksim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/MyCreditManager_2_wogur1212.xcodeproj/xcuserdata/jaehyeoksim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..6db6856 --- /dev/null +++ b/MyCreditManager_2_wogur1212.xcodeproj/xcuserdata/jaehyeoksim.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,6 @@ + + + diff --git a/MyCreditManager_2_wogur1212.xcodeproj/xcuserdata/jaehyeoksim.xcuserdatad/xcschemes/xcschememanagement.plist b/MyCreditManager_2_wogur1212.xcodeproj/xcuserdata/jaehyeoksim.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..629be99 --- /dev/null +++ b/MyCreditManager_2_wogur1212.xcodeproj/xcuserdata/jaehyeoksim.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + MyCreditManager_2_wogur1212.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/MyCreditManager_2_wogur1212/main.swift b/MyCreditManager_2_wogur1212/main.swift new file mode 100644 index 0000000..b52e04c --- /dev/null +++ b/MyCreditManager_2_wogur1212/main.swift @@ -0,0 +1,213 @@ +import Foundation + +class Student: Codable { + var name: String + var grade: [String: String]! + + init(name: String) { + self.name = name + self.grade = [:] + } + + func average() -> Double { + var totalScore = 0.0 + let totalSubjects = Double(grade.count) + + for total in grade.values { + switch total { + case "A+": + totalScore += 4.5 + case "A0": + totalScore += 4.0 + case "B+": + totalScore += 3.5 + case "B0": + totalScore += 3.0 + case "C+": + totalScore += 2.5 + case "C0": + totalScore += 2.0 + case "D+": + totalScore += 1.5 + case "D0": + totalScore += 1.0 + case "F": + totalScore += 0.0 + default: + break + } + } + let average = totalScore / totalSubjects + let finalAverage = round(average * 100)/100 + return finalAverage + } +} + +// 메뉴의 기능 모음 +class MenuFunction { + static func menuSelect() -> String { + let number = readLine() + var userSelect = String() + if let userInput = number { + userSelect = userInput + } + return userSelect + } + + static func addName() { + let inputName = readLine()?.trimmingCharacters(in: .whitespacesAndNewlines) + if let studentName = inputName { + if studentName.isEmpty { + print("입력이 잘못되었습니다. 다시 확인해주세요.") + } else if students[studentName] != nil { + print("\(studentName)은 이미 존재하는 학생입니다. 추가하지 않습니다.") + } else { + students[studentName] = Student(name: studentName) + print("\(studentName) 학생을 추가했습니다.") + } + } + } + + static func deleteStudent() { + let inputName = readLine()?.trimmingCharacters(in: .whitespacesAndNewlines) + if let studentName = inputName, !studentName.isEmpty { + if let student = students[studentName] { + students.removeValue(forKey: studentName) + print("\(student.name) 학생을 삭제하였습니다.") + } else { + print("\(studentName) 학생을 찾지 못했습니다.") + } + } else { + print("입력이 잘못되었습니다. 다시 확인해주세요.") + } + } + + static func addScore() { + let userInput = readLine() + var nameSubjectScore = Array() + if let studentInfo = userInput { + nameSubjectScore = studentInfo.components(separatedBy: " ") + + if nameSubjectScore.count != 3 { + print("입력이 잘못되었습니다. 다시 확인해주세요.") + } else if let student = students[nameSubjectScore[0]] { + student.grade[nameSubjectScore[1]] = nameSubjectScore[2] + print("\(nameSubjectScore[0]) 학생의 \(nameSubjectScore[1]) 과목 성적이 추가(변경)되었습니다.") + } else { + print("\(nameSubjectScore[0]) 학생은 등록되지 않았습니다. 성적을 추가할 수 없습니다.") + } + } + } + + static func deleteScore() { + let userInput = readLine() + if let studentInfo = userInput?.trimmingCharacters(in: .whitespacesAndNewlines) { + let nameSubjectScore = studentInfo.components(separatedBy: " ") + + if nameSubjectScore.isEmpty || nameSubjectScore.count != 2 { + print("입력이 잘못되었습니다. 다시 확인해주세요.") + } else if let student = students[nameSubjectScore[0]] { + if student.grade[nameSubjectScore[1]] == nil { + print("\(nameSubjectScore[1]) 과목의 성적이 존재하지 않습니다.") + }else { + student.grade.removeValue(forKey: nameSubjectScore[1]) + print("\(nameSubjectScore[0]) 학생의 \(nameSubjectScore[1]) 과목의 성적이 삭제 되었습니다") + } + } else { + print("\(nameSubjectScore[0]) 학생을 찾지 못했습니다.") + } + } + } + + static func showAverage() { + let userInput = readLine() + if let name = userInput?.trimmingCharacters(in: .whitespacesAndNewlines), !name.isEmpty { + if let student = students[name] { + if student.grade.isEmpty { + print("\(name) 학생의 성적이 없습니다.") + } else { + for (subject, score) in student.grade { + print("\(subject): \(score)") + } + print("평점: \(student.average())") + } + } else { + print("\(name) 학생을 찾지 못했습니다.") + } + } else { + print("입력이 잘못되었습니다. 다시 확인해주세요.") + } + } +} + +var students: [String: Student] = [:] + +// students파일 저장 및 불러오기 +func saveStudentsFile() { + if let documentURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first { + let fileURL = documentURL.appendingPathComponent("students_data.plist") + + do { + let data = try PropertyListEncoder().encode(students) + try data.write(to: fileURL) + } catch let error { + print("저장 실패: \(error)") + } + } +} + +func loadStudentsFile() { + if let documentURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first { + let fileURL = documentURL.appendingPathComponent("students_data.plist") + + do { + let data = try Data(contentsOf: fileURL) + let loadedStudents = try PropertyListDecoder().decode([String: Student].self, from: data) + students = loadedStudents + } catch let error { + print("불러오기 실패: \(error)") + } + } +} + + +func main() { + loadStudentsFile() + + menu: while true { + print(""" + 원하는 기능을 입력해 주세요 + 1: 학생추가, 2: 학생삭제, 3: 성적추가(변경), 4: 성적삭제, 5: 평점보기, X: 종료) + """) + let menuSelect = MenuFunction.menuSelect() + switch menuSelect { + case "1": + print("추가할 학생의 이름을 입력해주세요") + MenuFunction.addName() + case "2": + print("삭제할 학생의 이름을 입력해주세요") + MenuFunction.deleteStudent() + case "3": + print(""" + 성적을 추가할 학생의 이름, 과목 이름, 성적(A+, A0, F 등)을 띄어쓰기로 구분하여 차례로 작성해주세요. + 입력예) Mickey Swift A+ + 만약에 학생의 성적 중 해당 과목이 존재하면 기존 점수가 갱신됩니다. + """) + MenuFunction.addScore() + case "4": + print("성적을 삭제할 학생의 이름, 과목 이름을 띄어쓰기로 구분하여 차례로 작성해주세요.") + MenuFunction.deleteScore() + case "5": + print("평점을 알고싶은 학생의 이름을 입력해주세요") + MenuFunction.showAverage() + case "X": + print("프로그램을 종료합니다…") + saveStudentsFile() // 프로그램 종료 시 students 파일 저장 + break menu + default: + print("뭔가 입력이 잘못되었습니다. 1~5 사이의 숫자 혹은 X를 입력해주세요.") + } + } +} + +main()