fork download
  1. var couser = -1
  2. class Student{
  3. var id:Int
  4. var name:String
  5. var scores = [Int]()
  6. var telphone:String
  7. }
  8.  
  9. class StudentManager{
  10. var origin = Student()
  11. var info:Student{
  12. set{
  13. origin.name = NewValue.name
  14. origin.id = NewValue.id
  15. origin.scores = NewValue.scores
  16. origin.telphone = NewValue.telphone
  17. students += [origin]
  18. }
  19. }
  20. var students = [Student]()
  21. var avg = [Double]()
  22. var callAvg:avg{
  23. get{
  24. avg = []
  25. for cnt in 0 ... couser{
  26. avg.append = Double(students[cnt][2].reduce(0,+))/3.0
  27. }
  28. return avg
  29. }
  30. }
  31. }
  32.  
  33. func inputInfo(id:Int,name:String,score:[Int],telphone:String)->String{
  34. couser += 1;
  35. var manager = StudentManager()
  36. let input = manager.info
  37. manager.info = Student(id:id,name:name,scores:score,telphone:telphone)
  38. return "완료";
  39. }
  40.  
  41. func sayList()->(){
  42. var manager = StudentManager()
  43. let sortScore = manager.students
  44. var score = sortScore.sorted(by:{$0[0]<$1[0]})
  45. let avgScore = manager.callAvg
  46. print("학번\t이름\t전화\t국어\t수학\t영어\t평균")
  47. for cnt in 0...couser{
  48. print("\(score[cnt][0])\t\(score[cnt][1])\t\(score[cnt][3])",terminator:"\t")
  49. print("\(score[cnt][2][0]),\t\(score[cnt][2][1]),\t\(score[cnt][2][2])\t\(avgScore)")
  50. }
  51. }
  52. func avgList()->(){
  53. var manager = StudentManager()
  54. var avgScore = manager.callAvg
  55. avgScore = avgScore.sorted(by:>)
  56. sortIndex = [Int]()
  57. var avgCnt = -1
  58. var score = manager.students
  59. var onOff = 0
  60. for cnt1:Int in 0...couser{//지금 보고있는 avgIndex
  61. for cnt2:Int in 0...couser{//scoreIndex
  62. let avgTmp = Double(score[cnt2][2].reduce(0,+))/3.0 //scoreAvg
  63. if(avgTmp == avgScore[cnt1]){
  64. if(!sortIndex.isEmpty){
  65. onOff = 0;
  66. for cnt3:Int in 0...avgCnt{
  67. if(cnt2 == sortIndex[cnt3]){
  68. onOff = 1
  69. break
  70. }
  71. }
  72. if(onOff<1){//넣어야해
  73. avgCnt += 1
  74. sortIndex[avgCnt] = cnt2
  75. break
  76. }
  77. }
  78. else{
  79. avgCnt += 1
  80. sortIndex[avgCnt] = cnt2
  81. break
  82. }
  83. }
  84. }
  85. }
  86.  
  87. print("학번\t이름\t전화\t국어\t수학\t영어\t평균")
  88. for cnt in 0...couser{
  89. let sort = sortIndex[cnt]
  90. print("\(score[sort][0])\t\(score[sort][1])\t\(score[sort][3])",terminator:"\t")
  91. print("\(score[sort][2][0]),\t\(score[sort][2][1]),\t\(score[sort][2][2])\t\(avgScore[cnt])")
  92. }
  93. }
  94. func modInfo(id:Int)->String{
  95. let manager = StudentManager()
  96. var score = manager.Students
  97. for cnt in 0...couser{
  98. if(score[cnt][0] == id){
  99. let avg = Double(score[cnt][2][0]+score[cnt][2][1]+score[cnt][2][2])/3.0
  100. print("이름:\(score[cnt][1]) 전화: \(score[cnt][3])",terminator:"\t")
  101. print("국어: \(score[cnt][2][0]), 수학: \(score[cnt][2][1]), 영어: \(score[cnt][2][2]), 평균: \(avg)")
  102. return ""
  103. }
  104. }
  105. return "아이디 없음"
  106. }
  107. func removeInfo(id:Int)->String{
  108. let manager = StudentManager()
  109. var score = manager.Students
  110. for cnt in 0...couser{
  111. score.remove(at:couser)
  112. couser -= 1
  113. return "완료"
  114. }
  115. return "아이디 없음"
  116. }
  117. print("학생 성적 관리 프로그램")
  118. var onOff = 1
  119. var select = 0;
  120. while(onOff>0){
  121. print("1.학생 정보 입력\n2.학생 리스트 보기\n3.평균순 성적 보기\n4.학생 정보 수정력\n5.학생 정보 삭제\n6.종료\n입력 :",terminator:" ");
  122. select = Int((readLine())!)!
  123. if(select>0 && select <7){
  124. switch(select){
  125. case 1:
  126. let id = Int(readLine()!)!
  127. let name = readLine()
  128. let kor = Int(readLine()!)!
  129. let math = Int(readLine()!)!
  130. let eng = Int(readLine()!)!
  131. let telphone = readLine()
  132. let arr = [Int]()
  133. arr.append(kor)
  134. arr.append(math)
  135. arr.append(eng)
  136. print("\(inputInfo(id:id,name:name,score:arr,telphone:telphone))")
  137. case 2:
  138. sayList()
  139. case 3:
  140. avgList()
  141. case 4:
  142. let id = Int(readLine()!)!
  143. print("\(modInfo(id:id))")
  144. case 5:
  145. let id = Int(readLine()!)!
  146. print("\(removeInfo(id:id))")
  147. default://종료
  148. onOff = 0
  149. }
  150. }
  151. else{
  152. print("잘못된 입력. 재입력");
  153. }
  154. }
  155. print("종료");
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.swift:12:3: error: variable with a setter must also have a getter
                set{
                ^
prog.swift:10:15: error: 'Student' cannot be constructed because it has no accessible initializers
        var origin = Student()
                     ^
prog.swift:22:14: error: use of undeclared type 'avg'
        var callAvg:avg{
                    ^~~
prog.swift:2:7: error: class 'Student' has no initializers
class Student{
      ^
prog.swift:3:6: note: stored property 'id' without initial value prevents synthesized initializers
        var id:Int
            ^
                   = 0
prog.swift:4:6: note: stored property 'name' without initial value prevents synthesized initializers
        var name:String
            ^
                        = ""
prog.swift:6:6: note: stored property 'telphone' without initial value prevents synthesized initializers
        var telphone:String
            ^
                            = ""
prog.swift:13:18: error: use of unresolved identifier 'NewValue'; did you mean 'newValue'?
                        origin.name = NewValue.name
                                      ^~~~~~~~
                                      newValue
prog.swift:12:3: note: 'newValue' declared here
                set{
                ^
prog.swift:14:16: error: use of unresolved identifier 'NewValue'; did you mean 'newValue'?
                        origin.id = NewValue.id
                                    ^~~~~~~~
                                    newValue
prog.swift:12:3: note: 'newValue' declared here
                set{
                ^
prog.swift:15:20: error: use of unresolved identifier 'NewValue'; did you mean 'newValue'?
                        origin.scores = NewValue.scores
                                        ^~~~~~~~
                                        newValue
prog.swift:12:3: note: 'newValue' declared here
                set{
                ^
prog.swift:16:22: error: use of unresolved identifier 'NewValue'; did you mean 'newValue'?
                        origin.telphone = NewValue.telphone
                                          ^~~~~~~~
                                          newValue
prog.swift:12:3: note: 'newValue' declared here
                set{
                ^
prog.swift:26:16: error: cannot assign to value: 'append' returns immutable value
                                avg.append = Double(students[cnt][2].reduce(0,+))/3.0
                                ~~~~~~~~~~ ^
prog.swift:37:17: error: 'Student' cannot be constructed because it has no accessible initializers
        manager.info = Student(id:id,name:name,scores:score,telphone:telphone)
                       ^
prog.swift:44:35: error: type 'Student' has no subscript members
        var score = sortScore.sorted(by:{$0[0]<$1[0]})
                                         ^~
prog.swift:56:2: error: use of unresolved identifier 'sortIndex'; did you mean 'SetIndex'?
        sortIndex = [Int]()
        ^~~~~~~~~
        SetIndex
Swift.SetIndex:1:18: note: 'SetIndex' declared here
public typealias SetIndex<Element> = Set<Element>.Index
                 ^
prog.swift:62:29: error: type 'Student' has no subscript members
                        let avgTmp = Double(score[cnt2][2].reduce(0,+))/3.0 //scoreAvg
                                            ~~~~~^~~~~~
prog.swift:64:9: error: use of unresolved identifier 'sortIndex'; did you mean 'SetIndex'?
                                if(!sortIndex.isEmpty){
                                    ^~~~~~~~~
                                    SetIndex
Swift.SetIndex:1:18: note: 'SetIndex' declared here
public typealias SetIndex<Element> = Set<Element>.Index
                 ^
prog.swift:67:18: error: use of unresolved identifier 'sortIndex'; did you mean 'SetIndex'?
                                                if(cnt2 == sortIndex[cnt3]){
                                                           ^~~~~~~~~
                                                           SetIndex
Swift.SetIndex:1:18: note: 'SetIndex' declared here
public typealias SetIndex<Element> = Set<Element>.Index
                 ^
prog.swift:74:7: error: use of unresolved identifier 'sortIndex'; did you mean 'SetIndex'?
                                                sortIndex[avgCnt] = cnt2
                                                ^~~~~~~~~
                                                SetIndex
Swift.SetIndex:1:18: note: 'SetIndex' declared here
public typealias SetIndex<Element> = Set<Element>.Index
                 ^
prog.swift:80:6: error: use of unresolved identifier 'sortIndex'; did you mean 'SetIndex'?
                                        sortIndex[avgCnt] = cnt2
                                        ^~~~~~~~~
                                        SetIndex
Swift.SetIndex:1:18: note: 'SetIndex' declared here
public typealias SetIndex<Element> = Set<Element>.Index
                 ^
prog.swift:89:14: error: use of unresolved identifier 'sortIndex'; did you mean 'SetIndex'?
                let sort = sortIndex[cnt]
                           ^~~~~~~~~
                           SetIndex
Swift.SetIndex:1:18: note: 'SetIndex' declared here
public typealias SetIndex<Element> = Set<Element>.Index
                 ^
prog.swift:96:14: error: value of type 'StudentManager' has no member 'Students'
        var score = manager.Students
                    ^~~~~~~ ~~~~~~~~
prog.swift:109:14: error: value of type 'StudentManager' has no member 'Students'
        var score = manager.Students
                    ^~~~~~~ ~~~~~~~~
prog.swift:123:24: error: expected ',' separator
        if(select>0 && select <7){
                              ^
                             ,
prog.swift:123:24: error: '<' is not a prefix unary operator
        if(select>0 && select <7){
                              ^
prog.swift:133:5: error: cannot use mutating member on immutable value: 'arr' is a 'let' constant
                                arr.append(kor)
                                ^~~
prog.swift:132:5: note: change 'let' to 'var' to make it mutable
                                let arr = [Int]()
                                ^~~
                                var
prog.swift:134:5: error: cannot use mutating member on immutable value: 'arr' is a 'let' constant
                                arr.append(math)
                                ^~~
prog.swift:132:5: note: change 'let' to 'var' to make it mutable
                                let arr = [Int]()
                                ^~~
                                var
prog.swift:135:5: error: cannot use mutating member on immutable value: 'arr' is a 'let' constant
                                arr.append(eng)
                                ^~~
prog.swift:132:5: note: change 'let' to 'var' to make it mutable
                                let arr = [Int]()
                                ^~~
                                var
prog.swift:136:35: error: value of optional type 'String?' must be unwrapped to a value of type 'String'
                                print("\(inputInfo(id:id,name:name,score:arr,telphone:telphone))")
                                                              ^
prog.swift:136:35: note: coalesce using '??' to provide a default when the optional value contains 'nil'
                                print("\(inputInfo(id:id,name:name,score:arr,telphone:telphone))")
                                                              ^
                                                                   ?? <#default value#>
prog.swift:136:35: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
                                print("\(inputInfo(id:id,name:name,score:arr,telphone:telphone))")
                                                              ^
                                                                  !
prog.swift:136:59: error: value of optional type 'String?' must be unwrapped to a value of type 'String'
                                print("\(inputInfo(id:id,name:name,score:arr,telphone:telphone))")
                                                                                      ^
prog.swift:136:59: note: coalesce using '??' to provide a default when the optional value contains 'nil'
                                print("\(inputInfo(id:id,name:name,score:arr,telphone:telphone))")
                                                                                      ^
                                                                                               ?? <#default value#>
prog.swift:136:59: note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
                                print("\(inputInfo(id:id,name:name,score:arr,telphone:telphone))")
                                                                                      ^
                                                                                              !
<unknown>:0: error: error opening input file 'prog.o' (No such file or directory
)
clang: error: no such file or directory: 'prog.o'
clang: error: no such file or directory: '@prog.autolink'
stdout
Standard output is empty