Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Git_ Exercise.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 = "<group>"; };
90D3F152294FFCB300CEA3F8 /* Modules.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modules.swift; sourceTree = "<group>"; };
90D3F155294FFFA200CEA3F8 /* AddStudent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddStudent.swift; sourceTree = "<group>"; };
90D3F157294FFFC500CEA3F8 /* UpdateGrade.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateGrade.swift; sourceTree = "<group>"; };
90D3F158294FFFC500CEA3F8 /* DeleteStudent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeleteStudent.swift; sourceTree = "<group>"; };
90D3F159294FFFC600CEA3F8 /* Exit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Exit.swift; sourceTree = "<group>"; };
90D3F15A294FFFC600CEA3F8 /* RemoveGrade.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoveGrade.swift; sourceTree = "<group>"; };
90D3F15B294FFFC600CEA3F8 /* ReportCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReportCard.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -57,11 +71,34 @@
2768CA06294F453B00990B98 /* Git_ Exercise */ = {
isa = PBXGroup;
children = (
90D3F154294FFF8000CEA3F8 /* Utils */,
90D3F151294FFCA200CEA3F8 /* Modules */,
2768CA07294F453B00990B98 /* main.swift */,
);
path = "Git_ Exercise";
sourceTree = "<group>";
};
90D3F151294FFCA200CEA3F8 /* Modules */ = {
isa = PBXGroup;
children = (
90D3F152294FFCB300CEA3F8 /* Modules.swift */,
);
path = Modules;
sourceTree = "<group>";
};
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 = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -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;
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Git_ Exercise.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
91 changes: 91 additions & 0 deletions Git_ Exercise/Modules/Modules.swift
Original file line number Diff line number Diff line change
@@ -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 "프로그램을 종료합니다..."
}
}
25 changes: 25 additions & 0 deletions Git_ Exercise/Utils/AddStudent.swift
Original file line number Diff line number Diff line change
@@ -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)
}
25 changes: 25 additions & 0 deletions Git_ Exercise/Utils/DeleteStudent.swift
Original file line number Diff line number Diff line change
@@ -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)
}
12 changes: 12 additions & 0 deletions Git_ Exercise/Utils/Exit.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Exit.swift
// GradeManagement
//
// Created by 박재우 on 2022/12/19.
//

import Foundation

func exit() {
print(Operations().exit)
}
41 changes: 41 additions & 0 deletions Git_ Exercise/Utils/RemoveGrade.swift
Original file line number Diff line number Diff line change
@@ -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..<reports.count {
if reports[index].subject == subject {
manager[student]?.remove(at: index)
Operations().removeGrade(subject, of: student)
return
}
}
print("\(subject) \(Errors.searchSubject.rawValue)")
}
50 changes: 50 additions & 0 deletions Git_ Exercise/Utils/ReportCard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// ReportCard.swift
// GradeManagement
//
// Created by 박재우 on 2022/12/19.
//

import Foundation

func reportCard() {
print(Questions.reportCard.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
}
guard let reports = manager[student] else {return}
var average = 0.0
for report in reports {
print("\(report.subject): \(report.grade)")
switch Grade(rawValue: report.grade) {
case .APlus:
average += Score.APlus.rawValue
case .AZero:
average += Score.AZero.rawValue
case .BPlus:
average += Score.BPlus.rawValue
case .BZero:
average += Score.BZero.rawValue
case .CPlus:
average += Score.CPlus.rawValue
case .CZero:
average += Score.CZero.rawValue
case .DPlus:
average += Score.DPlus.rawValue
case .DZero:
average += Score.DZero.rawValue
default:
average += 0.0
}
}
average /= Double(reports.count)
print("평점 : \(average)")
}
Loading