//工程名字StudentInfo
//定义学生的属性类
class Student{
//属性类中添加:姓名、
var name:String
//班级、
var className:String
//分数
var grade:String
init(name:String,className:String,grade:String)
{
self.name = name
self.className = className
self.grade = grade
}
//打印函数方法
func description()
{
print("姓名:\(name),班级:\(className),分数:\(grade)")
}
}
let xiaomi = Student(name: "小米",className: "1507C",grade: "100")
xiaomi.description()
//定义排序函数
//定义swift的排序函数,函数名自行命名)
//函数的参数为(Name:[String],scode:[Int])
//函数的返回类型为void
//根据输入数组类型进行分数的排序
func sort(Name:[String], scode: [Int]) ->Void{ var scode = scode var Name = Name for i in (0..scode [M + 1]
{
let tmp = scode[M]
let tmpName = Name[M]
scode[M] = scode[M + 1]
Name[M] = Name[M + 1]
scode [M + 1] = tmp
Name[M + 1] = tmpName
}
}
}
print(scode)
print(Name)
//要求使用循环语句打印
for i in 0..<3 {
print(Name[i],scode[i])
}
}
sort(Name: ["小米","小花","小熊"], scode: [23,100,65])