【正文】
ble psalary() //計算普通員工工資 { (工作年數(shù):)。 psalary = bsalary+30*pn。 } } public class UEmployee : Employee //本科生職工類 { new public double psalary() { return * ()。 Employee emp1 = new Employee()。 (本科生職工:)。 (該本科生職工工資:{0}, ())。3.定義一個Shape抽象類,在該類中定義兩個抽象方法GetArea和GetPerim。抽象類方法實現(xiàn)public abstract class Shape { public abstract double GetArea()。 } class Rectangle : Shape //派生出來的Rectangle類 { private double Width。 //矩形的長度 public Rectangle(double a, double b) //構(gòu)造函數(shù) { Width = a。 } public override double GetArea() //重載的求面積方法 { return (Width * Length)。 } } class Circle : Shape //派生出的Circle類 { private double Radius。 } public override double GetArea() //重載的求面積方法 { return ( * Radius * Radius)。 } }接口方法實現(xiàn)public interface Shape { double GetArea()。 } class Rectangle : Shape //派生出來的Rectangle類 { public double Width。 //矩形的長度 public Rectangle(double a, double b) //構(gòu)造函數(shù) { Width = a。 } public double GetArea() //重載的求面積方法 { return (Width * Length)。 } } class Circle : Shape //派生出的Circle類 { public double Radius。 } public double GetArea() //重載的求面積方法 { return ( * Radius * Radius)。 } }4.設(shè)計一個抽象類Calculate(計算),該類包含OptA、OptB、OptC三個double類型的字段,包含一個帶有兩個double類型參數(shù)的構(gòu)造函數(shù)(用于給字段OptA、OptB賦值)和一個名為SqrtForSum的抽象方法,該方法帶有三個double類型參數(shù)、返回值類型為double型。public abstract class Calculate { protected double OptA, OptB, OptC。 OptB = b。 } class Cal:Calculate { public Cal(double a, double b, double c): base(a, b) { OptC = c。 sum = a + b + c。 } }class Program { static void Main(string[] args) { double a, b, c,sum。 b = (())。Cal cc = new Cal(a,b,c)。 (sum={0}, sum)。然后通過對Person類的繼承得到一個學(xué)生類(Student)。public class Person { public string Name。 public char Sex。 public double Aver。 Age = nl。 Score = new double[5]。 Age = 18。女39。 } public Student(string xm, int nl, char xb, double[] cj) { Name = xm。 Sex = xb。 for (int i = 0。 i++) Score[i] = cj[i]。 for (int i = 0。 i++) sum = sum + Score[i]。 return (Aver)。 (年齡:{0}, Age)。 (成績:)。 i 5。 (\n平均成績:{0}, CalAver())。 Student stu。 ()。男39。 ()。男39。 ()。 } }6.設(shè)計一個控制臺應(yīng)用程序,定義如下接口Ia: interface Ia //聲明接口Ia{ float getarea()。并分別輸出長2寬3的長方形和長5的正方形的面積?! ? //接口成員聲明 } public class Rectangle : Ia //類Rectangle繼承接口Ia { float x, y。 y = y1。 } } public class Square : Ia //類Square繼承接口Ia { float x。 } float () //顯式接口成員實現(xiàn),帶有接口名前綴,不能使用public { return x * x。 //定義一個類實例 Ia ia = (Ia)box1。 Square box2 = new Square()。 //定義一個接口實例 (正方形面積: {0}, ())。要求比較采用繼承Iparer接口的方式實現(xiàn)。 //學(xué)號 string xm。 //分?jǐn)?shù) public int pfs //pfs屬性 { get { return fs。 xm = name。 } public void disp() { (\t{0}\t{1}\t{2}, xh, xm, fs)。 Stud b = (Stud)y。 else if ( == ) return 0。 } } static void disparr(ArrayList myarr, string str) { (str)。 foreach (Stud s in myarr) ()。 IComparer myComparerfs = new myCompareClassfs()。 Stud[] st = new Stud[4] { new Stud(1, Smith, 82), new Stud(4, John, 88), new Stud(3, Mary, 95), new Stud(2, Cherr, 64) }。 i n。 (myComparerfs)。 } }8.設(shè)計一個控制臺應(yīng)用程序項目,輸入若干個學(xué)生的英語和數(shù)學(xué)成績,求出總分,并按總分從高到低排序。要求比較采用繼承繼承Iparable接口的方式實現(xiàn)。 private int eng, math, sum。 } } public void inscore() { (姓名:)。 (英語:)。 (數(shù)學(xué):)。 sum = eng + math。 } public int CompareTo(object obj) //實現(xiàn)接口方法 { Student s = (Student)obj。 else if (psum == ) return 0。 } } class Program { static void Main(string[] args) { int n, i。 Student p。 n = (())。 i n。 p = new Student()。 (p)。 (\t姓名\t英語\t數(shù)學(xué)\t總分)。 foreach(Student s in myarr) { (序號{0}:, i++)。 } ()。 (\t姓名\t英語\t數(shù)學(xué)\t總分)。 foreach (Student s in myarr) { (第{0}名:, i++)。 } }}