1.<p style="margin-top: 0px; margin-bottom: 0px; font-family: 'Heiti SC Light'; color: rgb(169, 169, 154);"><span style="font-family: Menlo;"><em>// </em></span>编写出一个通用的人员类(<span style="font-family: Menlo;"><em>Person</em></span>),该类具有姓名(<span style="font-family: Menlo;"><em>Name</em></span>)、年龄(<span style="font-family: Menlo;"><em>Age</em></span>)、性别(<span style="font-family: Menlo;"><em>Sex</em></span>)等域。</p><p style="margin-top: 0px; margin-bottom: 0px; font-family: 'Heiti SC Light'; color: rgb(169, 169, 154);"><span style="font-family: Menlo;"><em>// </em></span>然后对<span style="font-family: Menlo;"><em>Person </em></span>类的继承得到一个学生类(<span style="font-family: Menlo;"><em>Student</em></span>),该类能够存放学生的<span style="font-family: Menlo;"><em>5</em></span>门课的成绩,并能求</p><p style="margin-top: 0px; margin-bottom: 0px; font-family: 'Heiti SC Light'; color: rgb(169, 169, 154);"><span style="font-family: Menlo;"><em>// </em></span>出平均成绩,要求对该类的构造函数进行重载,至少给出三个形式。最后编程对<span style="font-family: Menlo;"><em>student</em></span>类的功能进行验证。</p>
public class HomeWork3 : MonoBehaviour {public Student stu=new Student("wang");public Student stu2=new Student(true);void Start () {Debug.Log (stu.name);for(int i=0;i<=4;i++){ stu.Score[i]=i;Debug.Log (stu.Score[i]);}stu.ave ();}void Update () {}}
2.
<pre name="code" class="html">public class Person {public string name;public int age;public bool sex;}
3.
<pre name="code" class="html">public class Student:Person {
public int [] Score = new int[5];
public Student(int score){
for(int i=0;i<=4;i++){
Score[i]=score;
}
}
public Student(string name){
base.name = name;
}
public Student(bool sex){
base.sex = sex;
if(sex==true){
Debug.Log("boy");
}else{
Debug.Log("girl");
}
}
public void ave(){
int num=0,sum=0;
for(int i=0;i<=4;i++){
num=Score[i];
sum+=num;
}
Debug.Log (sum/5);
}
}