110,536
社区成员
发帖
与我相关
我的任务
分享
struct Student
{
string name;
int[] score;
public Student(string name,int[] score)
{
//指向自身的指针
this.name = name;
this.score = score;
}
//计算平均分数
public float avg()
{
float num = 0.0f;
for (int i = 0; i < score.Length; i++)
{
num += score[i];
}
return num / score.Length;
}
public string Name
{
get { return name; }
}
public int[] Score
{
get { return score; }
set { score = value; }
}
}
namespace ConsoleApplication3
{
class StudentTest
{
public static void Main()
{
Student[] stu = new Student[3];
string[] name ={ "jack", "mary", "kate" };
int[] s ={ 80, 80, 80 };
for (int i = 0; i < 3; i++)
{
stu[i] = new Student(name[i], s);
Console.WriteLine("{0,10}{1,3}",stu[i].Name,stu[i].avg());
}
}
}
}
struct Student
{
string name;声明下学生姓名
int[] score;学生成绩
public Student(string name,int[] score) 建立一个学生类
{
//指向自身的指针
this.name = name;
this.score = score;
}
//计算平均分数
public float avg()
{
float num = 0.0f;
for (int i = 0; i < score.Length; i++)把每个同学分数都加起来
{
num += score[i];
}
return num / score.Length;
返回学生平均成绩
}
public string Name
{
get { return name; }
}
public int[] Score
{
get { return score; }
set { score = value; }
}
}
namespace ConsoleApplication3
{
class StudentTest
{
public static void Main()
{
Student[] stu = new Student[3];
string[] name ={ "jack", "mary", "kate" };
int[] s ={ 80, 80, 80 };
for (int i = 0; i < 3; i++)
{
stu[i] = new Student(name[i], s);
Console.WriteLine("{0,10}{1,3}",stu[i].Name,stu[i].avg());通过控制台打印出来这三个同学的姓名以及平均分
}
}
}
}