c语言题库

2025-01-02 17:56:55
推荐回答(2个)
回答1:

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

namespace Dome2
{
class Student
{
public string name;
public float[] score=new float[3];
public float sum, avg;
public void InitScore()
{
this.sum = 0;
this.avg = 0;
}
public void GetScore()
{
Console.WriteLine("学员姓名:");
this.name = Console.ReadLine();
for (int i = 0; i < score.Length; i++)
{
Console.WriteLine("第{0}门的成绩是:",i+1);
this.score[i] = float.Parse(Console.ReadLine());
}
Console.WriteLine();
}
public void GetSum()
{
for (int i = 0; i < score.Length; i++)
{
this.sum+=this.score[i];
}
this.avg = this.sum / 3;
}
public void DisplayScore()
{
Console.WriteLine("学员姓名:{0}", this.name);
for (int j = 0; j < 3; j++)
{
Console.WriteLine("第{0}门课程考试成绩是{1}", j + 1, this.score[j]);
} Console.WriteLine("三门课程的总成绩是{0},平均成绩是{1}",this.sum, this.avg.ToString("0.00"));
Console.WriteLine();
}
}
}

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

namespace Dome2
{
class Program
{
static void Main(string[] args)
{
Student[] student = new Student[5];
float max = 0,average = 0;
int i;
int counter = 0;
for (i = 0; i < student.Length; i++)
{
student[i] = new Student();
student[i].GetScore();
student[i].GetSum();
}
for (i = 0; i < student.Length; i++)
{
student[i].DisplayScore();
}
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("========================================================");
for (i = 0; i < student.Length;i++ )
{
counter++;
max = student[i].sum + max;
average = student[i].avg + average;
}
Console.WriteLine("班级参加考试人数:{0} 最高分:{1} 平均分:{2}", counter, max, average);
}
}
}

回答2:

、、、 不会。。