使用Visual Studio.net定义一个学员类,包括以下字段(学员编号,姓名,入学时间,数据库考试成绩、UML考试成绩、上机考试成绩),根据学员的总成绩实现一些若干功能。
时间: 2023-05-24 09:05:00 浏览: 86
可以参考以下代码实现:
```
public class Student
{
public int StudentID { get; set; }
public string Name { get; set; }
public DateTime EnrollDate { get; set; }
public int DatabaseScore { get; set; }
public int UMLScore { get; set; }
public int ProgrammingScore { get; set; }
// 计算总成绩
public int GetTotalScore()
{
return DatabaseScore + UMLScore + ProgrammingScore;
}
// 判断是否及格(总成绩需大于等于180分)
public bool IsPass()
{
return GetTotalScore() >= 180;
}
// 输出学生信息及总成绩
public void ShowInfoWithTotalScore()
{
Console.WriteLine("学员编号:{0}", StudentID);
Console.WriteLine("姓名:{0}", Name);
Console.WriteLine("入学时间:{0}", EnrollDate.ToString("yyyy-MM-dd"));
Console.WriteLine("数据库成绩:{0}", DatabaseScore);
Console.WriteLine("UML成绩:{0}", UMLScore);
Console.WriteLine("上机成绩:{0}", ProgrammingScore);
Console.WriteLine("总成绩:{0}", GetTotalScore());
}
}
```
使用示例:
```
// 创建一个学生对象,并初始化字段
Student student = new Student()
{
StudentID = 1001,
Name = "张三",
EnrollDate = new DateTime(2021, 1, 1),
DatabaseScore = 80,
UMLScore = 90,
ProgrammingScore = 85
};
// 输出学生信息及总成绩
student.ShowInfoWithTotalScore();
// 判断学生是否及格
if (student.IsPass())
{
Console.WriteLine("该学生已经及格!");
}
else
{
Console.WriteLine("该学生还未及格!");
}
```
相关推荐
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)