⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentdetails.cs

📁 yongle jpscxsd j cxksk xdkl sna
💻 CS
字号:
using System;

namespace Example_2
{
	///<summary>
	/// 此程序演示单重继承的实现。
	///</summary>

	//基类
	public class Person
	{
		private string _name;
		private uint _age;

		public void GetInfo()
		{
			Console.WriteLine("请输入您的姓名和年龄");
			_name = Console.ReadLine();
			_age = uint.Parse(Console.ReadLine());
		}
		public void DispInfo()
		{
			Console.WriteLine("尊敬的 {0},您的年龄为 {1}", _name, _age);
		}
	}

	//派生类
	public class Student:Person
	{
		private string _school;
		private uint _eng;
		private uint _math;
		private uint _sci;
		private uint _tot;

		public uint GetMarks()
		{
			Console.WriteLine("请输入学校名称");
			_school = Console.ReadLine();
			Console.WriteLine("请分别输入英语、数学和自然科学的分数。");
			_eng = uint.Parse(Console.ReadLine());
			_math = uint.Parse(Console.ReadLine());
			_sci = uint.Parse(Console.ReadLine());
			_tot = _eng + _math + _sci;
			Console.WriteLine("所得总分为: {0}",_tot);
			return _tot;
		}
	}

	//继承自所有祖先
	public class UnderGraduate:Student
	{
		public void ChkEgbl()
		{
			Console.WriteLine("要上升一级,要求总分不低于 150");
			if(this.GetMarks() > 149)
				Console.WriteLine("合格");
			else
				Console.WriteLine("不合格");
		}

	}
	public class Exercise
	{

		///<summary>
		/// 应用程序的主入口点。
		///</summary>
		[STAThread]
		public static void Main(string[] args)
		{
			UnderGraduate objUnderGraduate = new UnderGraduate();
			objUnderGraduate.GetInfo();
			objUnderGraduate.DispInfo();
			objUnderGraduate.ChkEgbl();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -