1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| abstract class ExamResult { //学号 public int Id { get; set; } //数学成绩 public double Math { get; set; } //英语成绩 public double English { get; set; } //计算总成绩 public abstract void Total(); } class MathMajor : ExamResult { public override void Total() { double total = Math * 0.6 + English * 0.4; Console.WriteLine("学号为" + Id + "数学专业学生的成绩为:" + total); } } class EnglishMajor : ExamResult { public override void Total() { double total = Math * 0.4 + English * 0.6; Console.WriteLine("学号为" + Id + "英语专业学生的成绩为:" + total); } } class Program { static void Main(string[] args) { MathMajor mathMajor = new MathMajor(); mathMajor.Id = 1; mathMajor.English = 80; mathMajor.Math = 90; mathMajor.Total(); EnglishMajor englishMajor = new EnglishMajor(); englishMajor.Id = 2; englishMajor.English = 80; englishMajor.Math = 90; englishMajor.Total(); } }
|