日期:2014-05-18 浏览次数:21058 次
using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Student x1 = new Student("1001", "学生1", 0x12, 90M, 91M, 92M); Console.WriteLine("学生:{0} 总成绩:{1} 升学标志:{2}", x1.name, x1.计算总成绩().ToString(), x1.升学().ToString()); Student x2 = new Student("1002", "学生2", 0x12, 92M, 91M, 82M); Console.WriteLine("学生:{0} 总成绩:{1} 升学标志:{2}", x2.name, x2.计算总成绩().ToString(), x2.升学().ToString()); Student x3 = new Student("1003", "学生3", 0x12, 90M, 71M, 92M); Console.WriteLine("学生:{0} 总成绩:{1} 升学标志:{2}", x3.name, x3.计算总成绩().ToString(), x3.升学().ToString()); Student x4 = new Student("1004", "学生4", 0x12, 60M, 11M, 22M); Console.WriteLine("学生:{0} 总成绩:{1} 升学标志:{2}", x4.name, x4.计算总成绩().ToString(), x4.升学().ToString()); } } public class Person { // Fields private int _age; private string _name; // Properties public int age { get { return this._age; } set { this._age = value; } } public string name { get { return this._name; } set { this._name = value; } } } public class Student : Person { // Fields private decimal _数学成绩; private string _学号; private decimal _英语成绩; private decimal _语文成绩; // Methods public Student(string 学号, string name, int age, decimal 数学成绩, decimal 语文成绩, decimal 英语成绩) { this.name = name; this .age = age; this.学号 = 学号; this.数学成绩 = 数学成绩; this.语文成绩 = 语文成绩; this.英语成绩 = 英语成绩; } public decimal 计算总成绩() { decimal sum=0; sum += this._数学成绩 + this._语文成绩 + this._英语成绩; return sum ; } public bool 升学() { return (decimal.Compare(this.计算总成绩(), 200M) >= 0); } // Properties public decimal 数学成绩 { get { return this._数学成绩; } set { this._数学成绩 = value; } } public string 学号 { get { return this._学号; } set { this._学号 = value; } } public decimal 英语成绩 { get { return this._英语成绩; } set { this._英语成绩 = value; } } public decimal 语文成绩 { get { return this._语文成绩; } set { this._语文成绩 = value; } } } }
------解决方案--------------------
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace zy2 { class Person { public string Name { get; set; } public int Age { get; set; } } class Student : Person { public string 学号 { get; set; } public int 英语成绩 { get; set; } public int 数学成绩 { get; set; } public int 语文成绩 { get; set; } private int 获得总分() { return this.英语成绩 + this.数学成绩 + this.语文成绩; } public void 显示总分() { Console.WriteLine("总分等于{0}.",