# 新手求助,如何求学生每门课程的总分和平均分啊,我创建的类里是个1维数组?

-1
[待解决问题]

//下面是我创建的StudentScore类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyScore
{
class StudentScore
{
private string sName;
private int sAge;
private double[] sScore;

public double[] SScore
{
get
{
return sScore;
}

set
{
sScore = value;
}
}

public StudentScore(string name, int age, double[] score)
{
sName = name;
sAge = age;
SScore = score;
}
public string Display()
{
string t;
t = "笔试成绩:"+SScore[0] + ",面试成绩:" + SScore[1];
return t;
}

}
}

//下面是程序主方法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyScore
{
class Program
{
static void Main(string[] args)
{
StudentScore[] Students = new StudentScore[2];

for (int i = 0; i < 2; i++)
{
Console.Write("请输入考生的名字:");
Console.Write("请输入考生的年龄:");
double[] newScore = new double[2];
Console.Write("请输入{0}的笔试分数:", newName);
Console.Write("请输入{0}的面试分数:", newName);
StudentScore Student = new StudentScore(newName,newAge,newScore);
Students[i] = Student;
}
foreach (StudentScore s in Students)
{
Console.WriteLine(s.Display());

}
}
}
}

meepoWho | 菜鸟二级 | 园豆：204

-1

//我会了
//在main方法里添加两个变量
double Sum1=0;
double Sum2=0;

//在循环里添加自加运算就可以了!!!
Sum1+=SScore[0];
Sum2+=SScore[1];
//最后输出
console.writeline(sum1);

meepoWho | 园豆：204 (菜鸟二级) | 2016-07-20 19:46

您需要登录以后才能回答，未注册用户请先注册