C# 定义一个描述学生基本信息的类,属性包括姓名、学以及C#、英语和数学成绩,方法包括设置姓名和学号、设置三门课的成绩和输出相关学生的信息,最后求出总成绩和平均成绩。
**
代码如下:
using System;
namespace debug_code5._9
{
public class Student
{
public string Name { get; set; }//自动属性
public string StudentID { get; set; }
public string CSharpScore { get; set; }
public string EnglishScore { get; set; }
public string MathScore { get; set; }
public int ScoreSum;
public int ArrScore;
public Student(string n, string i, string c, string m, string j)
{
Name = n;
StudentID = i;
CSharpScore = c;
EnglishScore = m;
MathScore = j;
ScoreSum = int.Parse(c) +int.Parse(m) + int.Parse(j);
ArrScore = ScoreSum / 3;
}
public void Output_Major()
{
Console.WriteLine("Student:{0}'s StudentID is {1} CSharpScore is {2} EnglishScore is {3} MathScore is {4}", Name, StudentID, CSharpScore, EnglishScore, MathScore);
Console.WriteLine("Student:{0}'s SunScore is {1}",Name,ScoreSum);
Console.WriteLine("Student:{0}'s ArrScore is {1}", Name,ArrScore);
}
}
class Program
{
static void Main(string[] args)
{
string n, i, c, m, j;
Console.Write("请依次输入以下内容:\n \t姓名\n \t学号\n \tC#成绩\n \t英语成绩\n \t数学成绩\n");
n = Console.ReadLine();
i = Console.ReadLine();
c = Console.ReadLine();
m = Console.ReadLine();
j = Console.ReadLine();
Student s1 = new Student(n, i, c, m, j);
s1.Output_Major();
Console.Read();
}
}
}