diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f435bd4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,92 @@ +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# Pods/ +# +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build/ + +# Accio dependency management +Dependencies/ +.accio/ + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. +# Instead, use fastlane to re-generate the screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +# Code Injection +# +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode + +iOSInjectionProject/ + +**/.DS_Store diff --git a/MyCreditManager_targ2t/MyCreditManager_targ2t.xcodeproj/project.pbxproj b/MyCreditManager_targ2t/MyCreditManager_targ2t.xcodeproj/project.pbxproj new file mode 100644 index 0000000..f39f665 --- /dev/null +++ b/MyCreditManager_targ2t/MyCreditManager_targ2t.xcodeproj/project.pbxproj @@ -0,0 +1,293 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + F047EEC6293DB13C00002FFA /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = F047EEC5293DB13C00002FFA /* main.swift */; }; + F0D4EAE0293F7CA700239E75 /* CreditManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0D4EADF293F7CA700239E75 /* CreditManager.swift */; }; + F0D4EAE2293F7D3400239E75 /* ConsoleIO.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0D4EAE1293F7D3400239E75 /* ConsoleIO.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + F047EEC0293DB13C00002FFA /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + F047EEC2293DB13C00002FFA /* MyCreditManager_targ2t */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = MyCreditManager_targ2t; sourceTree = BUILT_PRODUCTS_DIR; }; + F047EEC5293DB13C00002FFA /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + F0D4EADF293F7CA700239E75 /* CreditManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreditManager.swift; sourceTree = ""; }; + F0D4EAE1293F7D3400239E75 /* ConsoleIO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleIO.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + F047EEBF293DB13C00002FFA /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + F047EEB9293DB13C00002FFA = { + isa = PBXGroup; + children = ( + F047EEC4293DB13C00002FFA /* MyCreditManager_targ2t */, + F047EEC3293DB13C00002FFA /* Products */, + ); + sourceTree = ""; + }; + F047EEC3293DB13C00002FFA /* Products */ = { + isa = PBXGroup; + children = ( + F047EEC2293DB13C00002FFA /* MyCreditManager_targ2t */, + ); + name = Products; + sourceTree = ""; + }; + F047EEC4293DB13C00002FFA /* MyCreditManager_targ2t */ = { + isa = PBXGroup; + children = ( + F047EEC5293DB13C00002FFA /* main.swift */, + F0D4EADF293F7CA700239E75 /* CreditManager.swift */, + F0D4EAE1293F7D3400239E75 /* ConsoleIO.swift */, + ); + path = MyCreditManager_targ2t; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + F047EEC1293DB13C00002FFA /* MyCreditManager_targ2t */ = { + isa = PBXNativeTarget; + buildConfigurationList = F047EEC9293DB13C00002FFA /* Build configuration list for PBXNativeTarget "MyCreditManager_targ2t" */; + buildPhases = ( + F047EEBE293DB13C00002FFA /* Sources */, + F047EEBF293DB13C00002FFA /* Frameworks */, + F047EEC0293DB13C00002FFA /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = MyCreditManager_targ2t; + productName = MyCreditManager_targ2t; + productReference = F047EEC2293DB13C00002FFA /* MyCreditManager_targ2t */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + F047EEBA293DB13C00002FFA /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1410; + LastUpgradeCheck = 1410; + TargetAttributes = { + F047EEC1293DB13C00002FFA = { + CreatedOnToolsVersion = 14.1; + }; + }; + }; + buildConfigurationList = F047EEBD293DB13C00002FFA /* Build configuration list for PBXProject "MyCreditManager_targ2t" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = F047EEB9293DB13C00002FFA; + productRefGroup = F047EEC3293DB13C00002FFA /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + F047EEC1293DB13C00002FFA /* MyCreditManager_targ2t */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + F047EEBE293DB13C00002FFA /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + F0D4EAE2293F7D3400239E75 /* ConsoleIO.swift in Sources */, + F0D4EAE0293F7CA700239E75 /* CreditManager.swift in Sources */, + F047EEC6293DB13C00002FFA /* main.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + F047EEC7293DB13C00002FFA /* 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 = 12.6; + 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; + }; + F047EEC8293DB13C00002FFA /* 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 = 12.6; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + F047EECA293DB13C00002FFA /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + F047EECB293DB13C00002FFA /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + F047EEBD293DB13C00002FFA /* Build configuration list for PBXProject "MyCreditManager_targ2t" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + F047EEC7293DB13C00002FFA /* Debug */, + F047EEC8293DB13C00002FFA /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + F047EEC9293DB13C00002FFA /* Build configuration list for PBXNativeTarget "MyCreditManager_targ2t" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + F047EECA293DB13C00002FFA /* Debug */, + F047EECB293DB13C00002FFA /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = F047EEBA293DB13C00002FFA /* Project object */; +} diff --git a/MyCreditManager_targ2t/MyCreditManager_targ2t.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/MyCreditManager_targ2t/MyCreditManager_targ2t.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/MyCreditManager_targ2t/MyCreditManager_targ2t.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/MyCreditManager_targ2t/MyCreditManager_targ2t.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/MyCreditManager_targ2t/MyCreditManager_targ2t.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/MyCreditManager_targ2t/MyCreditManager_targ2t.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/MyCreditManager_targ2t/MyCreditManager_targ2t/ConsoleIO.swift b/MyCreditManager_targ2t/MyCreditManager_targ2t/ConsoleIO.swift new file mode 100644 index 0000000..1841dfd --- /dev/null +++ b/MyCreditManager_targ2t/MyCreditManager_targ2t/ConsoleIO.swift @@ -0,0 +1,125 @@ +// +// ConsoleIO.swift +// MyCreditManager_targ2t +// +// Created by 김보미 on 2022/12/06. +// + +import Foundation + + +/// 콘솔의 모든 입력 및 출력 요소를 관리하는 클래스이다. +class ConsoleIO { + + // MARK: - 메뉴 관련 메세지 출력 함수 목록 + /// 기능을 입력받기 위한 메뉴 안내를 콘솔에 출력하기 위한 함수이다. + func printAllMenu() { + print("원하는 기능을 입력해 주세요") + print("1: 학생추가, 2: 학생삭제, 3: 성적추가(변경), 4: 성적삭제, 5: 평점보기, X: 종료") + } + + /// 메뉴 선택 시 잘못된 입력을 하는 경우 에러 문구를 출력하는 함수이다. + func printMenuInputError() { + print("뭔가 입력이 잘못되었습니다. 1~5 사이의 숫자 혹은 X를 입력해주세요.") + } + + // MARK: - 기능 내부에서 반복적으로 사용되는 에러 메세지 출력 함수 목록 + /// 기능 내부에서 잘못된 입력을 하는 경우 동일 내용의 메세지 출력이 중복되므로 함수로 별도 구현하여 사용한다. + func printFuncInputError() { + print("입력이 잘못되었습니다. 다시 확인해주세요.") + } + + /// 없는 학생에 대한 에러 문구를 출력하는 함수이다. + func printStudentMissingError(name: String) { + print("\(name) 학생을 찾지 못했습니다.") + } + + // MARK: - 학생 추가 메뉴 관련 메세지 출력 함수 목록 + /// 학생 추가 메뉴 안내 문구를 출력하는 함수이다. + func printAddStudentGuid() { + print("추가할 학생의 이름을 입력해주세요") + } + + /// 학생 추가 메뉴 중 중복 에러 문구를 출력하는 함수이다. + func printAddStudentDuplicateError(name: String) { + print("\(name)은 이미 존재하는 학생입니다. 추가하지 않습니다.") + } + + /// 학생 추가가 정상적으로 실행된 후 안내 문구를 출력하는 함수이다. + func printAddStudentSuccess(name: String) { + print("\(name) 학생을 추가했습니다") + } + + // MARK: - 학생 삭제 메뉴 관련 메세지 출력 함수 목록 + /// 학생 삭제 메뉴 안내 문구를 출력하는 함수이다. + func printDeleteStudentGuid() { + print("삭제할 학생의 이름을 입력해주세요") + } + + /// 학생 삭제 메뉴에서 정상적으로 학생을 삭제한 후 안내 문구를 출력하는 함수이다. + func printDeleteStudentSuccess(name: String) { + print("\(name) 학생을 삭제하였습니다.") + } + + // MARK: - 성적 추가 메뉴 관련 메세지 출력 함수 목록 + /// 성적 추가 메뉴 안내 문구를 출력하는 함수이다. + func printAddGradeGuid() { + print("성적을 추가할 학생의 이름, 과목 이름, 성적(A+, A0, F 등)을 띄어쓰기로 구분하여 차례로 작성해 주세요.") + print("입력예) Mickey Swift A+") + print("만약에 학생의 성적 중 해당 과목이 존재한다면 기존 점수가 갱신됩니다.") + } + + /// 성적 추가 메뉴에서 정상적으로 성적을 추가(변경)한 후 안내 문구를 출력하는 함수 + func printAddGradeSuccess(name: String, subject: String, grade: String) { + print("\(name) 학생의 \(subject) 과목이 \(grade)로 추가(변경)되었습니다.") + } + + // MARK: - 성적 삭제 메뉴 관련 메세지 출력 함수 목록 + /// 성적 삭제 메뉴 안내 문구를 출력하는 함수이다. + func printDeleteGradeGuid() { + print("성적을 삭제할 학생의 이름, 과목 이름을 띄어쓰기로 구분하여 차례로 작성해 주세요.") + print("입력예) Mickey Swift") + } + + /// 성적 삭제 메뉴에서 정상적으로 성적을 추가(변경)한 후 안내 문구를 출력하는 함수이다. + func printDeleteGradeSuccess(name: String, subject: String) { + print("\(name) 학생의 \(subject) 과목의 성적이 삭제되었습니다.") + } + + // MARK: - 평점 메뉴 관련 메세지 출력 함수 목록 + /// 평점 메뉴 안내 문구를 출력하는 함수이다. + func printAverageGuid() { + print("평점을 알고싶은 학생의 이름을 입력해주세요") + } + + /// 평점 메뉴에서 과목들을 출력하는 함수이다. + func printAverageSubjectsSuccess(subject: String, grade: String) { + print("\(subject): \(grade)") + } + + /// 평점 메뉴에서 평점을 출력하는 함수이다. + func printAverageSuccess(average: Double) { + /// 소수점을 2자리까지만 보여주게 하는 String format을 사용한다. + print("평점: \(String(format: "%.2f", average))") + } + + // MARK: - 프로그램 종료 메세지 출력 함수 + /// 프로그램 종료 문구를 출력하는 함수이다. + func printQuitGuide() { + print("프로그램을 종료합니다...") + } + + // MARK: - 데이터 입력 관련 함수 + /// 사용자에게 데이터를 입력받는 함수이다. + func getInput() -> String { + /// FileHandle은 파일 디스크립터를 객체 지향 API로 감싼 얇은 래퍼로, 기본입력을 keyboard 변수에 할당한다. + /// availableData는 입력받은 데이터를 읽어오는 역할을 수행한다. + let inputData = FileHandle.standardInput.availableData + /// inputData의 데이터를 utf8형식의 String으로 Encoding하는 과정이다. + /// 데이터가 없을 수도 있으므로 없는 경우 공백을 반환하도록 언래핑한다. + let strData = String(data: inputData, encoding: String.Encoding.utf8) ?? "" + /// newline(엔터를 누르면 입력되는 새 줄)을 제거하고 남은 문자열을 return한다. + return strData.trimmingCharacters(in: CharacterSet.newlines) + } + +} diff --git a/MyCreditManager_targ2t/MyCreditManager_targ2t/CreditManager.swift b/MyCreditManager_targ2t/MyCreditManager_targ2t/CreditManager.swift new file mode 100644 index 0000000..a8bbf4a --- /dev/null +++ b/MyCreditManager_targ2t/MyCreditManager_targ2t/CreditManager.swift @@ -0,0 +1,398 @@ +// +// CreditManager.swift +// MyCreditManager_targ2t +// +// Created by 김보미 on 2022/12/06. +// + +import Foundation + +/// 메뉴의 타입을 정해주는 열거형 enum +enum OptionType: String { + case addStudent = "1" + case deleteStudent = "2" + case addGrade = "3" + case deleteGrade = "4" + case average = "5" + case quit = "X" + case unknown + + /// enum의 value에 따라서 실행해야 할 기능등을 매칭해주는 초기화함수 init + init(value: String) { + switch value { + case "1": self = .addStudent + case "2": self = .deleteStudent + case "3": self = .addGrade + case "4": self = .deleteGrade + case "5": self = .average + case "X": self = .quit + default: self = .unknown + } + } +} + +// MARK: - 전체적으로 사용될 배열과 상수들의 집합을 모아두었다. +/// 성적, 점수를 각각 Array로 구현 후 Dictionary로 Key-Value를 매칭시킨다. `평점에 활용 예정` +/// CaseIterable 프로토콜, CustomStringConvertible을 사용하는 경우 case로 처리 가능함! - Jason +let grade: [String] = ["A+", "A0", "B+", "B0", "C+", "C0", "D+", "D0", "F"] +let credit: [Double] = [4.5, 4, 3.5, 3, 2.5, 2, 1.5, 1, 0] +let creditByGrade = Dictionary(uniqueKeysWithValues: zip(grade, credit)) + +/// 학생 성적 목록의 저장형식으로 선언된 구조체이다. +struct StudentCreditList { + var name: String + var subject: [String] + var credit: [String] +} + +/// StudentCreditList 구조체를 따르는 배열을 선언한다. +var studentCreditList: [StudentCreditList] = [] + +// MARK: - CreditManager Class +class CreditManager { + + /// 콘솔의 모든 입력 및 출력 요소를 관리하는 클래스(ConsoleIO)를 상수로 선언하여 사용한다. + let consoleIO = ConsoleIO() + + /// 입력받은 옵션 타입을 value로 전환하는 과정을 함수로 선언하여 사용하였다. + func getOption(_ option: String) -> OptionType { + return (OptionType(value: option)) + } + + /// 실제 프로그램이 실행되는 동안 수행되는 함수이다. + func creditManager() { + + /// 콘솔 프로그램 종료 여부를 판단하기 위해 선언된 변수이다. + var isRun: Bool = true + + /// shouldQuit이 false일 동안 수행될 while 반복문이다. + /// while true가 되는 무한반복문 사용은 지양하는 것이 좋다 - Jason + while isRun { + /// while 반복문 시작과 동시에 사용할 수 있는 메뉴를 모두 print해준다. + consoleIO.printAllMenu() + + /// 메뉴에 대한 입력을 받는 상수를 선언하고 입력받은 내용을 할당한다. + let inputMenu = getOption(consoleIO.getInput()) + + /// 입력받은 메뉴를 기점으로 switch문으로 메뉴를 분기처리한다. + switch inputMenu { + + // MARK: - 학생 추가 기능 + case .addStudent: + /// 학생 추가 안내 문구를 출력한다. + consoleIO.printAddStudentGuid() + + /// 사용자에게 추가할 학생의 이름을 입력받는 상수를 선언하고 입력받은 내용을 할당한다. + let addStudentName: String = consoleIO.getInput() + + /// 학생 이름의 중복여부를 체크할 변수를 선언하고 기본값으로 false를 할당한다. + var checkDuplicateName: Bool = false + + /// studentCreditList의 요소 중 이름을 하나씩 꺼내서 입력된 이름과 같은지 확인하고 중복여부를 true로 바꾼다. + for studentCell in studentCreditList { + if addStudentName == studentCell.name { + checkDuplicateName = true + break + } + } + + /// 이름이 알파벳으로만 이루어졌는지 확인하기 위한 변수를 선언하고 기본값으로 true를 할당한다. + var isOnlyAlphabet: Bool = true + + /// 이름이 알파벳으로만 이루어져있는지 확인하는 예외처리 함수를 선언한다. + func checkNameIsOnlyAlphabet(_ name: String) { + + /// 정규식으로 이름이 알파벳으로만 이루어졌는지 확인하기 위한 조건 pattern을 선언하고 정규식을 할당한다. + let pattern = "^[a-zA-Z]*$" + + /// range를 통하여 pattern으로만 이루어져 있으면 해당 문자를 반환하고 + /// 알파벳이 아닌 숫자, 특수문자가 들어간 경우 nil을 반환한다. + let range = name.range(of: pattern, options: .regularExpression) + + /// 숫자, 특수문자가 들어간 경우에는 isOnlyAlphabet의 값을 false로 변환한다. + if range == nil { + isOnlyAlphabet = false + } + } + + /// 이름이 알파벳으로만 이루어져있는지 확인하는 예외처리 함수를 실행한다. + checkNameIsOnlyAlphabet(addStudentName) + + /// 예외처리 및 출력을 실행하는 구간이다. + if addStudentName == "" || !isOnlyAlphabet { + /// 1. 잘못된 입력(공백, 숫자)인 경우 에러 메세지를 출력한다. + consoleIO.printFuncInputError() + } else if checkDuplicateName == true { + /// 2. 이미 존재하는 학생을 추가하는 경우 에러 메세지를 출력한다. + consoleIO.printAddStudentDuplicateError(name: addStudentName) + } else { + /// 정상적으로 추가된 경우 배열에 추가하고 추가 안내 텍스트 출력한다. + let addNewStudent = StudentCreditList(name: "\(addStudentName)", subject: [], credit: []) + studentCreditList.append(addNewStudent) + consoleIO.printAddStudentSuccess(name: addStudentName) + } + /// 학생이 잘 추가되었는지 확인하기 위해 print문을 사용한다. + print(studentCreditList) + + // MARK: - 학생 삭제 기능 + case .deleteStudent: + /// 학생 삭제 안내 문구를 출력한다. + consoleIO.printDeleteStudentGuid() + + /// 사용자에게 삭제할 학생의 이름을 입력받는 상수를 선언하고 입력받은 내용을 할당한다. + let deleteStudentName: String = consoleIO.getInput() + + /// 삭제할 곳의 Index 값을 가지고 있는 변수를 선언한다. + var deleteIndex: Int = 0 + + /// 예외처리 및 출력을 실행하는 if문을 선언한다. + if deleteStudentName == "" { + /// 1. 잘못된 입력(공백, 저장된 학생 이름이 없는 경우)인 경우 오류 메세지를 출력한다. + consoleIO.printFuncInputError() + } else if studentCreditList.count == 0 { + /// 배열이 비어있는 경우 학생이 없으므로 오류 메세지를 출력한다. + consoleIO.printStudentMissingError(name: deleteStudentName) + } else { + /// 정상적으로 삭제된 경우 배열에서 삭제하고 삭제 안내 텍스트 출력한다. + for studentCell in studentCreditList { + if studentCell.name == deleteStudentName { + studentCreditList.remove(at: deleteIndex) + consoleIO.printDeleteStudentSuccess(name: deleteStudentName) + + break + } else { + deleteIndex += 1 + if deleteIndex == studentCreditList.count { + /// 2. 없는 학생을 삭제하는 경우 오류 메세지를 출력한다. + consoleIO.printStudentMissingError(name: deleteStudentName) + } + } + } + + } + /// 학생이 잘 삭제되었는지 확인하기 위해 print문을 사용한다. + print(studentCreditList) + + // MARK: - 성적 추가 기능 + case .addGrade: + /// 성적 추가 안내 문구를 출력한다. + consoleIO.printAddGradeGuid() + + /// 사용자에게 추가할 학생의 이름, 과목 이름, 성적을 입력받는 상수를 선언하고 입력받은 내용을 할당한다. + let addGradeInput: String = consoleIO.getInput() + + /// 띄어쓰기로 구분하여 입력받은 addGradeInput을 separator(공백문자) 기준으로 구분하여 배열로 만들어주는 split를 사용한 후 상수에 할당한다. + let splitAddGradeInput = addGradeInput.split(separator: " ") + + /// 학생이 이미 존재하는지를 판단하는 변수를 선언하고 기본값을 true로 할당한다. + var isStudentExist: Bool = true + + /// 학생이 존재하는 위치의 index를 가지게 될 변수를 선언한다. + var existIndex: Int = 0 + + /// 학생이 존재하는지를 판단할 함수를 선언한다. + func checkStudentExist() { + for studentCell in studentCreditList { + /// 입력을 학생 이름, 과목 이름, 성적 순서대로 받으므로 학생 이름을 받아오기 위해서는 index가 0인 것을 불러와야 한다. + if studentCell.name == splitAddGradeInput[0] { + break + } else { + existIndex += 1 + } + } + /// count한 index 값이 studentCreditList의 배열 길이와 같으면 학생이 존재하지 않으므로 존재하는지 판단하는 변수를 false로 전환한다. + if existIndex == studentCreditList.count { + isStudentExist = false + } + } + + /// 과목이 존재하는지를 판단하는 변수를 선언 후 false를 기본값으로 할당한다. + var isSubjectExist: Bool = false + + /// 과목의 위치 index를 가지는 변수를 선언한다. + var subjectIndex: Int = 0 + + /// 과목이 존재하는지를 판단할 함수를 선언한다. + func subjectExistCheck() { + for subject in studentCreditList[existIndex].subject { + if subject == splitAddGradeInput[1] { + isSubjectExist = true + break + } else { + subjectIndex += 1 + } + } + } + + /// 입력이 없는데 존재여부를 판단하게 되는 경우 에러가 발생하므로, 입력값이 있을 때만 확인하도록 if 조건문을 사용한다. + if addGradeInput != "" { + /// 학생이 존재하는지를 판단하는 함수 실행한다. + checkStudentExist() + + /// 과목이 존재하는지를 판단할 함수를 실행한다. + subjectExistCheck() + } + + /// 예외처리 및 출력을 실행하기 위해 if문을 선언한다. + if addGradeInput == "" || splitAddGradeInput.count != 3 || !isStudentExist { + /// 1. 잘못된 입력(공백, 학생이름/과목이름/성적 중 하나가 입력되지 않거나 초과 입력한 경우)인 경우 에러 메세지를 출력한다. + consoleIO.printFuncInputError() + } else if isSubjectExist { + /// 과목이 이미 존재하는 경우 성적만 바꿔준다. + studentCreditList[existIndex].credit[subjectIndex] = String(splitAddGradeInput[2]) + consoleIO.printAddGradeSuccess(name: String(splitAddGradeInput[0]), subject: String(splitAddGradeInput[1]), grade: String(splitAddGradeInput[2])) + } else { + /// 과목이 없지만 잘못된 입력이 아닌 경우 과목을 추가하고 성적도 추가해준다. + studentCreditList[existIndex].subject.append(String(splitAddGradeInput[1])) + studentCreditList[existIndex].credit.append(String(splitAddGradeInput[2])) + consoleIO.printAddGradeSuccess(name: String(splitAddGradeInput[0]), subject: String(splitAddGradeInput[1]), grade: String(splitAddGradeInput[2])) + } + + /// 성적이 잘 추가(변경)되었는지 확인하기 위해 print문을 사용한다. + print(studentCreditList) + + // MARK: - 성적 삭제 기능 + case .deleteGrade: + /// 성적 삭제 안내 문구를 출력한다. + consoleIO.printDeleteGradeGuid() + + /// 사용자에게 삭제할 학생의 이름, 과목 이름을 입력받는 상수를 선언하고 입력받은 내용을 할당한다. + let deleteGradeInput: String = consoleIO.getInput() + + /// 띄어쓰기로 구분하여 입력받은 deleteGradeInput을 separator(공백문자) 기준으로 구분하여 배열로 만들어주는 split를 사용한 후 상수에 할당한다. + let splitDeleteGradeInput = deleteGradeInput.split(separator: " ") + + /// 학생이 이미 존재하는지를 판단하는 변수를 선언 후 기본값을 true로 선언한다. + var isStudentExist: Bool = true + + /// 학생이 존재하는 위치의 index를 가지게 될 변수를 선언한다. + var existIndex: Int = 0 + + /// 학생이 존재하는지를 판단할 함수를 선언한다. + func studentExistCheck() { + for studentCell in studentCreditList { + /// 입력받은 이름이 studentCreditList에 있는지를 확인한다. + if studentCell.name == splitDeleteGradeInput[0] { + break + } else { + existIndex += 1 + } + } + if existIndex == studentCreditList.count { + isStudentExist = false + } + } + + /// 과목이 존재하는지를 판단하는 변수를 선언하고 true를 할당한다. + var isSubjectExist: Bool = true + + /// 과목의 위치 index를 가지는 변수를 선언한다. + var subjectIndex: Int = 0 + + /// 과목이 존재하는지, 몇 번째 인덱스에 있는지 찾아내는 함수를 선언한다. + func subjectExistCheck() { + for subject in studentCreditList[existIndex].subject { + if subject == splitDeleteGradeInput[1] { + break + } else { + subjectIndex += 1 + } + } + if subjectIndex == studentCreditList[existIndex].subject.count { + isSubjectExist = false + } + } + + /// 입력이 없는데 존재여부를 판단하게 되는 경우 Index out of range 에러가 발생하므로, 입력값이 있을 때만 확인하도록 if 조건문을 사용한다. + if deleteGradeInput != "" { + /// 학생이 존재하는지를 판단할 함수를 호출한다. + studentExistCheck() + if isStudentExist == true { + /// 학생이 존재한다면 과목이 존재하는지, 몇 번째 인덱스에 있는지 찾아내는 함수를 호출한다. + subjectExistCheck() + } + } + + // 예외처리 및 출력을 실행하는 구간 + if deleteGradeInput == "" || splitDeleteGradeInput.count != 2 || !isSubjectExist { + consoleIO.printFuncInputError() + } else if !isStudentExist { + consoleIO.printStudentMissingError(name: String(splitDeleteGradeInput[0])) + } else { + studentCreditList[existIndex].subject.remove(at: subjectIndex) + studentCreditList[existIndex].credit.remove(at: subjectIndex) + consoleIO.printDeleteGradeSuccess(name: String(splitDeleteGradeInput[0]), subject: String(splitDeleteGradeInput[1])) + } + + /// 성적이 잘 삭제되었는지 확인하기 위해 print문을 사용한다. + print(studentCreditList) + + // MARK: - 평점 기능 + case .average: + /// 평점 기능 안내 문구를 출력한다. + consoleIO.printAverageGuid() + + /// 사용자가 평점을 조회하고 싶은 학생의 이름을 입력받는 상수를 선언하고 입력받은 내용을 할당한다. + let nameForAverage: String = consoleIO.getInput() + + /// 학생이 이미 존재하는지를 판단하는 변수를 선언하고 true를 할당한다. + var isStudentExist: Bool = true + + /// 학생이 존재하는 위치의 index를 가지게 될 변수를 선언한다. + var existIndex: Int = 0 + + /// 학생이 존재하는지를 판단할 함수를 선언한다. + func studentExistCheck() { + for studentCell in studentCreditList { + if studentCell.name == nameForAverage { + break + } else { + existIndex += 1 + } + } + if existIndex == studentCreditList.count { + isStudentExist = false + } + } + + /// 학생이 존재하는지를 판단할 함수를 호출한다. + studentExistCheck() + + /// 점수의 위치 index값을 가지게 될 변수를 선언한다. + var creditIndex: Int = 0 + + /// 점수의 합을 할당받을 변수를 선언한다. + var sum: Double = 0.0 + + /// 점수의 합을 과목 수로 나눈 평균을 할당받을 변수를 선언한다. + var average: Double = 0.0 + + /// 예외처리 및 출력을 실행하는 구간을 위해 if문을 선언한다. + if nameForAverage == "" { + consoleIO.printFuncInputError() + } else if !isStudentExist { + consoleIO.printStudentMissingError(name: nameForAverage) + } else { + for subject in studentCreditList[existIndex].subject { + consoleIO.printAverageSubjectsSuccess(subject: subject, grade: String(studentCreditList[existIndex].credit[creditIndex])) + sum += creditByGrade[studentCreditList[existIndex].credit[creditIndex]]! + creditIndex += 1 + } + + /// 출력형식에 소수점까지 보여주어야 하므로 Int인 creditIndex를 Double로 형변환하여 나누는 연산을 수행한다. + average = sum / Double(creditIndex) + consoleIO.printAverageSuccess(average: average) + } + + // MARK: - 종료 기능 + case .quit: + consoleIO.printQuitGuide() + isRun = false + + /// case가 아닌 경우(메뉴가 아닌 다른 것을 입력한 경우) default를 수행한다. + default: + consoleIO.printMenuInputError() + } + } + } +} diff --git a/MyCreditManager_targ2t/MyCreditManager_targ2t/main.swift b/MyCreditManager_targ2t/MyCreditManager_targ2t/main.swift new file mode 100644 index 0000000..b630023 --- /dev/null +++ b/MyCreditManager_targ2t/MyCreditManager_targ2t/main.swift @@ -0,0 +1,19 @@ +// +// main.swift +// MyCreditManager_targ2t +// +// Created by 김보미 on 2022/12/05. +// + +/// [2022 맛있는코드 x 새싹] iOS 앱 개발자 부트캠프 사전과제 +/// 성적 관리 프로그램 (Console) +/// +/// Command Line Tool + +import Foundation + +/// 앱 작업 시 ContentView를 깔끔하게 사용하려고 하는 것처럼 main.swift도 깔끔하게 유지하기 위해 +/// 클래스와 구조체를 파일로 분리하는 것이 필요하다. +let creditManager = CreditManager() + +creditManager.creditManager() diff --git a/README.md b/README.md index 5305121..84edb0e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,70 @@ -# pull-request-practice -Pull Request 연습용 레포지토리입니다. +# [2022 맛있는코드 x 새싹] 2차 선발 과제 : 성적 관리 프로그램 (Console) + +## 과제 수행목적 + +- 과제는 프로그래밍 실력만을 알아보기 위함이 아닙니다. +- 주어진 학습자료를 잘 이해하고 과제를 얼만큼 잘 이해하고 수행하는지가 가장 중요합니다. +- 서두르지 말고 차분히 학습내용을 익힌 후 과제를 수행해주세요. + +## 사용 언어 / 환경 + +- Swift +- Xcode 기본 템플릿 중 [macOS - Command Line Tool] + +## Check List + +- [x] 기능을 입력받기 위한 안내 문구 (가이드) +- [x] 학생추가 + - 메뉴를 선택한 후에도 잘못 입력한 것이 있으면 처리해 주어야합니다 + - 이미 존재하는 학생은 다시 추가하지 않습니다 +- [x] 학생삭제 + - 메뉴를 선택한 후에도 잘못 입력한 것이 있으면 처리해 주어야합니다 + - 없는 학생은 삭제하지 않습니다 +- [x] 성적추가(변경) + - 메뉴를 선택한 후에도 잘못 입력한 것이 있으면 처리해 주어야합니다 + - 없는 학생의 성적은 추가하지 않습니다 +- [x] 성적삭제 + - 메뉴를 선택한 후에도 잘못 입력한 것이 있으면 처리해 주어야합니다 + - 없는 학생의 성적은 삭제하지 않습니다 +- [x] 평점보기 + - 메뉴를 선택한 후에도 잘못 입력한 것이 있으면 처리해 주어야합니다 + - 해당 학생의 과목과 성적을 모두 출력한 후 마지막 줄에 평점을 출력합니다 + - 없는 학생은 평점을 보여주지 않습니다 +- [x] 종료 + - 현재 학생과 성적의 모든 상태를 저장합니다 + - 프로그램을 종료합니다 + +## 프로그램 동작조건 + +- [x] 사용자가 종료 메뉴를 선택하기 전까지는 계속해서 사용자의 입력을 받습니다 +- [x] 메뉴선택을 포함한 모든 입력은 숫자 또는 영문으로 받습니다 +- [ ] 사용자가 프로그램을 종료한 후에 다시 실행하여도 기존의 성적 정보를 사용할 수 있어야 합니다 + +## 성적별 점수 + +- A+ (4.5점) / A0 (4점) +- B+ (3.5점) / B0 (3점) +- C+ (2.5점) / C0 (2점) +- D+ (1.5점) / D0 (1점) +- F (0점) + +## 평점 + +- 각 과목의 점수 총 합 / 과목 수 +- 최대 소수점 2번째 자리까지 출력 + - 예) + - 3.75 + - 4.1 + - 2 + + +## `도전 과제(가점 항목)` + +- 사용자가 프로그램을 종료한 후에 다시 실행하여도 기존의 성적 정보를 사용할 수 있도록 구현합니다 + +## 참고 문서 + +- Kodeco Command Line Programs on MacOS Tutorial + - https://www.kodeco.com/511-command-line-programs-on-macos-tutorial + +