首页 新闻 会员 周边

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

-1
[待解决问题]

新手想半天不会写,必须用二维数组吗?我想求面试成绩和笔试成绩的总分和平均分,

大神给个思路!!!

//下面是我创建的StudentScore类

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

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;
using System.Threading.Tasks;

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

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

}
Console.ReadKey();
}
}
}

meepoWho的主页 meepoWho | 菜鸟二级 | 园豆:204
提问于:2016-07-20 17:07
< >
分享
所有回答(1)
-1

我会了!!!

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

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

meepoWho | 园豆:204 (菜鸟二级) | 2016-07-20 19:46
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册