C# 定义一个描述学生基本信息的类,属性包括姓名、学以及C#、英语和数学成绩,方法包括设置姓名和学号、设置三门课的成绩和输出相关学生的信息,最后求出总成绩和平均成绩。

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();}
	
	    }}


  • 15
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值